# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
768646 |
2023-06-28T10:29:51 Z |
raysh07 |
Library (JOI18_library) |
C++17 |
|
258 ms |
2768 KB |
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
vector<vector<int>> adj;
vector<int> comp;
vector<bool> vis;
vector<int> m;
int q = 0;
void init(int n){
for (int i = 0; i < n; i++) m[i] = 0;
}
int go(vector <int> m){
q++;
if (q > 20000) exit(0);
return Query(m);
}
bool check(int i, int j, int n){
if (i == j) return false;
for (int k = i; k <= j; k++){
m[k] = 1;
}
int cnt = 0;
for (auto x : adj[i]) m[x] = 0;
for (int i = 0; i < n; i++) cnt += m[i];
if (cnt == 1) {
init(n);
return false;
}
int a1 = go(m);
m[i] = 0;
int a2;
if (cnt != 2)
a2 = go(m);
else a2 = 1;
init(n);
return a2 >= a1;
}
void dfs(int u, int par = -1){
comp.push_back(u + 1);
vis[u] = true;
for (int v : adj[u]){
if (v != par){
assert(!vis[v]);
dfs(v, u);
}
}
}
void Solve(int n)
{
if (n == 1){
Answer({1});
return;
}
if (n == 2){
Answer({1, 2});
return;
}
m.resize(n, 0);
adj.resize(1e5 + 69);
vis.resize(1e5 + 69, false);
int ok = 0;
for (int i = 0; i < n; i++){
while (adj[i].size() < 2 && check(i, n - 1, n)){
int l = i + 1, r = n - 1;
while (l != r){
int m = (l + r)/2;
if (check(i, m, n)) r = m;
else l = m + 1;
}
ok++;
adj[i].push_back(l);
adj[l].push_back(i);
}
}
for (int i = 0; i < n; i++){
if (adj[i].size() == 1){
dfs(i);
break;
}
}
assert(comp.size() == n);
Answer(comp);
}
Compilation message
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from library.cpp:1:
library.cpp: In function 'void Solve(int)':
library.cpp:100:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
100 | assert(comp.size() == n);
| ~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2640 KB |
# of queries: 3020 |
2 |
Correct |
26 ms |
2660 KB |
# of queries: 2997 |
3 |
Correct |
27 ms |
2676 KB |
# of queries: 3182 |
4 |
Correct |
36 ms |
2676 KB |
# of queries: 3159 |
5 |
Correct |
38 ms |
2680 KB |
# of queries: 3170 |
6 |
Correct |
22 ms |
2676 KB |
# of queries: 3186 |
7 |
Correct |
30 ms |
2768 KB |
# of queries: 3178 |
8 |
Correct |
34 ms |
2660 KB |
# of queries: 3031 |
9 |
Correct |
30 ms |
2668 KB |
# of queries: 3140 |
10 |
Correct |
15 ms |
2676 KB |
# of queries: 1874 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
1 ms |
2640 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
2640 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
2640 KB |
# of queries: 117 |
16 |
Correct |
5 ms |
2640 KB |
# of queries: 267 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2640 KB |
# of queries: 3020 |
2 |
Correct |
26 ms |
2660 KB |
# of queries: 2997 |
3 |
Correct |
27 ms |
2676 KB |
# of queries: 3182 |
4 |
Correct |
36 ms |
2676 KB |
# of queries: 3159 |
5 |
Correct |
38 ms |
2680 KB |
# of queries: 3170 |
6 |
Correct |
22 ms |
2676 KB |
# of queries: 3186 |
7 |
Correct |
30 ms |
2768 KB |
# of queries: 3178 |
8 |
Correct |
34 ms |
2660 KB |
# of queries: 3031 |
9 |
Correct |
30 ms |
2668 KB |
# of queries: 3140 |
10 |
Correct |
15 ms |
2676 KB |
# of queries: 1874 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
1 ms |
2640 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
2640 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
2640 KB |
# of queries: 117 |
16 |
Correct |
5 ms |
2640 KB |
# of queries: 267 |
17 |
Incorrect |
258 ms |
2768 KB |
Unexpected end of file - token expected |
18 |
Halted |
0 ms |
0 KB |
- |