#include <cstdio>
#include <iostream>
#include <vector>
#include "library.h"
using namespace std;
// Query()
// Answer()
int n;
int query(vector<int> v)
{
vector<int> m(n,0);
for(int i:v) m[i]=1;
return Query(m);
}
int get(int x,vector<int> v)
{
if(v.size()==1)
{
v.push_back(x);
if(query(v)==2)
return -1;
return v[0];
}
vector<int> mm;
for(int i=0;i<v.size()/2;i++)
mm.push_back(v[i]);
int cur=query(mm);
mm.push_back(x);
if(query(mm)<=cur)
{
mm.pop_back();
return get(x,mm);
}
mm.clear();
for(int i=v.size()/2;i<v.size();i++)
mm.push_back(v[i]);
return get(x,mm);
}
vector<int> adj[1005];
vector<int> ans;
int vis[1005];
void build(int x,int pa)
{
vis[x]=1;
ans.push_back(x+1);
for(int i:adj[x])
if(!vis[i]) build(i,x);
}
void Solve(int N)
{
n=N;
vector<int> hv1;
for(int i=0;i<N;i++)
{
vector<int> m(N,1);
m[i]=0;
if(Query(m)==1)
hv1.push_back(i);
}
for(int i=0;i<N;i++)
{
while(true){
if(adj[i].size()==2 || (adj[i].size()==1 && (hv1[0]==i||hv1[1]==i))) break;
vector<int> ss;
for(int j=0;j<N;j++)
{
bool ok=1;
for(int k:adj[i])
ok&=(k!=j);
ok&=(i!=j);
if(ok) ss.push_back(j);
}
int x=get(i,ss);
if(x!=-1) {adj[i].push_back(x); adj[x].push_back(i);}
}
//cout << i+1 << " Found " << x+1 << endl;
}
/*for(int i=0;i<n;i++)
{
cout << i+1 << ": ";
for(int j:adj[i]) cout << j+1 << " ";
cout << endl;
}*/
for(int i=0;i<n;i++)
{
if(adj[i].size()==1)
{
build(i,-1); break;
}
}
Answer(ans);
}
Compilation message
library.cpp: In function 'int get(int, std::vector<int>)':
library.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size()/2;i++)
~^~~~~~~~~~~
library.cpp:38:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=v.size()/2;i<v.size();i++)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
480 KB |
# of queries: 3315 |
2 |
Correct |
51 ms |
356 KB |
# of queries: 3291 |
3 |
Correct |
53 ms |
352 KB |
# of queries: 3487 |
4 |
Correct |
68 ms |
420 KB |
# of queries: 3477 |
5 |
Correct |
65 ms |
376 KB |
# of queries: 3471 |
6 |
Correct |
63 ms |
376 KB |
# of queries: 3485 |
7 |
Correct |
66 ms |
356 KB |
# of queries: 3467 |
8 |
Correct |
51 ms |
352 KB |
# of queries: 3321 |
9 |
Correct |
60 ms |
348 KB |
# of queries: 3447 |
10 |
Correct |
42 ms |
248 KB |
# of queries: 2049 |
11 |
Execution timed out |
3050 ms |
207104 KB |
Time limit exceeded |
12 |
Correct |
2 ms |
376 KB |
# of queries: 3 |
13 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 17 |
15 |
Correct |
5 ms |
376 KB |
# of queries: 139 |
16 |
Correct |
8 ms |
376 KB |
# of queries: 301 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
480 KB |
# of queries: 3315 |
2 |
Correct |
51 ms |
356 KB |
# of queries: 3291 |
3 |
Correct |
53 ms |
352 KB |
# of queries: 3487 |
4 |
Correct |
68 ms |
420 KB |
# of queries: 3477 |
5 |
Correct |
65 ms |
376 KB |
# of queries: 3471 |
6 |
Correct |
63 ms |
376 KB |
# of queries: 3485 |
7 |
Correct |
66 ms |
356 KB |
# of queries: 3467 |
8 |
Correct |
51 ms |
352 KB |
# of queries: 3321 |
9 |
Correct |
60 ms |
348 KB |
# of queries: 3447 |
10 |
Correct |
42 ms |
248 KB |
# of queries: 2049 |
11 |
Execution timed out |
3050 ms |
207104 KB |
Time limit exceeded |
12 |
Correct |
2 ms |
376 KB |
# of queries: 3 |
13 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 17 |
15 |
Correct |
5 ms |
376 KB |
# of queries: 139 |
16 |
Correct |
8 ms |
376 KB |
# of queries: 301 |
17 |
Incorrect |
627 ms |
516 KB |
Wrong Answer [3] |
18 |
Execution timed out |
3068 ms |
13980 KB |
Time limit exceeded |
19 |
Incorrect |
575 ms |
636 KB |
Wrong Answer [3] |
20 |
Execution timed out |
3049 ms |
14968 KB |
Time limit exceeded |
21 |
Correct |
566 ms |
504 KB |
# of queries: 19359 |
22 |
Incorrect |
647 ms |
520 KB |
Wrong Answer [3] |
23 |
Incorrect |
635 ms |
452 KB |
Wrong Answer [3] |
24 |
Correct |
232 ms |
484 KB |
# of queries: 10241 |
25 |
Execution timed out |
3022 ms |
13632 KB |
Time limit exceeded |
26 |
Execution timed out |
3044 ms |
15620 KB |
Time limit exceeded |
27 |
Correct |
234 ms |
352 KB |
# of queries: 10201 |
28 |
Incorrect |
611 ms |
376 KB |
Wrong Answer [3] |
29 |
Incorrect |
586 ms |
640 KB |
Wrong Answer [3] |
30 |
Incorrect |
646 ms |
472 KB |
Wrong Answer [3] |