Submission #94082

#TimeUsernameProblemLanguageResultExecution timeMemory
94082zeyad49Teams (CEOI11_tea)Java
0 / 100
2896 ms191048 KiB
import java.io.*; import java.util.*; class tea{ static int INF=(int)1e9; static Integer[]indices; static int n,a[]; static int[][] check(int limit) { int []dp=new int [n+1]; //number of teams int []nxt=new int [n+1]; TreeSet<Integer> cand=new TreeSet(); Deque<Integer> queue=new LinkedList(); cand.add(n); queue.add(n); for(int i=n-1;i>=0;i--) { int x=a[indices[i]]; if(i+x>n) continue; while(!queue.isEmpty()) { int j=queue.peekFirst(); if(j-i>limit) { queue.removeFirst(); cand.remove(j); } else break; } Integer first=cand.ceiling(i+x); if(first==null) break; dp[i]=dp[first]+1; nxt[i]=first; if(dp[i]>=dp[queue.peekLast()]) { queue.addLast(i); cand.add(i); } // System.out.println(queue); } int [][]ans=new int [2][n]; ans[0]=dp; ans[1]=nxt; return ans; } public static void main(String[] args) throws IOException { Scanner sc=new Scanner(); PrintWriter out=new PrintWriter(System.out); n=sc.nextInt(); indices=new Integer[n]; a=new int [n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); indices[i]=i; } Arrays.sort(indices,Comparator.comparingInt(i->-a[i])); int [][]x; x=check(n); int maxTeams=x[0][0]; int best=-1; int lo=1,hi=n; while(lo<=hi) { int mid=lo+hi>>1; x=check(mid); if(x[0][0]==maxTeams) { hi=mid-1; best=mid; } else lo=mid+1; } x=check(best); int []dp=x[0]; int []nxt=x[1]; out.println(dp[0]); Queue<Integer> list=new LinkedList(); for(int i=0;i<n;) { // int j=nxt[i]; while(i<j) { list.add(indices[i]+1); i++; } out.print(list.size()); while(!list.isEmpty()) out.print(" "+list.poll()); out.println(); } out.close(); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } Scanner(String fileName) throws FileNotFoundException{ br=new BufferedReader(new FileReader(fileName)); } String next() throws IOException { while(st==null || !st.hasMoreTokens()) st=new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException{ return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } } }

Compilation message (stderr)

Note: tea.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...
#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...