# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
125321 |
2019-07-05T05:42:22 Z |
khsoo01 |
Park (JOI17_park) |
C++11 |
|
305 ms |
788 KB |
#include<bits/stdc++.h>
#include "park.h"
using namespace std;
namespace {
const int N = 1505;
int place[N];
bool vis[N], blk[N];
int n;
vector<int> tree[N];
}
int check (int S, int E, vector<int> &O) {
for(int i=0;i<n;i++) place[i] = 0;
for(auto &T : O) place[T] = 1;
place[S] = 1;
place[E] = 1;
return Ask(min(S, E), max(S, E), place);
}
int Find (int A, int B, vector<int> &O) {
int S = 0, E = O.size();
while(S<E) {
int M = (S+E)/2;
vector<int> V;
for(int i=0;i<M;i++) {
V.push_back(O[i]);
}
check(A, B, V) ? E = M : S = M+1;
}
return (S ? O[S-1] : A);
}
void preorder (int C, int P, vector<int> &O) {
O.push_back(C);
for(auto &T: tree[C]) {
if(T == P || blk[T]) continue;
preorder(T, C, O);
}
}
void construct (int S, int E, vector<int> &O) {
vis[S] = true;
vis[E] = true;
int M = Find(S, E, O);
if(M == S) {
tree[S].push_back(E);
tree[E].push_back(S);
Answer(min(S, E), max(S, E));
}
else {
construct(S, M, O);
construct(M, E, O);
}
}
void Try (int P, int I) {
vector<int> V;
preorder(I, -1, V);
if(!check(I, P, V)) return;
int J = Find(I, P, V);
Answer(min(P, J), max(P, J));
blk[J] = true;
for(auto &T : tree[J]) {
if(!blk[T]) Try(P, T);
}
}
void Detect (int T, int N) {
n = N;
for(int i=1;i<n;i++) {
if(vis[i]) continue;
vector<int> V;
for(int j=1;j<n;j++) {
if(tree[j].empty()) V.push_back(j);
}
preorder(0, -1, V);
int M = Find(0, i, V);
if(tree[M].empty()) M = 0;
V.clear();
for(int j=1;j<n;j++) {
if(tree[j].empty()) V.push_back(j);
}
construct(M, i, V);
}
vector<int> X;
preorder(0, -1, X);
for(int i=(int)X.size()-1;i>0;i--) {
for(int j=0;j<X.size();j++) {
blk[X[j]] = (j >= i);
}
int I;
for(auto &T : tree[X[i]]) {
if(!blk[T]) {
I = T;
break;
}
}
blk[I] = true;
for(auto &T : tree[I]) {
if(!blk[T]) Try(X[i], T);
}
}
}
Compilation message
park.cpp: In function 'void Detect(int, int)':
park.cpp:90:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<X.size();j++) {
~^~~~~~~~~
park.cpp:93:7: warning: 'I' may be used uninitialized in this function [-Wmaybe-uninitialized]
int I;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
27 ms |
380 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
17 ms |
380 KB |
Output is correct |
5 |
Correct |
30 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
632 KB |
Output is correct |
2 |
Correct |
305 ms |
656 KB |
Output is correct |
3 |
Correct |
237 ms |
632 KB |
Output is correct |
4 |
Correct |
153 ms |
572 KB |
Output is correct |
5 |
Correct |
148 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
788 KB |
Output is correct |
2 |
Correct |
254 ms |
540 KB |
Output is correct |
3 |
Correct |
256 ms |
616 KB |
Output is correct |
4 |
Correct |
260 ms |
568 KB |
Output is correct |
5 |
Correct |
260 ms |
604 KB |
Output is correct |
6 |
Correct |
244 ms |
676 KB |
Output is correct |
7 |
Correct |
252 ms |
632 KB |
Output is correct |
8 |
Correct |
255 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
504 KB |
Output is correct |
2 |
Correct |
246 ms |
636 KB |
Output is correct |
3 |
Correct |
242 ms |
644 KB |
Output is correct |
4 |
Correct |
193 ms |
504 KB |
Output is correct |
5 |
Correct |
227 ms |
636 KB |
Output is correct |
6 |
Correct |
198 ms |
760 KB |
Output is correct |
7 |
Correct |
159 ms |
752 KB |
Output is correct |
8 |
Correct |
232 ms |
772 KB |
Output is correct |
9 |
Correct |
197 ms |
652 KB |
Output is correct |
10 |
Correct |
239 ms |
760 KB |
Output is correct |
11 |
Correct |
246 ms |
632 KB |
Output is correct |
12 |
Correct |
243 ms |
712 KB |
Output is correct |
13 |
Correct |
169 ms |
504 KB |
Output is correct |
14 |
Correct |
257 ms |
780 KB |
Output is correct |
15 |
Correct |
164 ms |
504 KB |
Output is correct |
16 |
Correct |
256 ms |
692 KB |
Output is correct |
17 |
Correct |
163 ms |
688 KB |
Output is correct |
18 |
Correct |
240 ms |
688 KB |
Output is correct |
19 |
Correct |
172 ms |
636 KB |
Output is correct |
20 |
Correct |
221 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
672 KB |
Output is correct |
2 |
Correct |
272 ms |
544 KB |
Output is correct |
3 |
Correct |
263 ms |
504 KB |
Output is correct |
4 |
Correct |
240 ms |
632 KB |
Output is correct |
5 |
Correct |
299 ms |
760 KB |
Output is correct |
6 |
Correct |
168 ms |
632 KB |
Output is correct |
7 |
Correct |
231 ms |
632 KB |
Output is correct |
8 |
Correct |
234 ms |
760 KB |
Output is correct |
9 |
Correct |
239 ms |
692 KB |
Output is correct |
10 |
Correct |
234 ms |
604 KB |
Output is correct |
11 |
Correct |
212 ms |
632 KB |
Output is correct |
12 |
Correct |
199 ms |
604 KB |
Output is correct |
13 |
Correct |
235 ms |
676 KB |
Output is correct |
14 |
Correct |
276 ms |
504 KB |
Output is correct |
15 |
Correct |
243 ms |
632 KB |
Output is correct |
16 |
Correct |
252 ms |
632 KB |
Output is correct |
17 |
Correct |
164 ms |
780 KB |
Output is correct |
18 |
Correct |
229 ms |
632 KB |
Output is correct |