# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
441577 |
2021-07-05T12:25:40 Z |
blue |
Library (JOI18_library) |
C++17 |
|
442 ms |
596 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, int lo, int hi)
{
// cerr << "find_neighbors " << I << ", ";
// for(int q:Q) cerr << q << ' ';
// cerr << '\n';
if(Q.size() == 0) return;
else if(hi == 0) return;
else if(neighbors[I].size() == 2) return;
else if(Q.size() == 1)
{
if (lo >= 1 || 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;
find_neighbors(I, Q1, neighbors_of_I, neighbors_of_I);
find_neighbors(I, Q2, max(0, lo - neighbors_of_I), hi - neighbors_of_I);
}
}
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, 0, 2 - neighbors[i].size());
}
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';
for(int r:res) cerr << r << ' ';
cerr << '\n';
Answer(res);
}
Compilation message
library.cpp: In function 'void find_neighbors(int, std::vector<int>, int, int)':
library.cpp:45:26: 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 = 0; i < Q.size()/2; i++) Q1.push_back(Q[i]);
| ~~^~~~~~~~~~~~
library.cpp:46:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = Q.size()/2; i < Q.size(); i++) Q2.push_back(Q[i]);
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
200 KB |
# of queries: 2660 |
2 |
Correct |
46 ms |
200 KB |
# of queries: 2692 |
3 |
Correct |
42 ms |
200 KB |
# of queries: 2786 |
4 |
Correct |
49 ms |
308 KB |
# of queries: 2840 |
5 |
Correct |
41 ms |
320 KB |
# of queries: 2798 |
6 |
Correct |
56 ms |
312 KB |
# of queries: 2818 |
7 |
Correct |
53 ms |
200 KB |
# of queries: 2836 |
8 |
Correct |
50 ms |
300 KB |
# of queries: 2700 |
9 |
Correct |
43 ms |
304 KB |
# of queries: 2800 |
10 |
Correct |
30 ms |
200 KB |
# of queries: 1606 |
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: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 13 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 100 |
16 |
Correct |
5 ms |
200 KB |
# of queries: 234 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
200 KB |
# of queries: 2660 |
2 |
Correct |
46 ms |
200 KB |
# of queries: 2692 |
3 |
Correct |
42 ms |
200 KB |
# of queries: 2786 |
4 |
Correct |
49 ms |
308 KB |
# of queries: 2840 |
5 |
Correct |
41 ms |
320 KB |
# of queries: 2798 |
6 |
Correct |
56 ms |
312 KB |
# of queries: 2818 |
7 |
Correct |
53 ms |
200 KB |
# of queries: 2836 |
8 |
Correct |
50 ms |
300 KB |
# of queries: 2700 |
9 |
Correct |
43 ms |
304 KB |
# of queries: 2800 |
10 |
Correct |
30 ms |
200 KB |
# of queries: 1606 |
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: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 13 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 100 |
16 |
Correct |
5 ms |
200 KB |
# of queries: 234 |
17 |
Correct |
342 ms |
336 KB |
# of queries: 18466 |
18 |
Correct |
336 ms |
596 KB |
# of queries: 18192 |
19 |
Correct |
385 ms |
456 KB |
# of queries: 18268 |
20 |
Correct |
307 ms |
456 KB |
# of queries: 17132 |
21 |
Correct |
293 ms |
340 KB |
# of queries: 16256 |
22 |
Correct |
316 ms |
352 KB |
# of queries: 18378 |
23 |
Correct |
336 ms |
452 KB |
# of queries: 18340 |
24 |
Correct |
109 ms |
580 KB |
# of queries: 8438 |
25 |
Correct |
354 ms |
328 KB |
# of queries: 17998 |
26 |
Correct |
341 ms |
576 KB |
# of queries: 16780 |
27 |
Correct |
156 ms |
320 KB |
# of queries: 8384 |
28 |
Correct |
442 ms |
348 KB |
# of queries: 19967 |
29 |
Correct |
393 ms |
584 KB |
# of queries: 19945 |
30 |
Correct |
397 ms |
328 KB |
# of queries: 19967 |