# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954570 |
2024-03-28T07:14:37 Z |
Sharky |
Library (JOI18_library) |
C++17 |
|
2000 ms |
980 KB |
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
random_device rd;
mt19937 g(rd());
int outn, qc = 0;
void TLE() {
TLE();
}
int query(vector<int>& v) {
qc++;
if (qc > 20000) TLE();
vector<int> vt(outn, 0);
for (auto x : v) vt[x - 1] = 1;
v.clear();
return Query(vt);
}
vector<int> adj[1001], ans;
void dfs(int u, int p = -1) {
ans.push_back(u);
for (int v : adj[u]) if (v != p) dfs(v, u);
}
void Solve(int n) {
if (n == 1) {
ans = {1};
Answer(ans);
return;
}
outn = n;
vector<int> ee;
vector<int> deg(n+1, 2), cand, vt;
for (int sk = 1; sk <= n; sk++) {
for (int i = 1; i <= n; i++) if (i != sk) vt.push_back(i);
if (query(vt) == 1) ee.push_back(sk), deg[sk]--;
cand.push_back(sk);
}
int ender = ee[0], i = ee[0], o = ee[1];
while (i != o) {
int sz = cand.size();
int rt = 25, nxt;
shuffle(cand.begin(), cand.end(), g);
vector<int> er;
for (int j = 0; j < sz; j += rt) {
for (int k = j; k < min(sz, j + rt); k++) {
vt.push_back(cand[k]);
if (cand[k] == i) continue;
}
vector<int> vt2 = vt;
vt2.push_back(i);
int extra = query(vt2) - query(vt);
if (extra) continue;
for (int k = j; k < min(sz, j + rt); k++) {
if (cand[k] == i) continue;
vt.push_back(i);
vt.push_back(cand[k]);
if (query(vt) == 1) {
deg[cand[k]]--, deg[i]--;
adj[cand[k]].push_back(i);
adj[i].push_back(cand[k]);
nxt = cand[k];
if (!deg[cand[k]]) er.push_back(k);
break;
}
}
if (!deg[i]) break;
}
reverse(er.begin(), er.end());
for (auto x : er) cand.erase(cand.begin() + x);
for (int j = cand.size() - 1; j >= 0; j--) if (cand[j] == i) {
cand.erase(cand.begin() + j);
break;
}
i = nxt;
}
dfs(ender);
Answer(ans);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:79:5: warning: 'nxt' may be used uninitialized in this function [-Wmaybe-uninitialized]
79 | i = nxt;
| ~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
476 KB |
# of queries: 4926 |
2 |
Correct |
43 ms |
464 KB |
# of queries: 4765 |
3 |
Correct |
42 ms |
960 KB |
# of queries: 4928 |
4 |
Correct |
33 ms |
712 KB |
# of queries: 4646 |
5 |
Correct |
35 ms |
964 KB |
# of queries: 4912 |
6 |
Correct |
43 ms |
472 KB |
# of queries: 5352 |
7 |
Correct |
33 ms |
980 KB |
# of queries: 4961 |
8 |
Correct |
42 ms |
708 KB |
# of queries: 4938 |
9 |
Correct |
45 ms |
452 KB |
# of queries: 4730 |
10 |
Correct |
23 ms |
476 KB |
# of queries: 2825 |
11 |
Correct |
1 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 5 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 10 |
14 |
Correct |
1 ms |
344 KB |
# of queries: 16 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 115 |
16 |
Correct |
2 ms |
472 KB |
# of queries: 275 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
476 KB |
# of queries: 4926 |
2 |
Correct |
43 ms |
464 KB |
# of queries: 4765 |
3 |
Correct |
42 ms |
960 KB |
# of queries: 4928 |
4 |
Correct |
33 ms |
712 KB |
# of queries: 4646 |
5 |
Correct |
35 ms |
964 KB |
# of queries: 4912 |
6 |
Correct |
43 ms |
472 KB |
# of queries: 5352 |
7 |
Correct |
33 ms |
980 KB |
# of queries: 4961 |
8 |
Correct |
42 ms |
708 KB |
# of queries: 4938 |
9 |
Correct |
45 ms |
452 KB |
# of queries: 4730 |
10 |
Correct |
23 ms |
476 KB |
# of queries: 2825 |
11 |
Correct |
1 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 5 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 10 |
14 |
Correct |
1 ms |
344 KB |
# of queries: 16 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 115 |
16 |
Correct |
2 ms |
472 KB |
# of queries: 275 |
17 |
Execution timed out |
3003 ms |
732 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |