Submission #727499

# Submission time Handle Problem Language Result Execution time Memory
727499 2023-04-20T21:21:28 Z jnjwnwnw Carnival (CEOI14_carnival) Java 11
20 / 100
896 ms 14432 KB
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 time Memory Grader output
1 Correct 205 ms 11656 KB Output is correct
2 Correct 310 ms 12532 KB Output is correct
3 Partially correct 666 ms 13912 KB Partially correct
4 Partially correct 734 ms 14144 KB Partially correct
5 Correct 142 ms 10756 KB Output is correct
6 Correct 142 ms 10604 KB Output is correct
7 Correct 283 ms 12136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 10848 KB Output is correct
2 Correct 314 ms 12348 KB Output is correct
3 Partially correct 467 ms 12376 KB Partially correct
4 Partially correct 743 ms 14104 KB Partially correct
5 Correct 169 ms 10684 KB Output is correct
6 Correct 162 ms 10832 KB Output is correct
7 Correct 217 ms 10676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 10496 KB Output is correct
2 Correct 208 ms 10880 KB Output is correct
3 Partially correct 477 ms 12460 KB Partially correct
4 Partially correct 890 ms 14356 KB Partially correct
5 Correct 194 ms 10712 KB Output is correct
6 Correct 221 ms 11076 KB Output is correct
7 Correct 359 ms 12556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 10600 KB Output is correct
2 Correct 178 ms 10872 KB Output is correct
3 Partially correct 720 ms 14432 KB Partially correct
4 Partially correct 896 ms 14240 KB Partially correct
5 Correct 237 ms 11460 KB Output is correct
6 Correct 397 ms 12376 KB Output is correct
7 Correct 320 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 10860 KB Output is correct
2 Correct 266 ms 11188 KB Output is correct
3 Partially correct 678 ms 13828 KB Partially correct
4 Partially correct 694 ms 13864 KB Partially correct
5 Correct 431 ms 12452 KB Output is correct
6 Partially correct 667 ms 13904 KB Partially correct
7 Partially correct 893 ms 14308 KB Partially correct