#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cmin(a, b) a=min(a, b)
#define cmax(a, b) a=max(a, b)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
void solve();
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
int ask(vector<vector<int>>& grid) {
cout << "?" << endl;
for (auto u: grid) {
for (auto v: u) cout << v ;
cout << endl;
}
int ans; cin >> ans;
return ans;
}
int end(vector<vector<int>>& grid) {
cout << "!" << endl;
for (auto u: grid) {
for (auto v: u) cout << v ;
cout << endl;
}
exit(0);
}
int n, m, q;
void solve() {
cin >> n;
vector<vector<int>> grid(n, vector<int>(n)), is(n, vector<int>(n, -1)); // 0: column, 1: line
set<int> col, line; for (int i=0; i<n; i++) col.insert(i), line.insert(i);
set<pair<int, int>> bestc, bestl;
{
for (int i=0; i<n; i++) grid[0][i]=1;
int x=ask(grid); grid[0][0]=0; int y=ask(grid);
if (x==n*n) {
grid[0][0]=1;
end(grid);
}
if (y==n*(n-1) && x==y+1) x=y;
if (x==y) is[0][0]=1, line.erase(0), bestl.insert({0, 0});
else is[0][0]=0, col.erase(0), bestc.insert({0, 0});
for (int i=0; i<n; i++) grid[0][i]=0;
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) if (col.count(j) && line.count(i)) {
grid[0][0]=1, grid[i][j]=1;
if (ask(grid)==2*n) is[i][j]=is[0][0];
else is[i][j]=1-is[0][0];
if (is[i][j]) line.erase(i), bestl.insert({i, j});
else col.erase(j), bestc.insert({i, j});
grid[0][0]=0, grid[i][j]=0;
}
}
if (!col.empty()) swap(bestl, bestc);
for (auto u: bestc) grid[u.fi][u.se]=1;
end(grid);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
508 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
1 ms |
336 KB |
Output is correct |
58 |
Correct |
2 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
412 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
2 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
504 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
2 ms |
336 KB |
Output is correct |
58 |
Correct |
2 ms |
336 KB |
Output is correct |
59 |
Partially correct |
58 ms |
592 KB |
Partially correct |
60 |
Correct |
3 ms |
592 KB |
Output is correct |
61 |
Partially correct |
44 ms |
624 KB |
Partially correct |
62 |
Partially correct |
49 ms |
592 KB |
Partially correct |
63 |
Partially correct |
107 ms |
628 KB |
Partially correct |
64 |
Partially correct |
93 ms |
592 KB |
Partially correct |
65 |
Partially correct |
120 ms |
624 KB |
Partially correct |
66 |
Partially correct |
91 ms |
592 KB |
Partially correct |
67 |
Partially correct |
95 ms |
592 KB |
Partially correct |
68 |
Partially correct |
98 ms |
624 KB |
Partially correct |
69 |
Partially correct |
78 ms |
624 KB |
Partially correct |
70 |
Partially correct |
49 ms |
592 KB |
Partially correct |
71 |
Partially correct |
75 ms |
760 KB |
Partially correct |
72 |
Correct |
3 ms |
764 KB |
Output is correct |
73 |
Partially correct |
56 ms |
624 KB |
Partially correct |
74 |
Partially correct |
73 ms |
1120 KB |
Partially correct |
75 |
Partially correct |
82 ms |
592 KB |
Partially correct |
76 |
Partially correct |
56 ms |
592 KB |
Partially correct |
77 |
Partially correct |
79 ms |
624 KB |
Partially correct |
78 |
Partially correct |
75 ms |
628 KB |
Partially correct |
79 |
Partially correct |
62 ms |
848 KB |
Partially correct |
80 |
Partially correct |
80 ms |
620 KB |
Partially correct |
81 |
Partially correct |
133 ms |
848 KB |
Partially correct |
82 |
Partially correct |
93 ms |
624 KB |
Partially correct |
83 |
Partially correct |
90 ms |
880 KB |
Partially correct |
84 |
Partially correct |
85 ms |
592 KB |
Partially correct |
85 |
Partially correct |
86 ms |
592 KB |
Partially correct |
86 |
Partially correct |
110 ms |
880 KB |
Partially correct |
87 |
Partially correct |
93 ms |
628 KB |
Partially correct |
88 |
Partially correct |
52 ms |
840 KB |
Partially correct |
89 |
Partially correct |
48 ms |
592 KB |
Partially correct |
90 |
Partially correct |
78 ms |
624 KB |
Partially correct |
91 |
Partially correct |
89 ms |
628 KB |
Partially correct |
92 |
Partially correct |
87 ms |
880 KB |
Partially correct |
93 |
Partially correct |
94 ms |
624 KB |
Partially correct |
94 |
Partially correct |
90 ms |
620 KB |
Partially correct |
95 |
Partially correct |
51 ms |
620 KB |
Partially correct |
96 |
Partially correct |
117 ms |
624 KB |
Partially correct |
97 |
Correct |
1 ms |
336 KB |
Output is correct |