-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMex Grid Construction.cpp
More file actions
54 lines (41 loc) · 947 Bytes
/
Mex Grid Construction.cpp
File metadata and controls
54 lines (41 loc) · 947 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
struct Mex {
int mex = 0;
set<int> elements;
void add(int x) {
if ( x < mex ) return;
if ( elements.find(x) != elements.end() ) return;
elements.insert(x);
if ( x != mex ) return;
while (*elements.begin() == mex) {
elements.erase(elements.begin());
mex++;
}
}
};
Mex mexes[100][100];
void solve() {
int n;
cin >> n;
int mex[n][n];
for(int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int mex = mexes[i][j].mex;
cout << mex << " ";
for(int k = 0; k < n; k++) {
mexes[i][k].add(mex);
mexes[k][j].add(mex);
}
}
cout << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}