# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1073455 |
2024-08-24T14:58:25 Z |
AdamGS |
Park (JOI17_park) |
C++17 |
|
140 ms |
1880 KB |
#include "park.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1407;
static int Place[1400];
vector<int>V[LIM], pos, ord;
int odw[LIM], oc[LIM], usun[LIM], n, ile;
void DFS(int x, int o) {
for(auto i : V[x]) if(i!=o) DFS(i, x);
pos.pb(x);
}
int znajdz_ojca(int x) {
pos.clear();
DFS(0, 0);
reverse(all(pos));
int po=0, ko=(int)pos.size()-1;
while(po<ko) {
int sr=(po+ko)/2;
rep(i, n) Place[i]=0;
rep(i, sr+1) Place[pos[i]]=1;
rep(i, n) if(!odw[i]) Place[i]=1;
if(Ask(0, x, Place)) ko=sr; else po=sr+1;
}
return pos[po];
}
void sciezka(int a, int b) {
rep(i, n) Place[i]=0;
Place[a]=Place[b]=1;
if(Ask(min(a, b), max(a, b), Place)) {
odw[b]=1; ++ile;
V[a].pb(b);
V[b].pb(a);
Answer(min(a, b), max(a, b));
return;
}
vector<int>T;
rep(i, n) if(!odw[i] && i!=b) T.pb(i);
int po=0, ko=(int)T.size()-1;
while(po<ko) {
int sr=(po+ko)/2;
rep(i, n) Place[i]=0;
rep(i, sr+1) Place[T[i]]=1;
Place[a]=Place[b]=1;
if(Ask(min(a, b), max(a, b), Place)) ko=sr; else po=sr+1;
}
sciezka(a, T[po]);
sciezka(T[po], b);
}
void DFS2(int x, int o) {
oc[x]=o;
for(auto i : V[x]) if(i!=o) DFS2(i, x);
}
void DFS4(int x) {
if(usun[x]) return;
ord.pb(x);
for(auto i : V[x]) if(i!=oc[x]) DFS4(i);
}
void DFS3(int x, int p) {
for(auto i : V[x]) if(i!=oc[x]) {
while(true) {
ord.clear();
DFS4(i);
if(ord.size()==0) break;
rep(j, n) Place[j]=0;
Place[p]=1;
for(auto j : ord) Place[j]=1;
if(!Ask(min(p, ord[0]), max(p, ord[0]), Place)) break;
int po=0, ko=ord.size()-1;
while(po<ko) {
int sr=(po+ko)/2;
rep(j, n) Place[j]=0;
Place[p]=1;
rep(j, sr+1) Place[ord[j]]=1;
if(Ask(min(p, ord[0]), max(p, ord[0]), Place)) ko=sr; else po=sr+1;
}
usun[ord[po]]=1;
if(p<ord[po]) Answer(p, ord[po]);
DFS3(ord[po], p);
}
}
}
void Detect(int T, int N) {
n=N;
odw[0]=ile=1;
while(ile<n) {
int x=-1;
rep(i, n) if(!odw[i]) {
x=i;
break;
}
int p=znajdz_ojca(x);
sciezka(p, x);
}
rep(a, n) {
DFS2(a, a);
rep(b, n) usun[b]=0;
for(auto b : V[a]) usun[b]=1;
for(auto b : V[a]) DFS3(b, a);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
536 KB |
Output is correct |
5 |
Correct |
33 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
600 KB |
Output is correct |
2 |
Correct |
135 ms |
600 KB |
Output is correct |
3 |
Correct |
92 ms |
1880 KB |
Output is correct |
4 |
Correct |
76 ms |
612 KB |
Output is correct |
5 |
Correct |
69 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
604 KB |
Output is correct |
2 |
Correct |
97 ms |
600 KB |
Output is correct |
3 |
Correct |
104 ms |
604 KB |
Output is correct |
4 |
Correct |
95 ms |
600 KB |
Output is correct |
5 |
Correct |
125 ms |
604 KB |
Output is correct |
6 |
Correct |
96 ms |
604 KB |
Output is correct |
7 |
Correct |
99 ms |
600 KB |
Output is correct |
8 |
Correct |
99 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
604 KB |
Output is correct |
2 |
Correct |
100 ms |
656 KB |
Output is correct |
3 |
Correct |
99 ms |
604 KB |
Output is correct |
4 |
Correct |
93 ms |
672 KB |
Output is correct |
5 |
Correct |
113 ms |
712 KB |
Output is correct |
6 |
Correct |
95 ms |
768 KB |
Output is correct |
7 |
Correct |
88 ms |
604 KB |
Output is correct |
8 |
Correct |
100 ms |
668 KB |
Output is correct |
9 |
Correct |
99 ms |
668 KB |
Output is correct |
10 |
Correct |
93 ms |
600 KB |
Output is correct |
11 |
Correct |
93 ms |
600 KB |
Output is correct |
12 |
Correct |
106 ms |
708 KB |
Output is correct |
13 |
Correct |
80 ms |
600 KB |
Output is correct |
14 |
Correct |
104 ms |
600 KB |
Output is correct |
15 |
Correct |
81 ms |
600 KB |
Output is correct |
16 |
Correct |
113 ms |
604 KB |
Output is correct |
17 |
Correct |
68 ms |
604 KB |
Output is correct |
18 |
Correct |
98 ms |
600 KB |
Output is correct |
19 |
Correct |
78 ms |
604 KB |
Output is correct |
20 |
Correct |
92 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
600 KB |
Output is correct |
2 |
Correct |
121 ms |
684 KB |
Output is correct |
3 |
Correct |
102 ms |
604 KB |
Output is correct |
4 |
Correct |
106 ms |
604 KB |
Output is correct |
5 |
Correct |
134 ms |
656 KB |
Output is correct |
6 |
Correct |
81 ms |
604 KB |
Output is correct |
7 |
Correct |
121 ms |
604 KB |
Output is correct |
8 |
Correct |
90 ms |
604 KB |
Output is correct |
9 |
Correct |
102 ms |
812 KB |
Output is correct |
10 |
Correct |
113 ms |
600 KB |
Output is correct |
11 |
Correct |
100 ms |
672 KB |
Output is correct |
12 |
Correct |
114 ms |
724 KB |
Output is correct |
13 |
Correct |
93 ms |
700 KB |
Output is correct |
14 |
Correct |
125 ms |
604 KB |
Output is correct |
15 |
Correct |
108 ms |
736 KB |
Output is correct |
16 |
Correct |
105 ms |
604 KB |
Output is correct |
17 |
Correct |
93 ms |
600 KB |
Output is correct |
18 |
Correct |
106 ms |
600 KB |
Output is correct |