結果

問題 No.130 XOR Minimax
ユーザー tentententen
提出日時 2021-12-02 16:42:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 701 ms / 5,000 ms
コード長 1,734 bytes
コンパイル時間 3,256 ms
コンパイル使用メモリ 76,260 KB
実行使用メモリ 69,948 KB
最終ジャッジ日時 2023-09-18 10:22:32
合計ジャッジ時間 13,403 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 386 ms
63,060 KB
testcase_01 AC 44 ms
49,236 KB
testcase_02 AC 43 ms
49,344 KB
testcase_03 AC 44 ms
49,480 KB
testcase_04 AC 298 ms
60,488 KB
testcase_05 AC 631 ms
68,136 KB
testcase_06 AC 579 ms
69,948 KB
testcase_07 AC 701 ms
69,256 KB
testcase_08 AC 620 ms
68,308 KB
testcase_09 AC 182 ms
58,652 KB
testcase_10 AC 228 ms
58,404 KB
testcase_11 AC 552 ms
67,380 KB
testcase_12 AC 141 ms
58,040 KB
testcase_13 AC 435 ms
65,980 KB
testcase_14 AC 566 ms
67,832 KB
testcase_15 AC 86 ms
54,828 KB
testcase_16 AC 442 ms
65,284 KB
testcase_17 AC 491 ms
65,256 KB
testcase_18 AC 428 ms
65,164 KB
testcase_19 AC 585 ms
67,360 KB
testcase_20 AC 352 ms
63,156 KB
testcase_21 AC 579 ms
67,776 KB
testcase_22 AC 230 ms
57,268 KB
testcase_23 AC 128 ms
55,860 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> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        System.out.println(check(29, list));
    }
    
    static int check(int idx, ArrayList<Integer> list) {
        if (idx < 0) {
            return 0;
        }
        ArrayList<Integer> ev = new ArrayList<>();
        ArrayList<Integer> odd = new ArrayList<>();
        int base = (1 << idx);
        for (int x : list) {
            if ((x & base) == 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 base + Math.min(check(idx - 1, ev), check(idx - 1, odd));
        }
    }
}
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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0