#include "library.h"
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
int n;
vector<int> pref;
bool query(int be, int en, int i) {
vector<int> ele(n, 0);
fill(ele.begin() + be, ele.begin() + en, 1);
int prv = (be == en ? -1 : (be == 0 ? pref[en - 1] : Query(ele) ) );
ele[i] = 1;
int cur = Query(ele);
return cur <= prv;
}
void Solve(int N) {
n = N;
pref.assign(n, 0);
vector<int> cur(n, 0);
for (int i = 0; i < n; ++i) {
cur[i] = 1;
pref[i] = Query(cur);
}
vector<vector<int> > gr(N);
for (int i = 1; i < N; ++i) if (query(0, i, i) ) {
int l = 0, r = i - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (query(0, mid + 1, i) ) r = mid;
else l = mid + 1;
}
gr[i].emplace_back(l);
gr[l].emplace_back(i);
if (query(l + 1, i, i) ) {
int be = l + 1;
l = be; r = i - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (query(be, mid + 1, i) ) r = mid;
else l = mid + 1;
}
gr[i].emplace_back(l);
gr[l].emplace_back(i);
}
}
int rt = -1;
for (int u = 0; u < N; ++u) if (sz(gr[u]) == 1) rt = u;
assert(rt != -1);
vector<bool> vis(N);
vector<int> ans;
for (int u = rt; u != -1; ) {
vis[u] = true;
ans.emplace_back(u);
int nxt = -1;
for (int v : gr[u]) if (!vis[v]) nxt = v;
u = nxt;
}
for (auto &i : ans) ++i;
Answer(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
376 KB |
# of queries: 2331 |
2 |
Correct |
43 ms |
248 KB |
# of queries: 2326 |
3 |
Correct |
44 ms |
336 KB |
# of queries: 2438 |
4 |
Correct |
44 ms |
248 KB |
# of queries: 2417 |
5 |
Correct |
42 ms |
252 KB |
# of queries: 2416 |
6 |
Correct |
44 ms |
248 KB |
# of queries: 2412 |
7 |
Correct |
46 ms |
248 KB |
# of queries: 2418 |
8 |
Correct |
43 ms |
504 KB |
# of queries: 2294 |
9 |
Correct |
46 ms |
336 KB |
# of queries: 2445 |
10 |
Correct |
26 ms |
376 KB |
# of queries: 1466 |
11 |
Runtime error |
5 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Correct |
5 ms |
248 KB |
# of queries: 4 |
13 |
Correct |
5 ms |
248 KB |
# of queries: 9 |
14 |
Correct |
5 ms |
248 KB |
# of queries: 14 |
15 |
Correct |
6 ms |
376 KB |
# of queries: 96 |
16 |
Correct |
8 ms |
248 KB |
# of queries: 216 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
376 KB |
# of queries: 2331 |
2 |
Correct |
43 ms |
248 KB |
# of queries: 2326 |
3 |
Correct |
44 ms |
336 KB |
# of queries: 2438 |
4 |
Correct |
44 ms |
248 KB |
# of queries: 2417 |
5 |
Correct |
42 ms |
252 KB |
# of queries: 2416 |
6 |
Correct |
44 ms |
248 KB |
# of queries: 2412 |
7 |
Correct |
46 ms |
248 KB |
# of queries: 2418 |
8 |
Correct |
43 ms |
504 KB |
# of queries: 2294 |
9 |
Correct |
46 ms |
336 KB |
# of queries: 2445 |
10 |
Correct |
26 ms |
376 KB |
# of queries: 1466 |
11 |
Runtime error |
5 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Correct |
5 ms |
248 KB |
# of queries: 4 |
13 |
Correct |
5 ms |
248 KB |
# of queries: 9 |
14 |
Correct |
5 ms |
248 KB |
# of queries: 14 |
15 |
Correct |
6 ms |
376 KB |
# of queries: 96 |
16 |
Correct |
8 ms |
248 KB |
# of queries: 216 |
17 |
Correct |
394 ms |
504 KB |
# of queries: 15269 |
18 |
Correct |
378 ms |
492 KB |
# of queries: 15130 |
19 |
Correct |
407 ms |
380 KB |
# of queries: 15359 |
20 |
Correct |
376 ms |
380 KB |
# of queries: 14392 |
21 |
Correct |
329 ms |
376 KB |
# of queries: 13478 |
22 |
Correct |
423 ms |
372 KB |
# of queries: 15429 |
23 |
Correct |
454 ms |
384 KB |
# of queries: 15297 |
24 |
Correct |
154 ms |
376 KB |
# of queries: 7171 |
25 |
Correct |
410 ms |
396 KB |
# of queries: 14970 |
26 |
Correct |
372 ms |
388 KB |
# of queries: 14028 |
27 |
Correct |
154 ms |
248 KB |
# of queries: 7228 |
28 |
Correct |
303 ms |
384 KB |
# of queries: 10976 |
29 |
Correct |
306 ms |
516 KB |
# of queries: 10964 |
30 |
Correct |
300 ms |
388 KB |
# of queries: 10976 |