#include<bits/stdc++.h>
#include"key.h"
using namespace std;
int sz[1005];
int out[1005], mb[1005];
vector<int> cycle[1005];
void EnsureKeyInfo(int N){
for(int i=1;i<=N;i++) {
TakeKey(i);
sz[i] = Explore();
if(sz[i] == 1) out[i] = i;
}
for(int i=1;i<=N;i++) {
if(mb[i]) continue;
vector<int> cand;
for(int j=1;j<=N;j++) {
if(sz[j] == sz[i]-1) cand.push_back(j);
}
random_shuffle(cand.begin(), cand.end());
for(int j : cand) {
TakeKey(i);
TakeKey(j);
int ret = Explore();
if(ret == sz[i]) {
out[i] = j;
break;
}
}
if(out[i]) continue;
cand.clear();
for(int j=i+1;j<=N;j++) {
if(i == j) continue;
if(sz[i] == sz[j]) cand.push_back(j);
}
if(cand.size() == sz[i]) {
cand.push_back(i);
sort(cand.begin(), cand.end());
int x = cand[0];
for(int j : cand) {
cycle[x].push_back(j);
mb[j] = x;
}
continue;
} else {
vector<int> rcand;
for(int j : cand) {
TakeKey(i);
TakeKey(j);
int ret = Explore();
if(ret == sz[i]) rcand.push_back(j);
}
rcand.push_back(i);
sort(rcand.begin(), rcand.end());
int x = rcand[0];
for(int j : rcand) {
cycle[x].push_back(j);
mb[j] = x;
}
}
}
for(int i=1;i<=N;i++) {
if(mb[i]) {
if(cycle[i].empty()) continue;
for(int x : cycle[i]) {
for(int y : cycle[i]) {
Report(x,y);
}
}
} else {
int prv = i;
Report(i,i);
int x = out[i];
while(x != prv) {
if(mb[x]) {
for(int j : cycle[mb[x]]) {
Report(i, j);
}
break;
} else {
Report(i, x);
prv = x;
x = out[x];
}
}
}
}
}
Compilation message
key.cpp: In function 'void EnsureKeyInfo(int)':
key.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cand.size() == sz[i]) {
~~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
740 KB |
Output is correct |
3 |
Correct |
4 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
848 KB |
Output is correct |
5 |
Correct |
4 ms |
900 KB |
Output is correct |
6 |
Correct |
4 ms |
900 KB |
Output is correct |
7 |
Correct |
3 ms |
924 KB |
Output is correct |
8 |
Correct |
4 ms |
1052 KB |
Output is correct |
9 |
Correct |
4 ms |
1052 KB |
Output is correct |
10 |
Correct |
4 ms |
1052 KB |
Output is correct |
11 |
Correct |
4 ms |
1052 KB |
Output is correct |
12 |
Correct |
4 ms |
1052 KB |
Output is correct |
13 |
Correct |
4 ms |
1052 KB |
Output is correct |
14 |
Correct |
3 ms |
1052 KB |
Output is correct |
15 |
Correct |
4 ms |
1104 KB |
Output is correct |
16 |
Correct |
3 ms |
1104 KB |
Output is correct |
17 |
Correct |
4 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
740 KB |
Output is correct |
3 |
Correct |
4 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
848 KB |
Output is correct |
5 |
Correct |
4 ms |
900 KB |
Output is correct |
6 |
Correct |
4 ms |
900 KB |
Output is correct |
7 |
Correct |
3 ms |
924 KB |
Output is correct |
8 |
Correct |
4 ms |
1052 KB |
Output is correct |
9 |
Correct |
4 ms |
1052 KB |
Output is correct |
10 |
Correct |
4 ms |
1052 KB |
Output is correct |
11 |
Correct |
4 ms |
1052 KB |
Output is correct |
12 |
Correct |
4 ms |
1052 KB |
Output is correct |
13 |
Correct |
4 ms |
1052 KB |
Output is correct |
14 |
Correct |
3 ms |
1052 KB |
Output is correct |
15 |
Correct |
4 ms |
1104 KB |
Output is correct |
16 |
Correct |
3 ms |
1104 KB |
Output is correct |
17 |
Correct |
4 ms |
1104 KB |
Output is correct |
18 |
Correct |
7 ms |
1896 KB |
Output is correct |
19 |
Correct |
5 ms |
1944 KB |
Output is correct |
20 |
Runtime error |
10 ms |
1944 KB |
Execution failed because the return code was nonzero |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
740 KB |
Output is correct |
3 |
Correct |
4 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
848 KB |
Output is correct |
5 |
Correct |
4 ms |
900 KB |
Output is correct |
6 |
Correct |
4 ms |
900 KB |
Output is correct |
7 |
Correct |
3 ms |
924 KB |
Output is correct |
8 |
Correct |
4 ms |
1052 KB |
Output is correct |
9 |
Correct |
4 ms |
1052 KB |
Output is correct |
10 |
Correct |
4 ms |
1052 KB |
Output is correct |
11 |
Correct |
4 ms |
1052 KB |
Output is correct |
12 |
Correct |
4 ms |
1052 KB |
Output is correct |
13 |
Correct |
4 ms |
1052 KB |
Output is correct |
14 |
Correct |
3 ms |
1052 KB |
Output is correct |
15 |
Correct |
4 ms |
1104 KB |
Output is correct |
16 |
Correct |
3 ms |
1104 KB |
Output is correct |
17 |
Correct |
4 ms |
1104 KB |
Output is correct |
18 |
Correct |
7 ms |
1896 KB |
Output is correct |
19 |
Correct |
5 ms |
1944 KB |
Output is correct |
20 |
Runtime error |
10 ms |
1944 KB |
Execution failed because the return code was nonzero |
21 |
Halted |
0 ms |
0 KB |
- |