#include "library.h"
#include <vector>
#include <iostream>
using namespace std;
const int maxN = 1000;
int N1;
int ask_vector(vector<int> Q)
{
vector<int> M(N1, 0);
for(int q:Q) M[q-1] = 1;
return Query(M);
}
vector<int> neighbors[1+maxN];
bool neighboring(int i, int j)
{
bool flag = 0;
for(int x: neighbors[i]) if(x == j) flag = 1;
return flag;
}
void find_neighbors(int I, vector<int> Q)
{
// cerr << "find_neighbors " << I << ", ";
// for(int q:Q) cerr << q << ' ';
// cerr << '\n';
if(Q.size() == 0) return;
else if(neighbors[I].size() == 2) return;
else if(Q.size() == 1)
{
if(ask_vector(vector<int>{I, Q[0]}) == 1)
{
neighbors[I].push_back(Q[0]);
neighbors[Q[0]].push_back(I);
}
}
else
{
vector<int> Q1, Q2;
for(int i = 0; i < Q.size()/2; i++) Q1.push_back(Q[i]);
for(int i = Q.size()/2; i < Q.size(); i++) Q2.push_back(Q[i]);
int noI = ask_vector(Q1);
Q1.push_back(I);
int withI = ask_vector(Q1);
Q1.pop_back();
int neighbors_of_I = noI - withI + 1;
if(neighbors_of_I == 2)
{
find_neighbors(I, Q1);
}
else if(neighbors_of_I == 1)
{
find_neighbors(I, Q1);
find_neighbors(I, Q2);
}
else
{
find_neighbors(I, Q2);
}
}
}
void Solve(int N)
{
N1 = N;
for(int i = 1; i <= N; i++)
{
if(neighbors[i].size() == 2) continue;
vector<int> Q;
for(int j = 1; j <= N; j++)
{
if(i != j && !neighboring(i, j))
Q.push_back(j);
}
find_neighbors(i, Q);
}
vector<int> visit(N+1, 0);
vector<int> res;
for(int i = 1; i <= N; i++)
{
if(neighbors[i].size() <= 1)
{
res.push_back(i);
visit[i] = 1;
break;
}
}
for(int i = 0; i < N; i++)
{
int u = res[i];
for(int v: neighbors[u])
{
if(visit[v]) continue;
visit[v] = 1;
res.push_back(v);
}
}
// for(int r:res) cerr << r << ' ';
// cerr << '\n';
Answer(res);
}
Compilation message
library.cpp: In function 'void find_neighbors(int, std::vector<int>)':
library.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < Q.size()/2; i++) Q1.push_back(Q[i]);
| ~~^~~~~~~~~~~~
library.cpp:45:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = Q.size()/2; i < Q.size(); i++) Q2.push_back(Q[i]);
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
316 KB |
# of queries: 3872 |
2 |
Correct |
56 ms |
300 KB |
# of queries: 3816 |
3 |
Correct |
54 ms |
200 KB |
# of queries: 3964 |
4 |
Correct |
66 ms |
200 KB |
# of queries: 3947 |
5 |
Correct |
57 ms |
200 KB |
# of queries: 3989 |
6 |
Correct |
53 ms |
304 KB |
# of queries: 3948 |
7 |
Correct |
61 ms |
320 KB |
# of queries: 4025 |
8 |
Correct |
66 ms |
300 KB |
# of queries: 3773 |
9 |
Correct |
66 ms |
200 KB |
# of queries: 3991 |
10 |
Correct |
39 ms |
200 KB |
# of queries: 2226 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 6 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 15 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 121 |
16 |
Correct |
6 ms |
200 KB |
# of queries: 292 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
316 KB |
# of queries: 3872 |
2 |
Correct |
56 ms |
300 KB |
# of queries: 3816 |
3 |
Correct |
54 ms |
200 KB |
# of queries: 3964 |
4 |
Correct |
66 ms |
200 KB |
# of queries: 3947 |
5 |
Correct |
57 ms |
200 KB |
# of queries: 3989 |
6 |
Correct |
53 ms |
304 KB |
# of queries: 3948 |
7 |
Correct |
61 ms |
320 KB |
# of queries: 4025 |
8 |
Correct |
66 ms |
300 KB |
# of queries: 3773 |
9 |
Correct |
66 ms |
200 KB |
# of queries: 3991 |
10 |
Correct |
39 ms |
200 KB |
# of queries: 2226 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 6 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 15 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 121 |
16 |
Correct |
6 ms |
200 KB |
# of queries: 292 |
17 |
Runtime error |
386 ms |
460 KB |
Execution killed with signal 13 |
18 |
Halted |
0 ms |
0 KB |
- |