# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
344079 |
2021-01-05T06:17:39 Z |
Kerim |
Library (JOI18_library) |
C++17 |
|
442 ms |
748 KB |
#include <cstdio>
#include <vector>
#include "library.h"
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define N 1003
using namespace std;
int val[N],n;
vector<int>adj[N],res;
void add(int x,int y){
//printf("%d %d\n",x,y);
adj[x].pb(y);
adj[y].pb(x);
}
void dfs(int nd,int pr){
res.pb(nd);
tr(it,adj[nd])
if(*it!=pr)
dfs(*it,nd);
}
int ask(int x,int i,int effect){
vector<int>M;
int cur=0;
for(int j=0;j<n;j++){
if(j>=x and j<=i)
cur+=val[j],M.pb(1);
else
M.pb(0);
}
//printf("ask %d %d %d %d %d\n",x,i,effect,(Query(M)+cur<=i-x-effect),cur);
return (Query(M)+cur<=i-x-effect);
}
void Solve(int nn){n=nn;
if(n==1){
res.pb(1);
Answer(res);
return;
}
for(int i=1;i<n;i++){
int st=0,en=i-1,a=-1,b=-1;
while(st<en){
int mid=(st+en+1)>>1;
if(ask(mid,i,0))
st=mid;
else
en=mid-1;
}
if(ask(st,i,0)){
add(st+1,i+1);a=st;
en=st-1;st=0;
if(st<=en){
//printf("%d %d %d\n",st,en,i);
while(st<en){
int mid=(st+en+1)>>1;
if(ask(mid,i,1))
st=mid;
else
en=mid-1;
}
if(ask(st,i,1))
add(st+1,i+1),b=st;
}
}
if(~a)val[a]++;
if(~b)val[b]++;
}
for(int i=1;i<=n;i++)
if(adj[i].size()==1){
dfs(i,-1);
break;
}
Answer(res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
364 KB |
# of queries: 2135 |
2 |
Correct |
35 ms |
492 KB |
# of queries: 2165 |
3 |
Correct |
34 ms |
492 KB |
# of queries: 2265 |
4 |
Correct |
33 ms |
364 KB |
# of queries: 2298 |
5 |
Correct |
26 ms |
408 KB |
# of queries: 2276 |
6 |
Correct |
42 ms |
364 KB |
# of queries: 2269 |
7 |
Correct |
37 ms |
364 KB |
# of queries: 2289 |
8 |
Correct |
34 ms |
384 KB |
# of queries: 2184 |
9 |
Correct |
33 ms |
364 KB |
# of queries: 2240 |
10 |
Correct |
18 ms |
364 KB |
# of queries: 1307 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 8 |
15 |
Correct |
1 ms |
364 KB |
# of queries: 80 |
16 |
Correct |
4 ms |
364 KB |
# of queries: 171 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
364 KB |
# of queries: 2135 |
2 |
Correct |
35 ms |
492 KB |
# of queries: 2165 |
3 |
Correct |
34 ms |
492 KB |
# of queries: 2265 |
4 |
Correct |
33 ms |
364 KB |
# of queries: 2298 |
5 |
Correct |
26 ms |
408 KB |
# of queries: 2276 |
6 |
Correct |
42 ms |
364 KB |
# of queries: 2269 |
7 |
Correct |
37 ms |
364 KB |
# of queries: 2289 |
8 |
Correct |
34 ms |
384 KB |
# of queries: 2184 |
9 |
Correct |
33 ms |
364 KB |
# of queries: 2240 |
10 |
Correct |
18 ms |
364 KB |
# of queries: 1307 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 8 |
15 |
Correct |
1 ms |
364 KB |
# of queries: 80 |
16 |
Correct |
4 ms |
364 KB |
# of queries: 171 |
17 |
Correct |
356 ms |
620 KB |
# of queries: 15330 |
18 |
Correct |
342 ms |
676 KB |
# of queries: 15069 |
19 |
Correct |
332 ms |
364 KB |
# of queries: 15199 |
20 |
Correct |
303 ms |
540 KB |
# of queries: 14151 |
21 |
Correct |
321 ms |
624 KB |
# of queries: 13376 |
22 |
Correct |
335 ms |
748 KB |
# of queries: 15171 |
23 |
Correct |
341 ms |
748 KB |
# of queries: 15236 |
24 |
Correct |
122 ms |
364 KB |
# of queries: 7031 |
25 |
Correct |
338 ms |
620 KB |
# of queries: 14944 |
26 |
Correct |
294 ms |
492 KB |
# of queries: 13891 |
27 |
Correct |
120 ms |
492 KB |
# of queries: 6903 |
28 |
Correct |
404 ms |
492 KB |
# of queries: 18933 |
29 |
Correct |
442 ms |
620 KB |
# of queries: 18912 |
30 |
Correct |
419 ms |
620 KB |
# of queries: 18933 |