# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
336108 |
2020-12-14T18:13:32 Z |
KWang31 |
Fun Tour (APIO20_fun) |
Java 11 |
|
892 ms |
41536 KB |
import java.util.*;
public class fun {
public static class Pair implements Comparable<Pair>{
int vtx; int val;
public Pair(int a, int b){
this.vtx=a; this.val=b;
}
public int compareTo(Pair other){
if(this.val>other.val)return -1;
if(this.val<other.val)return 1;
if(this.vtx<other.vtx)return -1;
return 1;
}
}
public static int[] createFunTour(int N, int Q){
if(N==2){
int[] a=new int[2]; a[1]=1; return a;
}
int min=N; int ind=0; int sz=0;
for (int i = 1; i < N; i++) {
sz=grader.attractionsBehind(0,i);
if(2*sz>N && sz<min){
min=sz; ind=i;
}
}
int c=0;
if(min!=N){
c=ind;//Centroid
}
int[] ch=new int[3]; Arrays.fill(ch,-1);
sz=0;
for (int i = 0; i < N; i++) {
if(i==c)continue;
if(grader.hoursRequired(c,i)==1){
ch[sz]=i; sz++;
}
}
int x,y;
ArrayList<Pair> arl[]=new ArrayList[3];
for(int i=0;i<3;i++){arl[i]=new ArrayList<>(); if(i<sz){arl[i].add(new Pair(ch[i],1));}}
if(sz==3){
for (int i = 0; i < N; i++) {
if(i==c || i==ch[0] || i==ch[1] || i==ch[2])continue;
x=grader.hoursRequired(ch[0],i);
y=grader.hoursRequired(ch[1],i);
if(x<y){
arl[0].add(new Pair(i,x+1));
}else if(y<x){
arl[1].add(new Pair(i,y+1));
}else{
arl[2].add(new Pair(i,x-1));
}
}
}else{
for (int i = 0; i < N; i++) {
if(i==c || i==ch[0] || i==ch[1])continue;
x=grader.hoursRequired(ch[0],i);
y=grader.hoursRequired(ch[1],i);
if(x<y){
arl[0].add(new Pair(i,x+1));
}else{
arl[1].add(new Pair(i,y+1));
}
}
}
int[] a=new int[N];
if(arl[0].size()==N/2){
arl[1].add(new Pair(c,-1));
}else{
arl[0].add(new Pair(c,-1));
}
for(int i=0;i<3;i++){Collections.sort(arl[i]);}//Sort in descending order
int[] p=new int[3];//Keeps current pointer
int z=0;
int cur=0;//We cannot use vertices from the same subtree twice in a row
x=arl[0].get(p[0]).val; y=0;
for(int i=1; i<3; i++){
if(!arl[i].isEmpty() && arl[i].get(0).val >= x){
x=arl[i].get(0).val; cur=i;
}
}
//System.out.println(arl[0].size()+" "+cur);
a[0]=arl[cur].get(p[cur]).vtx; p[cur]++;
//System.out.println(a[0]+".."+cur);
//System.out.println(Arrays.toString(p));
for(int done=1; done<N; done++){
if(p[(cur+1)%3]<arl[(cur+1)%3].size()){x=arl[(cur+1)%3].get(p[(cur+1)%3]).val;} else{x=-5;}
if(p[(cur+2)%3]<arl[(cur+2)%3].size()){y=arl[(cur+2)%3].get(p[(cur+2)%3]).val;} else{y=-5;}
if(2*(arl[(cur+1)%3].size()-p[(cur+1)%3])>=N-done+1 && y<=a[done-1]){
cur=(cur+1)%3;
}else if(2*(arl[(cur+2)%3].size()-p[(cur+2)%3])>=N-done+1 && x<=a[done-1]){
cur=(cur+2)%3;
}else if(x>y){
cur=(cur+1)%3;
}else{
cur=(cur+2)%3;
}
//System.out.println(done+" "+cur+" "+p[cur]);
a[done]=arl[cur].get(p[cur]).vtx; p[cur]++;
}
return a;
}
}
Compilation message
Note: fun.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8556 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8556 KB |
Output is correct |
4 |
Correct |
73 ms |
8556 KB |
Output is correct |
5 |
Correct |
73 ms |
8528 KB |
Output is correct |
6 |
Correct |
75 ms |
8416 KB |
Output is correct |
7 |
Correct |
74 ms |
8556 KB |
Output is correct |
8 |
Correct |
74 ms |
8552 KB |
Output is correct |
9 |
Correct |
75 ms |
8540 KB |
Output is correct |
10 |
Correct |
72 ms |
8428 KB |
Output is correct |
11 |
Correct |
75 ms |
8540 KB |
Output is correct |
12 |
Correct |
74 ms |
8556 KB |
Output is correct |
13 |
Correct |
72 ms |
8556 KB |
Output is correct |
14 |
Correct |
74 ms |
8428 KB |
Output is correct |
15 |
Correct |
71 ms |
8428 KB |
Output is correct |
16 |
Correct |
75 ms |
8556 KB |
Output is correct |
17 |
Correct |
73 ms |
8556 KB |
Output is correct |
18 |
Correct |
71 ms |
8556 KB |
Output is correct |
19 |
Correct |
74 ms |
8556 KB |
Output is correct |
20 |
Correct |
72 ms |
8552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8556 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8556 KB |
Output is correct |
4 |
Correct |
73 ms |
8556 KB |
Output is correct |
5 |
Correct |
73 ms |
8528 KB |
Output is correct |
6 |
Correct |
75 ms |
8416 KB |
Output is correct |
7 |
Correct |
74 ms |
8556 KB |
Output is correct |
8 |
Correct |
74 ms |
8552 KB |
Output is correct |
9 |
Correct |
75 ms |
8540 KB |
Output is correct |
10 |
Correct |
72 ms |
8428 KB |
Output is correct |
11 |
Correct |
75 ms |
8540 KB |
Output is correct |
12 |
Correct |
74 ms |
8556 KB |
Output is correct |
13 |
Correct |
72 ms |
8556 KB |
Output is correct |
14 |
Correct |
74 ms |
8428 KB |
Output is correct |
15 |
Correct |
71 ms |
8428 KB |
Output is correct |
16 |
Correct |
75 ms |
8556 KB |
Output is correct |
17 |
Correct |
73 ms |
8556 KB |
Output is correct |
18 |
Correct |
71 ms |
8556 KB |
Output is correct |
19 |
Correct |
74 ms |
8556 KB |
Output is correct |
20 |
Correct |
72 ms |
8552 KB |
Output is correct |
21 |
Correct |
75 ms |
8448 KB |
Output is correct |
22 |
Correct |
73 ms |
8556 KB |
Output is correct |
23 |
Correct |
77 ms |
8556 KB |
Output is correct |
24 |
Correct |
96 ms |
9732 KB |
Output is correct |
25 |
Correct |
73 ms |
8552 KB |
Output is correct |
26 |
Correct |
75 ms |
8556 KB |
Output is correct |
27 |
Correct |
81 ms |
8684 KB |
Output is correct |
28 |
Correct |
73 ms |
8556 KB |
Output is correct |
29 |
Correct |
93 ms |
9604 KB |
Output is correct |
30 |
Correct |
74 ms |
8556 KB |
Output is correct |
31 |
Correct |
90 ms |
9460 KB |
Output is correct |
32 |
Correct |
89 ms |
9476 KB |
Output is correct |
33 |
Correct |
75 ms |
8680 KB |
Output is correct |
34 |
Correct |
93 ms |
9724 KB |
Output is correct |
35 |
Correct |
94 ms |
9732 KB |
Output is correct |
36 |
Correct |
95 ms |
9736 KB |
Output is correct |
37 |
Correct |
77 ms |
8556 KB |
Output is correct |
38 |
Correct |
93 ms |
9600 KB |
Output is correct |
39 |
Correct |
90 ms |
9560 KB |
Output is correct |
40 |
Correct |
95 ms |
9580 KB |
Output is correct |
41 |
Correct |
79 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8556 KB |
Output is correct |
2 |
Correct |
72 ms |
8556 KB |
Output is correct |
3 |
Correct |
73 ms |
8556 KB |
Output is correct |
4 |
Correct |
73 ms |
8528 KB |
Output is correct |
5 |
Correct |
75 ms |
8416 KB |
Output is correct |
6 |
Correct |
74 ms |
8556 KB |
Output is correct |
7 |
Correct |
74 ms |
8552 KB |
Output is correct |
8 |
Correct |
75 ms |
8540 KB |
Output is correct |
9 |
Correct |
75 ms |
8448 KB |
Output is correct |
10 |
Correct |
73 ms |
8556 KB |
Output is correct |
11 |
Correct |
77 ms |
8556 KB |
Output is correct |
12 |
Correct |
96 ms |
9732 KB |
Output is correct |
13 |
Correct |
73 ms |
8552 KB |
Output is correct |
14 |
Correct |
75 ms |
8556 KB |
Output is correct |
15 |
Correct |
81 ms |
8684 KB |
Output is correct |
16 |
Correct |
96 ms |
9496 KB |
Output is correct |
17 |
Correct |
99 ms |
9792 KB |
Output is correct |
18 |
Correct |
535 ms |
39988 KB |
Output is correct |
19 |
Correct |
124 ms |
10020 KB |
Output is correct |
20 |
Correct |
158 ms |
10420 KB |
Output is correct |
21 |
Correct |
168 ms |
10616 KB |
Output is correct |
22 |
Correct |
216 ms |
13320 KB |
Output is correct |
23 |
Correct |
375 ms |
17456 KB |
Output is correct |
24 |
Correct |
397 ms |
18424 KB |
Output is correct |
25 |
Correct |
481 ms |
29964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8556 KB |
Output is correct |
2 |
Correct |
72 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8428 KB |
Output is correct |
4 |
Correct |
75 ms |
8540 KB |
Output is correct |
5 |
Correct |
74 ms |
8556 KB |
Output is correct |
6 |
Correct |
72 ms |
8556 KB |
Output is correct |
7 |
Correct |
73 ms |
8556 KB |
Output is correct |
8 |
Correct |
93 ms |
9604 KB |
Output is correct |
9 |
Correct |
74 ms |
8556 KB |
Output is correct |
10 |
Correct |
90 ms |
9460 KB |
Output is correct |
11 |
Correct |
89 ms |
9476 KB |
Output is correct |
12 |
Correct |
75 ms |
8680 KB |
Output is correct |
13 |
Correct |
114 ms |
9860 KB |
Output is correct |
14 |
Correct |
274 ms |
13748 KB |
Output is correct |
15 |
Correct |
892 ms |
41536 KB |
Output is correct |
16 |
Runtime error |
807 ms |
41408 KB |
Execution failed because the return code was nonzero |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8556 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8556 KB |
Output is correct |
4 |
Correct |
73 ms |
8556 KB |
Output is correct |
5 |
Correct |
73 ms |
8528 KB |
Output is correct |
6 |
Correct |
75 ms |
8416 KB |
Output is correct |
7 |
Correct |
74 ms |
8556 KB |
Output is correct |
8 |
Correct |
74 ms |
8552 KB |
Output is correct |
9 |
Correct |
75 ms |
8540 KB |
Output is correct |
10 |
Correct |
72 ms |
8428 KB |
Output is correct |
11 |
Correct |
75 ms |
8540 KB |
Output is correct |
12 |
Correct |
74 ms |
8556 KB |
Output is correct |
13 |
Correct |
72 ms |
8556 KB |
Output is correct |
14 |
Correct |
74 ms |
8428 KB |
Output is correct |
15 |
Correct |
71 ms |
8428 KB |
Output is correct |
16 |
Correct |
75 ms |
8556 KB |
Output is correct |
17 |
Correct |
73 ms |
8556 KB |
Output is correct |
18 |
Correct |
71 ms |
8556 KB |
Output is correct |
19 |
Correct |
74 ms |
8556 KB |
Output is correct |
20 |
Correct |
72 ms |
8552 KB |
Output is correct |
21 |
Correct |
75 ms |
8448 KB |
Output is correct |
22 |
Correct |
73 ms |
8556 KB |
Output is correct |
23 |
Correct |
77 ms |
8556 KB |
Output is correct |
24 |
Correct |
96 ms |
9732 KB |
Output is correct |
25 |
Correct |
73 ms |
8552 KB |
Output is correct |
26 |
Correct |
75 ms |
8556 KB |
Output is correct |
27 |
Correct |
81 ms |
8684 KB |
Output is correct |
28 |
Correct |
73 ms |
8556 KB |
Output is correct |
29 |
Correct |
93 ms |
9604 KB |
Output is correct |
30 |
Correct |
74 ms |
8556 KB |
Output is correct |
31 |
Correct |
90 ms |
9460 KB |
Output is correct |
32 |
Correct |
89 ms |
9476 KB |
Output is correct |
33 |
Correct |
75 ms |
8680 KB |
Output is correct |
34 |
Correct |
93 ms |
9724 KB |
Output is correct |
35 |
Correct |
94 ms |
9732 KB |
Output is correct |
36 |
Correct |
95 ms |
9736 KB |
Output is correct |
37 |
Correct |
77 ms |
8556 KB |
Output is correct |
38 |
Correct |
93 ms |
9600 KB |
Output is correct |
39 |
Correct |
90 ms |
9560 KB |
Output is correct |
40 |
Correct |
95 ms |
9580 KB |
Output is correct |
41 |
Correct |
79 ms |
8556 KB |
Output is correct |
42 |
Correct |
96 ms |
9496 KB |
Output is correct |
43 |
Correct |
99 ms |
9792 KB |
Output is correct |
44 |
Correct |
535 ms |
39988 KB |
Output is correct |
45 |
Correct |
124 ms |
10020 KB |
Output is correct |
46 |
Correct |
158 ms |
10420 KB |
Output is correct |
47 |
Correct |
168 ms |
10616 KB |
Output is correct |
48 |
Correct |
216 ms |
13320 KB |
Output is correct |
49 |
Correct |
375 ms |
17456 KB |
Output is correct |
50 |
Correct |
397 ms |
18424 KB |
Output is correct |
51 |
Correct |
481 ms |
29964 KB |
Output is correct |
52 |
Correct |
114 ms |
9860 KB |
Output is correct |
53 |
Correct |
274 ms |
13748 KB |
Output is correct |
54 |
Correct |
892 ms |
41536 KB |
Output is correct |
55 |
Runtime error |
807 ms |
41408 KB |
Execution failed because the return code was nonzero |
56 |
Halted |
0 ms |
0 KB |
- |