#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) : 1;
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 = s = 0; i < N; ++i) {
assert(1 <= adj[i].size() && adj[i].size() <= 2);
s += adj[i].size() == 1;
}
assert(s == 2);
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 |
48 ms |
376 KB |
Output is correct |
2 |
Correct |
48 ms |
440 KB |
Output is correct |
3 |
Runtime error |
46 ms |
700 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
376 KB |
Output is correct |
2 |
Correct |
48 ms |
440 KB |
Output is correct |
3 |
Runtime error |
46 ms |
700 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |