#include <bits/stdc++.h>
#include "library.h"
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1000 + 7;
int n;
bool vis[N];
VI qr, opt, ans;
int findLeaf() {
fill(ALL(qr), 1);
F0R(i, n) {
qr[i] = 0;
//cout << "asking: "; F0R(i, n) cout << qr[i] << ' '; cout << endl;
int z = Query(qr);
qr[i] = 1;
if (z == 1) return i;
}
return -1;
}
inline bool get(int x, int l, int r) {
fill(ALL(qr), 0);
FOR(i, l, r + 1) qr[ opt[i] ] = 1;
int g1 = Query(qr);
qr[x] = 1;
int g2 = Query(qr);
return g1 == g2;
}
int bs(int now, int l = 0, int r = opt.size()) {
if (l == r) return opt[l];
int mid = (l + r) >> 1;
if (get(now, l, mid)) return bs(now, l, mid);
return bs(now, mid + 1, r);
}
void Solve(int nn) {
n = nn;
if (n == 1) {
Answer({1});
return;
}
qr.resize(n);
int now = findLeaf();
ans.pb(now + 1);
F0R(i, n - 1) {
vis[now] = 1;
qr[now] = 0;
opt.clear();
F0R(i, n) if (!vis[i]) opt.pb(i);
//cout << "for i = " << i << " and now = " << now + 1 << " opt is ";
//for(int on : opt) cout << on + 1 << ' '; cout << endl;
int f = bs(now);
ans.pb(f + 1);
now = f;
}
//for(int on : ans) cout << on << ' '; cout << endl;
Answer(ans);
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
208 KB |
# of queries: 2411 |
2 |
Correct |
30 ms |
208 KB |
# of queries: 2455 |
3 |
Correct |
38 ms |
308 KB |
# of queries: 2664 |
4 |
Correct |
31 ms |
208 KB |
# of queries: 2613 |
5 |
Correct |
44 ms |
208 KB |
# of queries: 2534 |
6 |
Correct |
46 ms |
208 KB |
# of queries: 2567 |
7 |
Correct |
38 ms |
208 KB |
# of queries: 2580 |
8 |
Correct |
29 ms |
208 KB |
# of queries: 2416 |
9 |
Correct |
34 ms |
208 KB |
# of queries: 2552 |
10 |
Correct |
16 ms |
312 KB |
# of queries: 1494 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 3 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
252 KB |
# of queries: 85 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 195 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
208 KB |
# of queries: 2411 |
2 |
Correct |
30 ms |
208 KB |
# of queries: 2455 |
3 |
Correct |
38 ms |
308 KB |
# of queries: 2664 |
4 |
Correct |
31 ms |
208 KB |
# of queries: 2613 |
5 |
Correct |
44 ms |
208 KB |
# of queries: 2534 |
6 |
Correct |
46 ms |
208 KB |
# of queries: 2567 |
7 |
Correct |
38 ms |
208 KB |
# of queries: 2580 |
8 |
Correct |
29 ms |
208 KB |
# of queries: 2416 |
9 |
Correct |
34 ms |
208 KB |
# of queries: 2552 |
10 |
Correct |
16 ms |
312 KB |
# of queries: 1494 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 3 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
252 KB |
# of queries: 85 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 195 |
17 |
Correct |
453 ms |
296 KB |
# of queries: 18050 |
18 |
Correct |
356 ms |
308 KB |
# of queries: 17249 |
19 |
Correct |
446 ms |
300 KB |
# of queries: 17493 |
20 |
Correct |
410 ms |
312 KB |
# of queries: 16333 |
21 |
Correct |
373 ms |
440 KB |
# of queries: 15390 |
22 |
Correct |
443 ms |
296 KB |
# of queries: 17681 |
23 |
Correct |
384 ms |
304 KB |
# of queries: 17244 |
24 |
Correct |
134 ms |
312 KB |
# of queries: 7909 |
25 |
Correct |
415 ms |
312 KB |
# of queries: 17150 |
26 |
Correct |
386 ms |
308 KB |
# of queries: 16033 |
27 |
Correct |
151 ms |
208 KB |
# of queries: 8020 |
28 |
Correct |
438 ms |
312 KB |
# of queries: 17955 |
29 |
Correct |
452 ms |
300 KB |
# of queries: 17935 |
30 |
Correct |
424 ms |
312 KB |
# of queries: 17955 |