Submission #726591

# Submission time Handle Problem Language Result Execution time Memory
726591 2023-04-19T06:10:47 Z jnjwnwnw Carnival (CEOI14_carnival) Java 11
20 / 100
949 ms 14588 KB
import java.util.*;
import java.io.*;
public class carnival{
    // this class isnt neeeeded, can be done difficultly using an ArrayList<Integer>[]
    private class Node{
        // 2 nodes are adjacent if asking the computer about them yeilds a 1
        private HashSet<Node> adjacent;
        private int id;
        public Node(int iid){ 
            id = iid; 
            adjacent = new HashSet<>();
            adjacent.add(this);
        }
    }

    public static void main(String[] args) throws IOException {
        new carnival();
    }

    public carnival()throws IOException{
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(new StringTokenizer(br.readLine()).nextToken());
        Node[] nodes = new Node[n];
        for(int i = 0; i < n; i++){
            nodes[i] = new Node(i);
        }
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if (nodes[i].adjacent.contains(nodes[j])){continue;}
                System.out.println("2 " + (i+1) + " " + (j+1));
                if (Integer.parseInt(new StringTokenizer(br.readLine()).nextToken()) == 1){
                    // are connected
                    nodes[i].adjacent.addAll(nodes[j].adjacent);
                    nodes[j].adjacent = nodes[i].adjacent;
                }
            }
        }

        HashSet<HashSet<Node>> allSets = new HashSet<>();
        for(int i = 0; i < n; i++){
            allSets.add(nodes[i].adjacent);
        }

        int[] result = new int[n];
        int r = 0;
        for(HashSet<Node> s: allSets){
            r++;
            for (Node node: s){
                result[node.id] = r;
            }
        }

        System.out.print("0 ");
        for(int i = 0; i < n-1; i++){
            System.out.print(result[i] + " ");
        } System.out.println(result[n-1]);
    }
}
# Verdict Execution time Memory Grader output
1 Partially correct 792 ms 13904 KB Partially correct
2 Partially correct 739 ms 13936 KB Partially correct
3 Partially correct 812 ms 13744 KB Partially correct
4 Partially correct 813 ms 13848 KB Partially correct
5 Partially correct 500 ms 12556 KB Partially correct
6 Correct 170 ms 10768 KB Output is correct
7 Partially correct 754 ms 13824 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 783 ms 13712 KB Partially correct
2 Partially correct 949 ms 14248 KB Partially correct
3 Partially correct 726 ms 13868 KB Partially correct
4 Partially correct 726 ms 13944 KB Partially correct
5 Partially correct 734 ms 13812 KB Partially correct
6 Correct 331 ms 11468 KB Output is correct
7 Partially correct 759 ms 13680 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 10416 KB Output is correct
2 Partially correct 787 ms 13800 KB Partially correct
3 Partially correct 904 ms 14588 KB Partially correct
4 Partially correct 898 ms 14084 KB Partially correct
5 Partially correct 729 ms 13872 KB Partially correct
6 Partially correct 679 ms 13528 KB Partially correct
7 Partially correct 915 ms 14472 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 828 ms 13784 KB Partially correct
2 Partially correct 780 ms 13792 KB Partially correct
3 Partially correct 915 ms 14348 KB Partially correct
4 Partially correct 867 ms 14220 KB Partially correct
5 Partially correct 739 ms 13844 KB Partially correct
6 Partially correct 762 ms 13792 KB Partially correct
7 Partially correct 888 ms 14200 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 727 ms 13796 KB Partially correct
2 Partially correct 907 ms 14284 KB Partially correct
3 Partially correct 891 ms 14364 KB Partially correct
4 Partially correct 896 ms 14192 KB Partially correct
5 Partially correct 814 ms 14276 KB Partially correct
6 Partially correct 878 ms 14432 KB Partially correct
7 Partially correct 880 ms 14580 KB Partially correct