Submission #727549

# Submission time Handle Problem Language Result Execution time Memory
727549 2023-04-21T00:41:50 Z jnjwnwnw Carnival (CEOI14_carnival) Java 11
100 / 100
443 ms 13988 KB
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

Note: carnival.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# Verdict Execution time Memory Grader output
1 Correct 284 ms 13988 KB Output is correct
2 Correct 342 ms 13484 KB Output is correct
3 Correct 333 ms 13348 KB Output is correct
4 Correct 245 ms 13444 KB Output is correct
5 Correct 248 ms 13316 KB Output is correct
6 Correct 252 ms 13364 KB Output is correct
7 Correct 313 ms 13172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 13344 KB Output is correct
2 Correct 350 ms 13324 KB Output is correct
3 Correct 311 ms 13344 KB Output is correct
4 Correct 275 ms 13252 KB Output is correct
5 Correct 257 ms 13572 KB Output is correct
6 Correct 263 ms 13188 KB Output is correct
7 Correct 273 ms 13380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 13276 KB Output is correct
2 Correct 276 ms 13292 KB Output is correct
3 Correct 443 ms 13620 KB Output is correct
4 Correct 251 ms 13412 KB Output is correct
5 Correct 247 ms 13332 KB Output is correct
6 Correct 253 ms 13264 KB Output is correct
7 Correct 357 ms 13528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 13332 KB Output is correct
2 Correct 262 ms 13204 KB Output is correct
3 Correct 313 ms 13172 KB Output is correct
4 Correct 253 ms 13440 KB Output is correct
5 Correct 240 ms 13108 KB Output is correct
6 Correct 259 ms 13264 KB Output is correct
7 Correct 352 ms 13224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 13352 KB Output is correct
2 Correct 323 ms 13280 KB Output is correct
3 Correct 389 ms 13476 KB Output is correct
4 Correct 389 ms 13288 KB Output is correct
5 Correct 263 ms 13176 KB Output is correct
6 Correct 232 ms 13260 KB Output is correct
7 Correct 259 ms 13304 KB Output is correct