Submission #94029

#TimeUsernameProblemLanguageResultExecution timeMemory
94029zeyad49Teams (CEOI11_tea)Java
50 / 100
2630 ms117556 KiB
import java.io.*; import java.util.*; class tea{ static int INF=(int)1e9; public static void main(String[] args) throws IOException { Scanner sc=new Scanner(); PrintWriter out=new PrintWriter(System.out); int n=sc.nextInt(); Integer[]indices=new Integer[n]; int []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 []dp=new int [n+1]; //number of teams int []nxt=new int [n+1]; int []maxTeam=new int [n+1]; maxTeam[n]=-INF; for(int i=n-1;i>=0;i--) { int idx=indices[i]; if(i+a[idx]>n) dp[i]=-INF; else { int best=i+a[idx]; int currMax=Math.max(a[idx],maxTeam[i+a[idx]]); for(int j=i+a[idx];j<=n;j++) { int newMax=Math.max(j-i,maxTeam[j]); if(dp[j]>dp[best]||(dp[j]==dp[best] && newMax<currMax)) { best=j; currMax=newMax; } } nxt[i]=best; dp[i]=1+dp[best]; maxTeam[i]=currMax; } } 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...