#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(228);
vector <int> ans;
#ifdef HOME
int Q = 0;
vector <int> pos;
int Query(vector <int> m) {
++Q;
vector <bool> used(m.size());
for (int i = 0; i < m.size(); ++i) {
if (m[i]) used[pos[i]] = 1;
}
int ans = 0;
for (int i = 0; i < used.size(); ++i) {
ans += used[i] && (!i || !used[i - 1]);
}
return ans;
}
void Answer(vector <int> a) {
cout << "Q = " << Q << '\n';
auto b = a; reverse(b.begin(), b.end());
if (a == ans || b == ans) cout << "correct\n";
else cout << "WA\n";
}
#else
#include "library.h"
#endif
#define ii pair <int, int>
#define app push_back
// Query()
// Answer()
int n_glob;
vector <ii> ed;
int query(vector<int> v) {
vector<int> m(n_glob,0);
for(int i:v) m[i]=1;
return Query(m);
}
int new_edge(vector <int> v) {
int ans = v.size() - query(v);
vector<int> m(n_glob,0);
for(int i:v) m[i]=1;
for (auto e : ed) ans -= m[e.first] && m[e.second];
return ans;
}
const int N = 2007;
vector <int> g[N];
void Solve(int n) {
n_glob = n;
for (int t = 0; t < n - 1; ++t) {
vector <int> cur;
for (int i = 0; i < n; ++i) cur.app(i);
while (cur.size() > 2) {
int m = (cur.size() + 1) >> 1;
while (1) {
shuffle(cur.begin(), cur.end(), rnd);
vector <int> tmp;
for (int i = 0; i < m; ++i) tmp.app(cur[i]);
if (new_edge(tmp)) {
cur = tmp;
break;
}
}
}
ed.app({cur[0], cur[1]});
g[cur[0]].app(cur[1]); g[cur[1]].app(cur[0]);
}
vector <int> ans;
for (int i = 0; i < n; ++i) {
if (g[i].size() == 1) {
ans.app(i); break;
}
}
int p = -1;
for (int i = 0; i < n - 1; ++i) {
for (int v : g[ans.back()]) {
if (v != p) {
p = ans.back();
ans.app(v);
break;
}
}
}
for (auto &e : ans) ++e;
Answer(ans);
}
#ifdef HOME
int main() {
for (int i = 1; i <= 800; ++i) ans.app(i);
shuffle(ans.begin(), ans.end(), rnd);
pos.resize(ans.size());
for (int i = 0; i < ans.size(); ++i) pos[ans[i] - 1] = i;
Solve(ans.size());
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
376 KB |
# of queries: 3678 |
2 |
Correct |
53 ms |
372 KB |
# of queries: 3609 |
3 |
Correct |
63 ms |
372 KB |
# of queries: 3912 |
4 |
Correct |
75 ms |
376 KB |
# of queries: 3968 |
5 |
Correct |
68 ms |
376 KB |
# of queries: 3978 |
6 |
Correct |
86 ms |
376 KB |
# of queries: 4107 |
7 |
Correct |
74 ms |
372 KB |
# of queries: 3951 |
8 |
Correct |
81 ms |
404 KB |
# of queries: 3747 |
9 |
Correct |
94 ms |
380 KB |
# of queries: 4146 |
10 |
Correct |
31 ms |
376 KB |
# of queries: 2217 |
11 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [4 |
12 |
Correct |
2 ms |
376 KB |
# of queries: 0 |
13 |
Correct |
2 ms |
248 KB |
# of queries: 3 |
14 |
Correct |
2 ms |
248 KB |
# of queries: 7 |
15 |
Correct |
5 ms |
376 KB |
# of queries: 153 |
16 |
Correct |
7 ms |
376 KB |
# of queries: 286 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
376 KB |
# of queries: 3678 |
2 |
Correct |
53 ms |
372 KB |
# of queries: 3609 |
3 |
Correct |
63 ms |
372 KB |
# of queries: 3912 |
4 |
Correct |
75 ms |
376 KB |
# of queries: 3968 |
5 |
Correct |
68 ms |
376 KB |
# of queries: 3978 |
6 |
Correct |
86 ms |
376 KB |
# of queries: 4107 |
7 |
Correct |
74 ms |
372 KB |
# of queries: 3951 |
8 |
Correct |
81 ms |
404 KB |
# of queries: 3747 |
9 |
Correct |
94 ms |
380 KB |
# of queries: 4146 |
10 |
Correct |
31 ms |
376 KB |
# of queries: 2217 |
11 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [4 |
12 |
Correct |
2 ms |
376 KB |
# of queries: 0 |
13 |
Correct |
2 ms |
248 KB |
# of queries: 3 |
14 |
Correct |
2 ms |
248 KB |
# of queries: 7 |
15 |
Correct |
5 ms |
376 KB |
# of queries: 153 |
16 |
Correct |
7 ms |
376 KB |
# of queries: 286 |
17 |
Incorrect |
684 ms |
648 KB |
Wrong Answer [3 |
18 |
Incorrect |
760 ms |
376 KB |
Wrong Answer [3 |
19 |
Incorrect |
734 ms |
664 KB |
Wrong Answer [3 |
20 |
Incorrect |
723 ms |
424 KB |
Wrong Answer [3 |
21 |
Incorrect |
717 ms |
516 KB |
Wrong Answer [3 |
22 |
Incorrect |
734 ms |
632 KB |
Wrong Answer [3 |
23 |
Incorrect |
706 ms |
640 KB |
Wrong Answer [3 |
24 |
Correct |
313 ms |
376 KB |
# of queries: 11266 |
25 |
Incorrect |
741 ms |
508 KB |
Wrong Answer [3 |
26 |
Incorrect |
710 ms |
528 KB |
Wrong Answer [3 |
27 |
Correct |
315 ms |
372 KB |
# of queries: 12403 |
28 |
Incorrect |
762 ms |
504 KB |
Wrong Answer [3 |
29 |
Incorrect |
737 ms |
544 KB |
Wrong Answer [3 |
30 |
Incorrect |
749 ms |
424 KB |
Wrong Answer [3 |