Submission #333810

#TimeUsernameProblemLanguageResultExecution timeMemory
333810KWang31Fun Tour (APIO20_fun)Java
0 / 100
92 ms9324 KiB
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){ 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; int[] dep=new int[N]; int[] sub=new int[N]; ArrayList<Pair> arl[]=new ArrayList[sz]; for(int i=0;i<sz;i++){arl[i]=new ArrayList<>(); 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){ sub[i]=ch[0];dep[i]=x+1; arl[0].add(new Pair(i,x+1)); }else if(y<x){ sub[i]=ch[1]; dep[i]=y+1;arl[1].add(new Pair(i,y+1)); }else{ sub[i]=ch[2]; dep[i]=x-1;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){ sub[i]=ch[0];dep[i]=x+1; arl[0].add(new Pair(i,x+1)); }else{ sub[i]=ch[1]; dep[i]=y+1;arl[1].add(new Pair(i,y+1)); } } } int[] a=new int[N]; for(int i=0;i<sz;i++){Collections.sort(arl[i]);} int[] p=new int[sz]; int done=0; int z=0; while(done<N-1){ if(p[0]<arl[0].size()){x=arl[0].get(p[0]).val; }else{x=-1;} if(p[1]<arl[1].size()){y=arl[1].get(p[1]).val;} else{y=-1;} if(sz==3 && p[2]<arl[2].size()){z=arl[2].get(p[2]).val;} else{z=-1;} if(x>=y&&x>=z){ a[done]=arl[0].get(p[0]).vtx+1; p[0]++; }else if(y>=x && y>=z){ a[done]=arl[1].get(p[1]).vtx+1; p[1]++; }else{ a[done]=arl[2].get(p[2]).vtx+1; p[2]++; } done++; } a[N-1]=c; return a; } }

Compilation message (stderr)

Note: fun.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...