forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
52 lines (47 loc) · 1.16 KB
/
B.cpp
File metadata and controls
52 lines (47 loc) · 1.16 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
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
bool run() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int> > > mm(105, vector<pair<int, int> >());
REP(i,n) REP(j,m) {
int t;
cin >> t;
mm[t].push_back(make_pair(i, j));
}
vector<int> row(n, -1), col(m, -1);
RFOR(cur,100,1) {
REP(i,mm[cur].size()) {
int x = mm[cur][i].first, y = mm[cur][i].second;
bool flag = false;
if (row[x] == -1 || row[x] == cur) {
row[x] = cur;
flag = true;
}
if (col[y] == -1 || col[y] == cur) {
col[y] = cur;
flag = true;
}
if (!flag) return false;
}
}
return true;
}
int main() {
int k;
cin >> k;
FOR(c,1,k) {
cout << "Case #" << c << ": ";
if (run()) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}