Submission #727499

#TimeUsernameProblemLanguageResultExecution timeMemory
727499jnjwnwnwCarnival (CEOI14_carnival)Java
20 / 100
896 ms14432 KiB
import java.util.*; import java.io.*; public class carnival { private static ArrayList<Integer> components; private static HashMap<Integer, ArrayList<Integer>> sets; public static void main(String[] args) throws IOException { new carnival(); } public carnival() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); sets = new HashMap<>(); components = new ArrayList<>(); components.add(1); sets.put(1, new ArrayList<>()); sets.get(1).add(1); for(int i = 2; i <= n; i++){ boolean added = false; for(Integer val: components){ System.out.println("2 " + i + " " + val); st = new StringTokenizer(br.readLine()); if ((Integer.parseInt(st.nextToken()) == 1)){ sets.get(val).add(i); added=true; break; } } if (!added){ sets.put(i, new ArrayList<>()); sets.get(i).add(i); components.add(i); } } int[] result = new int[n+1]; int m = 1; for(Integer i: components){ for(Integer j: sets.get(i)){ result[j] = m; } m++; } for(int i: result){ System.out.print(i + " "); } System.out.println(); } } /** * Modified fork of KATTIO */ class ASTDIO extends PrintWriter{ private BufferedReader br; private StringTokenizer st = new StringTokenizer(""); private String line; public ASTDIO(){ super(new BufferedOutputStream(System.out)); br = new BufferedReader(new InputStreamReader(System.in)); } public ASTDIO(String problemName)throws IOException{ super(new File(problemName + ".out")); br = new BufferedReader(new FileReader(problemName + ".in")); } // use these 2 if blank lines can occur in the input, and replace all uses of next() with nextToken() // private String token; // private String peekToken() { // if (token == null) // try { // while (st == null || !st.hasMoreTokens()) { // line = br.readLine(); // if (line == null) return null; // st = new StringTokenizer(line); // } // token = st.nextToken(); // } catch (IOException e) { } // return token; // } // private String nextToken() { // String ans = peekToken(); // token = null; // return ans; // } /** * PRECONDITION: all input lines are consecutive, so the nextLine should always have some data */ public String next() { if (!st.hasMoreTokens()){ try { line = br.readLine(); } catch (IOException e) {;} if(line==null){return null;} } st = new StringTokenizer(line); return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){return Long.parseLong(next());} public void close(){ super.close(); try{ br.close(); } catch(Exception e){ ; } } }
#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...