Submission #727549

#TimeUsernameProblemLanguageResultExecution timeMemory
727549jnjwnwnwCarnival (CEOI14_carnival)Java
100 / 100
443 ms13988 KiB
import java.util.*; import java.io.*; public class carnival { public static void main(String[] args) throws IOException{ new carnival(); } public carnival() throws IOException{ AIO s = new AIO(); int n = s.nextInt(); int numThatFormOwnSet = 1; String asking = " 1 "; boolean[] formOwnSet = new boolean[n]; formOwnSet[0] = true; int prev = 1; for(int i = 2; i <= n; i++){ s.println(i + asking + i); int cur = s.nextInt(); formOwnSet[i-1] = (cur != prev); numThatFormOwnSet += (cur!=prev) ? 1 : 0; prev = cur; asking = asking + i + " "; } ArrayList<Integer>[] sets = new ArrayList[numThatFormOwnSet]; int curSet = 0; for(int i = 0; i < n; i++){ if (formOwnSet[i]){ sets[curSet] = new ArrayList<Integer>(); sets[curSet].add(i+1); curSet++; } } curSet = 0; for(int i = 0; i <n; i++){ if (formOwnSet[i]){ curSet++; } else{ for(int j = 0; j <= curSet; j++){ int setID = sets[j].get(0); s.println("2 " + (i+1) + " " + setID); if (s.nextInt() == 1){ sets[j].add(i+1); break; } } } } int[] result = new int[n+1]; for(int i = 0; i < numThatFormOwnSet; i++){ for(int j: sets[i]){ result[j] = i+1; } } for(int i: result){ s.print(i + " "); } s.println(); } } /** * fastish io specific to this problem, this is more for ease of typing and readability later on */ class AIO { private StringTokenizer st; private BufferedReader br; public AIO(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } public int nextInt() throws IOException{ if (!st.hasMoreTokens()){ st = new StringTokenizer(br.readLine()); } return Integer.parseInt(st.nextToken()); } public void println(int a){ System.out.println(a); } public void print(int a){ System.out.print(a); } public void println(String s){ System.out.println(s); } public void print(String s){ System.out.print(s); } public void println(){ System.out.println(); } }

Compilation message (stderr)

Note: carnival.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...