#include <bits/stdc++.h>
#include "library.h"
using namespace std;
vector<vector<int> > adj;
vector<int> M, res, nv;
void Solve(int N) {
int l, r, m, c, d, e, s, t = 0, z, i, j;
for (i = 0; i < N; ++i) adj.push_back(nv), M.push_back(0), res.push_back(-1);
for (i = 0; i < N; ++i) {
++t;
if (!i) continue;
for (j = 0; j < M.size(); ++j) M[j] = 0;
for (j = 0; j < i + 1; ++j) M[j] = 1;
for (c = Query(M); c < t; --t) {
l = 0;
r = i - 1;
while (l < r) {
m = (l + r) / 2;
for (j = s = 0; j < M.size(); ++j) M[j] = 0;
for (j = l; j < m + 1; ++j) s += M[j] = j != z;
d = s ? Query(M) : 0;
M[i] = 1;
e = Query(M);
(e < d + 1 ? r : l) = m + (e > d);
}
z = (l + r) / 2;
adj[i].push_back(z);
adj[z].push_back(i);
}
z = -1;
}
for (i = 0; i < N; ++i) if (adj[i].size() <= 1) {
for (j = 0, c = i, t = -1; j < N - 1; ++j) {
res[j] = c;
if (adj[c][0] != t) c = adj[t = c][0];
else c = adj[t = c][1];
}
res[j] = c;
break;
}
for (i = 0; i < N; ++i) ++res[i];
Answer(res);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < M.size(); ++j) M[j] = 0;
~~^~~~~~~~~~
library.cpp:21:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = s = 0; j < M.size(); ++j) M[j] = 0;
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
248 KB |
Output is correct |
2 |
Correct |
46 ms |
308 KB |
Output is correct |
3 |
Correct |
45 ms |
476 KB |
Output is correct |
4 |
Correct |
47 ms |
476 KB |
Output is correct |
5 |
Correct |
48 ms |
476 KB |
Output is correct |
6 |
Correct |
49 ms |
476 KB |
Output is correct |
7 |
Correct |
49 ms |
624 KB |
Output is correct |
8 |
Correct |
46 ms |
624 KB |
Output is correct |
9 |
Correct |
46 ms |
624 KB |
Output is correct |
10 |
Correct |
27 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
624 KB |
Output is correct |
14 |
Correct |
2 ms |
624 KB |
Output is correct |
15 |
Correct |
3 ms |
624 KB |
Output is correct |
16 |
Correct |
5 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
248 KB |
Output is correct |
2 |
Correct |
46 ms |
308 KB |
Output is correct |
3 |
Correct |
45 ms |
476 KB |
Output is correct |
4 |
Correct |
47 ms |
476 KB |
Output is correct |
5 |
Correct |
48 ms |
476 KB |
Output is correct |
6 |
Correct |
49 ms |
476 KB |
Output is correct |
7 |
Correct |
49 ms |
624 KB |
Output is correct |
8 |
Correct |
46 ms |
624 KB |
Output is correct |
9 |
Correct |
46 ms |
624 KB |
Output is correct |
10 |
Correct |
27 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
624 KB |
Output is correct |
14 |
Correct |
2 ms |
624 KB |
Output is correct |
15 |
Correct |
3 ms |
624 KB |
Output is correct |
16 |
Correct |
5 ms |
624 KB |
Output is correct |
17 |
Correct |
518 ms |
736 KB |
Output is correct |
18 |
Correct |
500 ms |
736 KB |
Output is correct |
19 |
Correct |
555 ms |
740 KB |
Output is correct |
20 |
Correct |
381 ms |
740 KB |
Output is correct |
21 |
Correct |
435 ms |
740 KB |
Output is correct |
22 |
Correct |
534 ms |
740 KB |
Output is correct |
23 |
Correct |
548 ms |
740 KB |
Output is correct |
24 |
Correct |
174 ms |
740 KB |
Output is correct |
25 |
Correct |
522 ms |
828 KB |
Output is correct |
26 |
Correct |
450 ms |
828 KB |
Output is correct |
27 |
Correct |
184 ms |
828 KB |
Output is correct |
28 |
Correct |
431 ms |
828 KB |
Output is correct |
29 |
Correct |
423 ms |
828 KB |
Output is correct |
30 |
Correct |
460 ms |
828 KB |
Output is correct |