#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
bool use[2000];
vector<int> v1, v2;
int find(int left,int N){
vector<int> M(N);
int i;
for (i = 0; i < v1.size(); i++) M[v1[i]] = 1;
int a = Query(M);
M[left] = 1;
int b = Query(M);
vector<int> *live, *erase;
if (a == b) live = &v1, erase = &v2;
else live = &v2, erase = &v1;
if (live->size() == 1) return live->back();
erase->clear();
for (i = 0, b = live->size() / 2; i < b; i++){
a = live->back();
live->pop_back();
erase->push_back(a);
}
return find(left, N);
}
void Solve(int N)
{
vector<int> M(N);
vector<int> res;
int i,j;
int A;
if (N == 1){
res.push_back(1);
Answer(res);
return;
}
for (i = 0; i < N; i++) {
M[i] = 1;
}
for (i = 0; i < N; i++){
M[i] = 0;
A = Query(M);
if (A == 1){
res.push_back(i + 1);
use[i] = 1;
break;
}
M[i] = 1;
}
int t = 1;
for (i = 1; i < N; i++){
t = 1;
v1.clear();
v2.clear();
for (j = 0; j < N; j++){
if (use[j]) continue;
if (t) v1.push_back(j);
else v2.push_back(j);
t ^= 1;
}
if (i == N - 1){
res.push_back(v1[0]+1);
break;
}
int nxt = find(res.back()-1, N);
//int nxt = 1;
use[nxt] = 1;
res.push_back(nxt+1);
}
Answer(res);
}
Compilation message
library.cpp: In function 'int find(int, int)':
library.cpp:12:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < v1.size(); i++) M[v1[i]] = 1;
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
392 KB |
Output is correct |
2 |
Correct |
45 ms |
392 KB |
Output is correct |
3 |
Correct |
46 ms |
496 KB |
Output is correct |
4 |
Correct |
44 ms |
496 KB |
Output is correct |
5 |
Correct |
39 ms |
496 KB |
Output is correct |
6 |
Correct |
39 ms |
496 KB |
Output is correct |
7 |
Correct |
40 ms |
496 KB |
Output is correct |
8 |
Correct |
35 ms |
504 KB |
Output is correct |
9 |
Correct |
40 ms |
504 KB |
Output is correct |
10 |
Correct |
19 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
392 KB |
Output is correct |
2 |
Correct |
45 ms |
392 KB |
Output is correct |
3 |
Correct |
46 ms |
496 KB |
Output is correct |
4 |
Correct |
44 ms |
496 KB |
Output is correct |
5 |
Correct |
39 ms |
496 KB |
Output is correct |
6 |
Correct |
39 ms |
496 KB |
Output is correct |
7 |
Correct |
40 ms |
496 KB |
Output is correct |
8 |
Correct |
35 ms |
504 KB |
Output is correct |
9 |
Correct |
40 ms |
504 KB |
Output is correct |
10 |
Correct |
19 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
484 ms |
692 KB |
Output is correct |
18 |
Correct |
477 ms |
692 KB |
Output is correct |
19 |
Correct |
472 ms |
692 KB |
Output is correct |
20 |
Correct |
404 ms |
692 KB |
Output is correct |
21 |
Correct |
399 ms |
704 KB |
Output is correct |
22 |
Correct |
461 ms |
704 KB |
Output is correct |
23 |
Correct |
484 ms |
704 KB |
Output is correct |
24 |
Correct |
152 ms |
704 KB |
Output is correct |
25 |
Correct |
486 ms |
704 KB |
Output is correct |
26 |
Correct |
425 ms |
704 KB |
Output is correct |
27 |
Correct |
160 ms |
704 KB |
Output is correct |
28 |
Correct |
481 ms |
716 KB |
Output is correct |
29 |
Correct |
498 ms |
716 KB |
Output is correct |
30 |
Correct |
470 ms |
716 KB |
Output is correct |