Submission #270619

# Submission time Handle Problem Language Result Execution time Memory
270619 2020-08-17T20:07:27 Z R3KT Carnival (CEOI14_carnival) Java 11
0 / 100
110 ms 10544 KB
import java.util.*;
import java.io.*;

public class carnival {

	// https://oj.uz/problem/view/CEOI14_carnival
	
	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(in.readLine());

		ArrayList<Integer> parents = new ArrayList<>();
		int[] par = new int[n+1];
		parents.add(1);
		par[1] = 1;
		int counter=2;
		for (int i=2; i<=n; i++) {
			StringBuilder sb = new StringBuilder();
			sb.append(parents.size()+1 + " ");
			for (int j=0; j<parents.size(); j++) {
				sb.append(parents.get(j) + " ");
			}
			sb.append(i + " ");
			System.out.println(sb);
			System.out.flush();
			int curvalue = Integer.parseInt(in.readLine());
			if (curvalue == parents.size()+1) {
				parents.add(i);
				par[i] = counter;
				counter++;
			}
			else {
				// binary search where it needs to go
				int min=0;
				int max = parents.size()-1;
				while (min < max) {
					int middle = (min + max)/2;
					sb = new StringBuilder();
					sb.append(middle - min + 1 + " ");
					// search first half
					for (int j=min; j<=middle; j++) {
						sb.append(parents.get(j) +  " ");
					}
					sb.append(i + " ");
					System.out.println(sb);
					System.out.flush();
					int curvalue2 = Integer.parseInt(in.readLine());
					if (curvalue2 == middle-min+1) {
						// inside lower half
						max = middle;
					}
					else min = middle+1;
				}
				par[i] = par[parents.get(min)];
			}
		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(0 + " ");
		for (int i=1; i<=n; i++) {
			sb.append(par[i] + " ");
		}
		System.out.println(sb);
		System.exit(0);
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 79 ms 10348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 81 ms 10436 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 10444 KB Output is correct
2 Runtime error 84 ms 10036 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 10544 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 83 ms 10144 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -