結果

問題 No.130 XOR Minimax
ユーザー tentententen
提出日時 2021-11-10 11:59:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,152 ms / 5,000 ms
コード長 1,819 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 75,060 KB
実行使用メモリ 90,632 KB
最終ジャッジ日時 2023-08-13 05:14:17
合計ジャッジ時間 19,537 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 672 ms
75,080 KB
testcase_01 AC 42 ms
47,368 KB
testcase_02 AC 43 ms
49,592 KB
testcase_03 AC 44 ms
49,288 KB
testcase_04 AC 163 ms
56,280 KB
testcase_05 AC 217 ms
57,356 KB
testcase_06 AC 932 ms
89,012 KB
testcase_07 AC 961 ms
88,392 KB
testcase_08 AC 1,126 ms
82,616 KB
testcase_09 AC 275 ms
64,660 KB
testcase_10 AC 358 ms
67,072 KB
testcase_11 AC 787 ms
90,632 KB
testcase_12 AC 198 ms
61,664 KB
testcase_13 AC 645 ms
87,668 KB
testcase_14 AC 1,152 ms
78,900 KB
testcase_15 AC 90 ms
54,540 KB
testcase_16 AC 948 ms
89,160 KB
testcase_17 AC 857 ms
75,344 KB
testcase_18 AC 813 ms
74,444 KB
testcase_19 AC 1,043 ms
77,892 KB
testcase_20 AC 630 ms
74,576 KB
testcase_21 AC 1,041 ms
77,156 KB
testcase_22 AC 378 ms
67,280 KB
testcase_23 AC 178 ms
56,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        HashSet<Integer> list = new HashSet<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        System.out.println(getMin(30, list));
    }
    
    static int getMin(int idx, HashSet<Integer> list) {
        if (idx < 0) {
            return 0;
        }
        HashSet<Integer> odd = new HashSet<>();
        HashSet<Integer> even = new HashSet<>();
        for (int x : list) {
            if ((x & (1 << idx)) == 0) {
                even.add(x);
            } else {
                odd.add(x ^ (1 << idx));
            }
        }
        if (even.size() == 0) {
            return getMin(idx - 1, odd);
        } else if (odd.size() == 0) {
            return getMin(idx - 1, even);
        } else {
            return (1 << idx) + Math.min(getMin(idx - 1, even), getMin(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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0