#include <cstdio>
#include <vector>
#include "library.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void Solve(int N)
{
if(N==1){
vector<int>ans={1};
Answer(ans);
return;
}
vector<int>M(N,1);
vector<int>ans;
vector<int>unknown;
for(int i=1;i<=N;i++)unknown.push_back(i);
for(int i=0;i<N;i++){//Locating an edge, letting it be L
M[i]=0;
if(Query(M)==1){
ans.push_back(i+1);
unknown.erase(remove(unknown.begin(),unknown.end(),i+1),unknown.end());
break;
}
M[i]=1;
}
while((int)ans.size()<N){
vector<int>space=unknown,a,b;
while(space.size()>1){
int halfsize=space.size()/2;
for(int i=0;i<halfsize;i++){
a.push_back(space[i]);
}
for(int i=halfsize;i<(int)space.size();i++){
b.push_back(space[i]);
}
//assert(a.size()&&b.size());
fill(M.begin(),M.end(),0);
for(auto x:a)M[x-1]=1;
int pre = Query(M);
M[ans.back()-1]=1;
int aft = Query(M);
if(pre==aft)space=a;
else space=b;
a.clear();
b.clear();
}
ans.push_back(*(space.begin()));
unknown.erase(remove(unknown.begin(),unknown.end(),*(space.begin())),unknown.end());
}
assert(ans.size()==N);
Answer(ans);
}
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:5:
library.cpp: In function 'void Solve(int)':
library.cpp:53:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | assert(ans.size()==N);
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
300 KB |
# of queries: 2375 |
2 |
Correct |
28 ms |
300 KB |
# of queries: 2409 |
3 |
Correct |
45 ms |
300 KB |
# of queries: 2648 |
4 |
Correct |
33 ms |
208 KB |
# of queries: 2595 |
5 |
Correct |
38 ms |
308 KB |
# of queries: 2508 |
6 |
Correct |
43 ms |
308 KB |
# of queries: 2551 |
7 |
Correct |
38 ms |
424 KB |
# of queries: 2544 |
8 |
Correct |
43 ms |
288 KB |
# of queries: 2420 |
9 |
Correct |
31 ms |
292 KB |
# of queries: 2546 |
10 |
Correct |
17 ms |
208 KB |
# of queries: 1474 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 77 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 183 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
300 KB |
# of queries: 2375 |
2 |
Correct |
28 ms |
300 KB |
# of queries: 2409 |
3 |
Correct |
45 ms |
300 KB |
# of queries: 2648 |
4 |
Correct |
33 ms |
208 KB |
# of queries: 2595 |
5 |
Correct |
38 ms |
308 KB |
# of queries: 2508 |
6 |
Correct |
43 ms |
308 KB |
# of queries: 2551 |
7 |
Correct |
38 ms |
424 KB |
# of queries: 2544 |
8 |
Correct |
43 ms |
288 KB |
# of queries: 2420 |
9 |
Correct |
31 ms |
292 KB |
# of queries: 2546 |
10 |
Correct |
17 ms |
208 KB |
# of queries: 1474 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 77 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 183 |
17 |
Correct |
472 ms |
300 KB |
# of queries: 17982 |
18 |
Correct |
365 ms |
328 KB |
# of queries: 17293 |
19 |
Correct |
404 ms |
432 KB |
# of queries: 17467 |
20 |
Correct |
409 ms |
444 KB |
# of queries: 16325 |
21 |
Correct |
319 ms |
312 KB |
# of queries: 15324 |
22 |
Correct |
409 ms |
300 KB |
# of queries: 17669 |
23 |
Correct |
451 ms |
304 KB |
# of queries: 17224 |
24 |
Correct |
145 ms |
324 KB |
# of queries: 7915 |
25 |
Correct |
407 ms |
328 KB |
# of queries: 17136 |
26 |
Correct |
395 ms |
436 KB |
# of queries: 15963 |
27 |
Correct |
128 ms |
288 KB |
# of queries: 8040 |
28 |
Correct |
369 ms |
312 KB |
# of queries: 15957 |
29 |
Correct |
415 ms |
320 KB |
# of queries: 15939 |
30 |
Correct |
397 ms |
324 KB |
# of queries: 15957 |