# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
394190 |
2021-04-26T04:56:46 Z |
BJoozz |
Fun Tour (APIO20_fun) |
C++14 |
|
306 ms |
20180 KB |
#include<bits/stdc++.h>
using namespace std;
#include "fun.h"
#define X first
#define Y second
#define pb push_back
#define getdis hoursRequired
#define getsz attractionsBehind
const int MAX=100005,mod=1e9+7,M=2000,inf=1e9;
void maxx(int &a,int b){if(b>a) a=b;}
using ii = pair < int ,int > ;
void minn(int &a,int b){if(b<a) a=b;}
void maxp(ii &a,ii b){if(b>a) a=b;}
void minp(ii &a,ii b){if(b<a) a=b;}
bool cp(ii &a,ii b){if(b>a) {a=b;return 1;}else return 0;}
void PL(int &a,int b){a+=b;if(a>=mod) a-=mod;}
///+++++++++++++++++++++++++++++
int a[MAX],sz[4],h[MAX];
bool vs[MAX];
int D[4];
short bel[MAX];
int L[4][MAX];
int getdeep(int v){
ii u = ii (0,0);
int r;
for(int i=1;i<=3;i++) if(i!=v && sz[i]!=0)
if( cp(u,ii(h[L[i][sz[i]]],sz[i])) ) r=i;
return r;
}
bool cmp(int u,int v){
return h[u]<h[v];}
std::vector<int> createFunTour(int n,int Q){
vector < int > vec;
a[0]=n;
if(n==2){
vec.pb(0);vec.pb(1);return vec;
}
int r=0;
for(int i=1;i<n;i++){
a[i]=getsz(0,i);
if(a[i]>n/2 && a[i]<a[r]) {
r=i;
}
}
int cn=0;
for(int i=0;i<n;i++)if(r!=i){
h[i]=getdis(r,i);
if(h[i]==1) D[++cn]=i;
}
vs[r]=1;
for(int i=1,u;i<=cn;i++){
u=D[i];
bel[u]=i;
L[i][1]=u;
vs[u]=1;
sz[i]=getsz(r,u);
///co the toi uu
}
int top[4]={1,1,1,1};
for(int i=0;i<n;i++) if(!vs[i]){
if(getdis(D[1],i)==h[i]-1){
bel[i]=1;
}
else{
if(getdis(D[2],i)==h[i]-1)
bel[i]=2;
else bel[i]=3;
}
L[bel[i]][++top[bel[i]]]=i;
//cout<<i<<' '<<bel[i]<<'\n';
}
for(int i=1;i<=cn;i++){
sort(L[i]+1,L[i]+1+sz[i],cmp);
}
int las=0;
int allsz=n;
bool okk=1;
for(int i=1;i<n && okk;i++){
int z=getdeep(las);
int v=L[z][sz[z]];
vec.pb(v);
sz[z]--;
allsz--;
las=z;
for(int i=1;i<=cn;i++)
if(sz[i]>=allsz/2){
okk=0;break;
}
}
if(!okk && allsz>1){
int sp;
for(int i=1;i<=cn;i++)
if(sz[i]>=allsz/2){
sp=i;break;
}
int z=getdeep(0);
if(z!=las && z!=sp){
int v=L[z][sz[z]];
vec.pb(v);
sz[z]--;
allsz--;
las=z;
}
bool turn=(las!=sp);
//for ( int u:vec) cout<<u<<' ';cout<<'\n';
//cout<<las<<' '<<sp<<'\n';
//cout<<allsz;return vec;
//cout<<sz[sp]<<' '<<allsz<<'\n';
while(allsz>1){
if(turn){
int z=sp;
int v=L[z][sz[z]];
vec.pb(v);
sz[z]--;
allsz--;
las=z;
}
else{
int z=getdeep(sp);
int v=L[z][sz[z]];
vec.pb(v);
sz[z]--;
allsz--;
las=z;
}
turn^=1;
}
}
vec.pb(r);
//cout<<allsz<<'\n';
return vec;
}
Compilation message
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:96:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
96 | for(int i=1;i<=cn;i++)
| ^~~
fun.cpp:100:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
100 | int z=getdeep(0);
| ^~~
fun.cpp: In function 'int getdeep(int)':
fun.cpp:30:12: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
30 | return r;
| ^
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:126:22: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
126 | sz[z]--;
| ~~~~~^~
fun.cpp:104:22: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
104 | sz[z]--;
| ~~~~~^~
fun.cpp:28:27: warning: 'sp' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | for(int i=1;i<=3;i++) if(i!=v && sz[i]!=0)
| ^~
fun.cpp:95:13: note: 'sp' was declared here
95 | int sp;
| ^~
fun.cpp:28:27: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | for(int i=1;i<=3;i++) if(i!=v && sz[i]!=0)
| ^~
fun.cpp:27:9: note: 'r' was declared here
27 | int r;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
134 ms |
15424 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
4 ms |
716 KB |
Output is correct |
22 |
Correct |
7 ms |
1228 KB |
Output is correct |
23 |
Correct |
15 ms |
2256 KB |
Output is correct |
24 |
Correct |
18 ms |
2964 KB |
Output is correct |
25 |
Correct |
75 ms |
9028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
10 ms |
1740 KB |
Output is correct |
15 |
Correct |
144 ms |
15512 KB |
Output is correct |
16 |
Correct |
160 ms |
15460 KB |
Output is correct |
17 |
Correct |
28 ms |
3816 KB |
Output is correct |
18 |
Correct |
74 ms |
7152 KB |
Output is correct |
19 |
Correct |
109 ms |
12160 KB |
Output is correct |
20 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
134 ms |
15424 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
2 ms |
588 KB |
Output is correct |
47 |
Correct |
4 ms |
716 KB |
Output is correct |
48 |
Correct |
7 ms |
1228 KB |
Output is correct |
49 |
Correct |
15 ms |
2256 KB |
Output is correct |
50 |
Correct |
18 ms |
2964 KB |
Output is correct |
51 |
Correct |
75 ms |
9028 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
10 ms |
1740 KB |
Output is correct |
54 |
Correct |
144 ms |
15512 KB |
Output is correct |
55 |
Correct |
160 ms |
15460 KB |
Output is correct |
56 |
Correct |
28 ms |
3816 KB |
Output is correct |
57 |
Correct |
74 ms |
7152 KB |
Output is correct |
58 |
Correct |
109 ms |
12160 KB |
Output is correct |
59 |
Correct |
5 ms |
844 KB |
Output is correct |
60 |
Correct |
203 ms |
15392 KB |
Output is correct |
61 |
Correct |
216 ms |
17920 KB |
Output is correct |
62 |
Correct |
178 ms |
15524 KB |
Output is correct |
63 |
Correct |
218 ms |
19388 KB |
Output is correct |
64 |
Correct |
199 ms |
19436 KB |
Output is correct |
65 |
Correct |
208 ms |
15444 KB |
Output is correct |
66 |
Correct |
255 ms |
17724 KB |
Output is correct |
67 |
Correct |
206 ms |
19516 KB |
Output is correct |
68 |
Correct |
233 ms |
18532 KB |
Output is correct |
69 |
Correct |
306 ms |
20180 KB |
Output is correct |
70 |
Correct |
185 ms |
15408 KB |
Output is correct |
71 |
Correct |
209 ms |
19388 KB |
Output is correct |
72 |
Correct |
262 ms |
18032 KB |
Output is correct |
73 |
Correct |
230 ms |
18836 KB |
Output is correct |
74 |
Correct |
277 ms |
20140 KB |
Output is correct |
75 |
Correct |
209 ms |
15424 KB |
Output is correct |
76 |
Correct |
218 ms |
19480 KB |
Output is correct |
77 |
Correct |
231 ms |
19356 KB |
Output is correct |
78 |
Incorrect |
181 ms |
18692 KB |
Repeated index |
79 |
Halted |
0 ms |
0 KB |
- |