답안 #94028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94028 2019-01-14T21:04:13 Z zeyad49 Teams (CEOI11_tea) Java 11
0 / 100
82 ms 9976 KB
import java.io.*;
import java.util.*;

class team{

	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

Note: tea.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# 결과 실행 시간 메모리 Grader output
1 Runtime error 77 ms 9976 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 78 ms 9708 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 78 ms 9676 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 76 ms 9576 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 76 ms 9704 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 77 ms 9844 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 78 ms 9836 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 9612 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 9880 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 9720 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -