#include <bits/stdc++.h>
#include <signal.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
using namespace std;
int N, M, Q;
vector<vector<int>> grid;
void output(){
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << grid[i][j];
}
cout << "\n";
}
}
int find_next(int l, int r){
int c = 0;
if(l == 0){
c++;
if(r == 1) c++;
}
return c;
}
signed main() {
cin >> N;
vector<int> pos(N);
grid.resize(N, vector<int>(N, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) grid[i][j] = 1;
cout << "?" << "\n";
output();
cout << flush;
for (int j = 0; j < N; j++) grid[i][j] = 0;
int base; cin >> base;
if (base == N*N) {
cout << "!" << "\n";
for (int j = 0; j < N; j++) grid[i][j] = 1;
output();
cout << flush;
return 0;
}
int l = 0, r = N-1;
while (r - l > 1) {
int mid = (l + r) / 2;
for (int j = l; j <= mid; j++) grid[i][j] = 1;
cout << "?" << "\n";
output();
for (int j = 0; j < N; j++) grid[i][j] = 0;
cout << flush;
int res; cin >> res;
if (res < (mid - l + 1) * N) {
r = mid;
} else {
l = mid + 1;
}
}
int rnd = find_next(l, r);
if (l == r) {
pos[i] = l;
continue;
}
grid[i][l] = 1;
grid[i][r] = 1;
cout << "?" << "\n";
output();
cout << flush;
int res; cin >> res;
if (res == N) {
grid[i][l] = 0;
grid[i][r] = 0;
pos[i] = l;
continue;
}
if (res == 2*N) {
grid[i][l] = 0;
grid[i][r] = 0;
pos[i] = r+1;
continue;
}
grid[i][rnd] = 1;
cout << "?" << "\n";
output();
cout << flush;
cin >> res;
if (res == N*2 - 1) {
grid[i][r] = 0;
cout << "?" << "\n";
output();
cout << flush;
cin >> res;
if (res == N*2 - 1) pos[i] = r;
else pos[i] = l;
} else {
grid[i][r] = 0;
cout << "?" << "\n";
output();
cout << flush;
cin >> res;
if (res == N*2 - 1) pos[i] = l;
else pos[i] = r;
}
grid[i][rnd] = 0;
grid[i][l] = 0;
}
for (int i = 0; i < N; i++) {
grid[i][pos[i]] = 1;
}
cout << "!" << "\n";
cout << flush;
output();
cout << flush;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
356 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
2 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
0 ms |
424 KB |
Output is correct |
54 |
Correct |
1 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Partially correct |
217 ms |
1012 KB |
Partially correct |
60 |
Correct |
1 ms |
344 KB |
Output is correct |
61 |
Partially correct |
251 ms |
344 KB |
Partially correct |
62 |
Partially correct |
223 ms |
836 KB |
Partially correct |
63 |
Partially correct |
225 ms |
344 KB |
Partially correct |
64 |
Partially correct |
292 ms |
1080 KB |
Partially correct |
65 |
Partially correct |
261 ms |
344 KB |
Partially correct |
66 |
Partially correct |
239 ms |
492 KB |
Partially correct |
67 |
Partially correct |
273 ms |
344 KB |
Partially correct |
68 |
Partially correct |
270 ms |
344 KB |
Partially correct |
69 |
Partially correct |
247 ms |
784 KB |
Partially correct |
70 |
Partially correct |
242 ms |
344 KB |
Partially correct |
71 |
Partially correct |
235 ms |
1248 KB |
Partially correct |
72 |
Correct |
1 ms |
344 KB |
Output is correct |
73 |
Partially correct |
65 ms |
344 KB |
Partially correct |
74 |
Partially correct |
121 ms |
344 KB |
Partially correct |
75 |
Partially correct |
284 ms |
344 KB |
Partially correct |
76 |
Partially correct |
291 ms |
344 KB |
Partially correct |
77 |
Partially correct |
221 ms |
780 KB |
Partially correct |
78 |
Partially correct |
55 ms |
344 KB |
Partially correct |
79 |
Partially correct |
241 ms |
496 KB |
Partially correct |
80 |
Partially correct |
223 ms |
720 KB |
Partially correct |
81 |
Partially correct |
262 ms |
344 KB |
Partially correct |
82 |
Partially correct |
291 ms |
928 KB |
Partially correct |
83 |
Partially correct |
222 ms |
344 KB |
Partially correct |
84 |
Partially correct |
231 ms |
344 KB |
Partially correct |
85 |
Partially correct |
235 ms |
344 KB |
Partially correct |
86 |
Partially correct |
210 ms |
344 KB |
Partially correct |
87 |
Partially correct |
266 ms |
1084 KB |
Partially correct |
88 |
Partially correct |
206 ms |
344 KB |
Partially correct |
89 |
Partially correct |
273 ms |
1216 KB |
Partially correct |
90 |
Partially correct |
209 ms |
344 KB |
Partially correct |
91 |
Partially correct |
216 ms |
500 KB |
Partially correct |
92 |
Partially correct |
241 ms |
340 KB |
Partially correct |
93 |
Partially correct |
210 ms |
344 KB |
Partially correct |
94 |
Partially correct |
269 ms |
944 KB |
Partially correct |
95 |
Partially correct |
223 ms |
344 KB |
Partially correct |
96 |
Partially correct |
229 ms |
928 KB |
Partially correct |
97 |
Correct |
0 ms |
344 KB |
Output is correct |