Submission #94027

# Submission time Handle Problem Language Result Execution time Memory
94027 2019-01-14T20:51:55 Z zeyad49 Teams (CEOI11_tea) Java 11
0 / 100
2500 ms 123580 KB
import java.io.*;
import java.util.*;

class tea{

	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];
		int []nxt=new int [n+1];
		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];
				for(int j=i+a[idx];j<=n;j++)
					if(dp[j]>dp[best])
						best=j;
				nxt[i]=best;
				dp[i]=1+dp[best];
			}
		}
		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 197 ms 16136 KB Output is correct
2 Correct 184 ms 15704 KB Output is correct
3 Incorrect 185 ms 15644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 189 ms 15488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 15708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 294 ms 17984 KB Output is correct
2 Incorrect 283 ms 17984 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2549 ms 30572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2553 ms 32468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2579 ms 78812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2574 ms 123580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2689 ms 122908 KB Time limit exceeded
2 Halted 0 ms 0 KB -