#include "bits/stdc++.h"
#include "library.h"
using namespace std;
#define pb push_back
#define sz(v) ((int)v.size())
mt19937 rng(time(NULL));
vector<int> ans, j;
bitset<1001> in;
int query(int s, vector<int> &z) {
shuffle(z.begin(), z.end(), rng);
if (sz(z) == 1) return z[0];
if (sz(z) == 0) return -1;
int l = 0;
int r = sz(z) - 1;
int c1, c2;
while (l < r) {
int m = (l+r)/2;
fill(j.begin(), j.end(), 0);
for (int i = l; i <= m; ++i)
j[z[i]-1] = 1;
c1 = Query(j);
j[s-1] = 1;
c2 = Query(j);
if (c1 >= c2)
r = m;
else
l = m+1;
}
if (l == sz(z) -1) {
fill(j.begin(), j.end(), 0);
j[s-1] = 1; j[z.back()-1] = 1;
if (Query(j) != 1)
return -1;
}
return z[l];
}
void remain(vector<int> &u, int n) {
u.clear();
for (int i = 1; i <= n; ++i)
if (!in[i]) u.pb(i);
}
void Solve(int n) {
int c = 1;
j.assign(n, 0);
vector<int> u;
while (c != -1) {
in[c] = 1;
ans.pb(c);
remain(u, n);
c = query(c, u);
}
reverse(ans.begin(), ans.end());
c = ans.back();
ans.pop_back();
while (c != -1) {
in[c] = 1;
ans.pb(c);
remain(u, n);
c = query(c, u);
}
Answer(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
208 KB |
# of queries: 2399 |
2 |
Correct |
25 ms |
208 KB |
# of queries: 2357 |
3 |
Correct |
35 ms |
208 KB |
# of queries: 2516 |
4 |
Correct |
25 ms |
208 KB |
# of queries: 2542 |
5 |
Correct |
24 ms |
208 KB |
# of queries: 2541 |
6 |
Correct |
22 ms |
208 KB |
# of queries: 2520 |
7 |
Correct |
25 ms |
208 KB |
# of queries: 2509 |
8 |
Correct |
23 ms |
208 KB |
# of queries: 2412 |
9 |
Correct |
31 ms |
208 KB |
# of queries: 2504 |
10 |
Correct |
10 ms |
308 KB |
# of queries: 1470 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Incorrect |
0 ms |
208 KB |
Wrong Answer [8] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
208 KB |
# of queries: 2399 |
2 |
Correct |
25 ms |
208 KB |
# of queries: 2357 |
3 |
Correct |
35 ms |
208 KB |
# of queries: 2516 |
4 |
Correct |
25 ms |
208 KB |
# of queries: 2542 |
5 |
Correct |
24 ms |
208 KB |
# of queries: 2541 |
6 |
Correct |
22 ms |
208 KB |
# of queries: 2520 |
7 |
Correct |
25 ms |
208 KB |
# of queries: 2509 |
8 |
Correct |
23 ms |
208 KB |
# of queries: 2412 |
9 |
Correct |
31 ms |
208 KB |
# of queries: 2504 |
10 |
Correct |
10 ms |
308 KB |
# of queries: 1470 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Incorrect |
0 ms |
208 KB |
Wrong Answer [8] |
14 |
Halted |
0 ms |
0 KB |
- |