-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP171SUMD.cpp
More file actions
108 lines (102 loc) · 2.08 KB
/
P171SUMD.cpp
File metadata and controls
108 lines (102 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int const base = 1e9 + 7;
int check(int A[101][101], int B[101][101], int m, int n){
For(i, 1, m){
For(j, 1, n){
if(A[i][j] != B[i][j]) return 0;
}
}
return 1;
}
int main(void){
int m, n;
int Pass[101][101];
int Start[101][101];
int H[10001], T = 0, C[10001], K = 0;
cin>>m>>n;
For(i, 1, m){
For(j, 1, n){
cin>>Pass[i][j];
Start[i][j] = 0;
}
}
if(m < n){
For(i, 1, m){
int mins = maxn;
For(j, 1, n){
if(Pass[i][j] < mins) mins = Pass[i][j];
}
if(mins != 0){
For(k, 1, mins) H[++T] = i;
For(j, 1, n){
Start[i][j] += mins;
}
}
}
For(j, 1, n){
int mins = maxn;
int t;
For(i, 1, m){
if(Pass[i][j] < mins){
mins = Pass[i][j];
t = Pass[i][j] - Start[i][j];
}
}
if(t != 0){
For(k, 1, t) C[++K] = j;
For(i, 1, m){
Start[i][j] += t;
}
}
}
if(check(Start, Pass, m, n) == 0) cout<<"-1";
else{
cout<<(T + K)<<endl;
For(i, 1, T) cout<<"H "<<H[i]<<endl;
For(i, 1, K) cout<<"C "<<C[i]<<endl;
}
}
else{
For(j, 1, n){
int mins = maxn;
For(i, 1, m){
if(Pass[i][j] < mins) mins = Pass[i][j];
}
if(mins != 0){
For(k, 1, mins) C[++K] = j;
For(i, 1, m){
Start[i][j] += mins;
}
}
}
For(i, 1, m){
int mins = maxn;
int t;
For(j, 1, n){
if(Pass[i][j] < mins){
mins = Pass[i][j];
t = Pass[i][j] - Start[i][j];
}
}
if(t != 0){
For(k, 1, t) H[++T] = i;
For(j, 1, n){
Start[i][j] += t;
}
}
}
if(check(Start, Pass, m, n) == 0) cout<<"-1";
else{
cout<<(T + K)<<endl;
For(i, 1, T) cout<<"H "<<H[i]<<endl;
For(i, 1, K) cout<<"C "<<C[i]<<endl;
}
}
return 0;
}