# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
438172 |
2021-06-27T17:32:50 Z |
blue |
Library (JOI18_library) |
C++17 |
|
451 ms |
456 KB |
#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
{
int noI = ask_vector(Q);
Q.push_back(I);
int withI = ask_vector(Q);
Q.pop_back();
if(withI == noI + 1) return;
vector<int> Q1, Q2;
for(int i = 0; i < Q.size()/2; i++)
if(neighbors[ Q[i] ].size() < 2)
Q1.push_back(Q[i]);
for(int i = Q.size()/2; i < Q.size(); i++)
if(neighbors[ Q[i] ].size() < 2)
Q2.push_back(Q[i]);
find_neighbors(I, Q1);
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 = i+1; j <= N; j++)
{
if(!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:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 0; i < Q.size()/2; i++)
| ~~^~~~~~~~~~~~
library.cpp:56:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = Q.size()/2; i < Q.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
348 KB |
# of queries: 3760 |
2 |
Correct |
68 ms |
344 KB |
# of queries: 3724 |
3 |
Correct |
59 ms |
332 KB |
# of queries: 3916 |
4 |
Correct |
71 ms |
444 KB |
# of queries: 4011 |
5 |
Correct |
71 ms |
340 KB |
# of queries: 4022 |
6 |
Correct |
63 ms |
324 KB |
# of queries: 3955 |
7 |
Correct |
57 ms |
456 KB |
# of queries: 4051 |
8 |
Correct |
66 ms |
448 KB |
# of queries: 3755 |
9 |
Correct |
68 ms |
328 KB |
# of queries: 4050 |
10 |
Correct |
36 ms |
332 KB |
# of queries: 2268 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 115 |
16 |
Correct |
6 ms |
200 KB |
# of queries: 297 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
348 KB |
# of queries: 3760 |
2 |
Correct |
68 ms |
344 KB |
# of queries: 3724 |
3 |
Correct |
59 ms |
332 KB |
# of queries: 3916 |
4 |
Correct |
71 ms |
444 KB |
# of queries: 4011 |
5 |
Correct |
71 ms |
340 KB |
# of queries: 4022 |
6 |
Correct |
63 ms |
324 KB |
# of queries: 3955 |
7 |
Correct |
57 ms |
456 KB |
# of queries: 4051 |
8 |
Correct |
66 ms |
448 KB |
# of queries: 3755 |
9 |
Correct |
68 ms |
328 KB |
# of queries: 4050 |
10 |
Correct |
36 ms |
332 KB |
# of queries: 2268 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 11 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 115 |
16 |
Correct |
6 ms |
200 KB |
# of queries: 297 |
17 |
Runtime error |
451 ms |
448 KB |
Execution killed with signal 13 |
18 |
Halted |
0 ms |
0 KB |
- |