#include"bits/stdc++.h"
#include"library.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };
namespace A{
int N;
vector<pair<int,int>> e;
int siz(int l, int r){
int ret = r-l;
rep(i, e.size()){
if(l <= e[i].first && e[i].first < r && l <= e[i].second && e[i].second < r) ret--;
}
return ret;
}
int Search1(int l, int r, int x){
if(l+1 == r) return l;
vector<int> tmp(N, 0);
int m = (l+r)/2;
for(int i=l; i<m; i++) tmp[i] = 1;
tmp[x] = 1;
int ret = Query(tmp);
if(siz(l, m) == ret) return Search1(l, m, x);
else return Search1(m, r, x);
}
pair<int, int> Search2(int l, int r, int x){
vector<int> tmp(N, 0);
int m = (l+r)/2;
for(int i=l; i<m; i++) tmp[i] = 1;
tmp[x] = 1;
int ret = Query(tmp);
if(siz(l, m)-1 == ret) return Search2(l, m, x);
else if(siz(l, m)+1 == ret) return Search2(m, r, x);
else return mp(Search1(l, m, x), Search1(m, r, x));
}
vector<int> ls[1000];
void dfs(int n, int b, vector<int>& ans){
ans.pb(n+1);
rep(i, ls[n].size()){
if(ls[n][i] == b) continue;
dfs(ls[n][i], n, ans);
}
}
}
void Solve(int _N){
using namespace A;
N = _N;
if(N == 1){
Answer({ 1 });
return;
}
int memo[1000];
rep(i, N){
vector<int> tmp(N, 0);
rep(j, i+1) tmp[j] = 1;
memo[i] = Query(tmp);
if(i > 0 && memo[i-1]+1 != memo[i]){
pair<int, int> ret = mp(-1,-1);
if(memo[i-1] == memo[i]) ret.first = Search1(0, i, i);
else ret = Search2(0, i, i);
e.pb({ ret.first, i });
if(ret.second != -1) e.pb({ ret.second, i });
}
}
rep(i, e.size()){
ls[e[i].first].pb(e[i].second);
ls[e[i].second].pb(e[i].first);
}
rep(i, N){
if(ls[i].size() == 1){
vector<int> ans;
dfs(i, -1, ans);
Answer(ans);
return;
}
}
}
Compilation message
library.cpp: In function 'int A::siz(int, int)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:22:3: note: in expansion of macro 'rep'
22 | rep(i, e.size()){
| ^~~
library.cpp: In function 'void A::dfs(int, int, std::vector<int>&)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:55:3: note: in expansion of macro 'rep'
55 | rep(i, ls[n].size()){
| ^~~
library.cpp: In function 'void Solve(int)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:70:2: note: in expansion of macro 'rep'
70 | rep(i, N){
| ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:72:3: note: in expansion of macro 'rep'
72 | rep(j, i+1) tmp[j] = 1;
| ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:83:2: note: in expansion of macro 'rep'
83 | rep(i, e.size()){
| ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
library.cpp:87:2: note: in expansion of macro 'rep'
87 | rep(i, N){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
316 KB |
# of queries: 1369 |
2 |
Correct |
33 ms |
312 KB |
# of queries: 1408 |
3 |
Correct |
17 ms |
320 KB |
# of queries: 1442 |
4 |
Correct |
24 ms |
308 KB |
# of queries: 1448 |
5 |
Correct |
32 ms |
320 KB |
# of queries: 1460 |
6 |
Correct |
25 ms |
316 KB |
# of queries: 1443 |
7 |
Correct |
29 ms |
324 KB |
# of queries: 1459 |
8 |
Correct |
26 ms |
312 KB |
# of queries: 1377 |
9 |
Correct |
20 ms |
316 KB |
# of queries: 1451 |
10 |
Correct |
13 ms |
200 KB |
# of queries: 862 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
236 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 53 |
16 |
Correct |
2 ms |
200 KB |
# of queries: 118 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
316 KB |
# of queries: 1369 |
2 |
Correct |
33 ms |
312 KB |
# of queries: 1408 |
3 |
Correct |
17 ms |
320 KB |
# of queries: 1442 |
4 |
Correct |
24 ms |
308 KB |
# of queries: 1448 |
5 |
Correct |
32 ms |
320 KB |
# of queries: 1460 |
6 |
Correct |
25 ms |
316 KB |
# of queries: 1443 |
7 |
Correct |
29 ms |
324 KB |
# of queries: 1459 |
8 |
Correct |
26 ms |
312 KB |
# of queries: 1377 |
9 |
Correct |
20 ms |
316 KB |
# of queries: 1451 |
10 |
Correct |
13 ms |
200 KB |
# of queries: 862 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
236 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 53 |
16 |
Correct |
2 ms |
200 KB |
# of queries: 118 |
17 |
Correct |
199 ms |
348 KB |
# of queries: 9700 |
18 |
Correct |
167 ms |
372 KB |
# of queries: 9535 |
19 |
Correct |
165 ms |
476 KB |
# of queries: 9596 |
20 |
Correct |
192 ms |
472 KB |
# of queries: 8916 |
21 |
Correct |
104 ms |
340 KB |
# of queries: 8436 |
22 |
Correct |
234 ms |
352 KB |
# of queries: 9629 |
23 |
Correct |
194 ms |
352 KB |
# of queries: 9636 |
24 |
Correct |
98 ms |
324 KB |
# of queries: 4431 |
25 |
Correct |
205 ms |
352 KB |
# of queries: 9399 |
26 |
Correct |
194 ms |
352 KB |
# of queries: 8760 |
27 |
Correct |
62 ms |
328 KB |
# of queries: 4426 |
28 |
Correct |
207 ms |
348 KB |
# of queries: 9967 |
29 |
Correct |
151 ms |
448 KB |
# of queries: 9956 |
30 |
Correct |
148 ms |
460 KB |
# of queries: 9967 |