結果

問題 No.130 XOR Minimax
ユーザー tentententen
提出日時 2022-08-19 16:03:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 592 ms / 5,000 ms
コード長 1,717 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 79,132 KB
実行使用メモリ 63,764 KB
最終ジャッジ日時 2024-04-16 20:21:28
合計ジャッジ時間 12,008 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 359 ms
52,744 KB
testcase_01 AC 53 ms
37,296 KB
testcase_02 AC 52 ms
36,696 KB
testcase_03 AC 52 ms
37,280 KB
testcase_04 AC 306 ms
49,472 KB
testcase_05 AC 576 ms
62,200 KB
testcase_06 AC 592 ms
61,248 KB
testcase_07 AC 570 ms
63,764 KB
testcase_08 AC 512 ms
58,648 KB
testcase_09 AC 179 ms
46,716 KB
testcase_10 AC 215 ms
49,176 KB
testcase_11 AC 534 ms
58,728 KB
testcase_12 AC 139 ms
46,092 KB
testcase_13 AC 455 ms
58,200 KB
testcase_14 AC 490 ms
56,500 KB
testcase_15 AC 86 ms
41,564 KB
testcase_16 AC 456 ms
54,112 KB
testcase_17 AC 413 ms
53,972 KB
testcase_18 AC 418 ms
54,192 KB
testcase_19 AC 465 ms
55,888 KB
testcase_20 AC 377 ms
52,580 KB
testcase_21 AC 486 ms
55,896 KB
testcase_22 AC 235 ms
47,940 KB
testcase_23 AC 133 ms
44,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayList<Integer> all = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            all.add(sc.nextInt());
        }
        System.out.println(check(29, all));
    }
    
    static int check(int idx, ArrayList<Integer> list) {
        if (idx < 0) {
            return 0;
        }
        ArrayList<Integer> odd  = new ArrayList<>();
        ArrayList<Integer> ev = new ArrayList<>();
        for (int x : list) {
            if ((x & (1 << idx)) == 0) {
                ev.add(x);
            } else {
                odd.add(x);
            }
        }
        if (ev.size() == 0) {
            return check(idx - 1, odd);
        } else if (odd.size() == 0) {
            return check(idx - 1, ev);
        } else {
            return Math.min(check(idx - 1, odd), check(idx - 1, ev)) + (1 << idx);
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0