結果

問題 No.130 XOR Minimax
ユーザー tentententen
提出日時 2023-01-26 13:02:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 609 ms / 5,000 ms
コード長 2,268 bytes
コンパイル時間 3,608 ms
コンパイル使用メモリ 96,772 KB
実行使用メモリ 71,396 KB
最終ジャッジ日時 2023-09-09 15:14:11
合計ジャッジ時間 13,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 352 ms
64,792 KB
testcase_01 AC 42 ms
47,172 KB
testcase_02 AC 41 ms
49,464 KB
testcase_03 AC 42 ms
49,444 KB
testcase_04 AC 291 ms
60,208 KB
testcase_05 AC 609 ms
69,796 KB
testcase_06 AC 544 ms
71,396 KB
testcase_07 AC 549 ms
69,248 KB
testcase_08 AC 573 ms
69,220 KB
testcase_09 AC 161 ms
58,720 KB
testcase_10 AC 217 ms
58,920 KB
testcase_11 AC 497 ms
67,140 KB
testcase_12 AC 139 ms
57,844 KB
testcase_13 AC 447 ms
67,848 KB
testcase_14 AC 508 ms
67,312 KB
testcase_15 AC 82 ms
55,140 KB
testcase_16 AC 418 ms
64,644 KB
testcase_17 AC 435 ms
67,268 KB
testcase_18 AC 424 ms
66,936 KB
testcase_19 AC 501 ms
67,000 KB
testcase_20 AC 338 ms
62,856 KB
testcase_21 AC 580 ms
67,908 KB
testcase_22 AC 225 ms
57,584 KB
testcase_23 AC 122 ms
55,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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(dfw(30, list));
    }
    
    static int dfw(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 dfw(idx - 1, odd);
        } else if (odd.size() == 0) {
            return dfw(idx - 1, ev);
        } else {
            return Math.min(dfw(idx - 1, odd), dfw(idx - 1, ev)) + (1 << idx);
        }
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0