# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954557 |
2024-03-28T07:00:31 Z |
Sharky |
Library (JOI18_library) |
C++17 |
|
27 ms |
472 KB |
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void clr(vector<int>& vt) {
for (int i = 0; i < vt.size(); i++) vt[i] = 0;
}
random_device rd;
mt19937 g(rd());
int outn;
int query(vector<int>& v) {
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);
cout << 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 = sqrt(sz), 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 clr(std::vector<int>&)':
library.cpp:6:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | for (int i = 0; i < vt.size(); i++) vt[i] = 0;
| ~~^~~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:78:5: warning: 'nxt' may be used uninitialized in this function [-Wmaybe-uninitialized]
78 | i = nxt;
| ~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
472 KB |
DO NOT WRITE ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
472 KB |
DO NOT WRITE ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |