Submission #94030

# Submission time Handle Problem Language Result Execution time Memory
94030 2019-01-14T21:06:12 Z zeyad49 Teams (CEOI11_tea) Java 11
50 / 100
2500 ms 114904 KB
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]=-1;
				
			
			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

Note: tea.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# Verdict Execution time Memory Grader output
1 Correct 195 ms 15684 KB Output is correct
2 Correct 191 ms 15452 KB Output is correct
3 Correct 186 ms 15064 KB Output is correct
4 Correct 192 ms 15724 KB Output is correct
5 Correct 186 ms 15436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 15528 KB Output is correct
2 Correct 178 ms 15172 KB Output is correct
3 Correct 178 ms 15728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 15868 KB Output is correct
2 Correct 182 ms 15748 KB Output is correct
3 Correct 178 ms 15344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 18080 KB Output is correct
2 Correct 346 ms 17928 KB Output is correct
3 Correct 311 ms 18128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 17988 KB Output is correct
2 Correct 332 ms 17876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2513 ms 30488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2580 ms 31912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2552 ms 73236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2543 ms 114904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2573 ms 113588 KB Time limit exceeded
2 Halted 0 ms 0 KB -