結果

問題 No.2061 XOR Sort
ユーザー tentententen
提出日時 2023-04-13 16:40:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 958 ms / 2,000 ms
コード長 2,447 bytes
コンパイル時間 3,226 ms
コンパイル使用メモリ 93,044 KB
実行使用メモリ 63,884 KB
最終ジャッジ日時 2024-04-17 19:55:51
合計ジャッジ時間 16,540 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
37,028 KB
testcase_01 AC 57 ms
37,076 KB
testcase_02 AC 55 ms
36,832 KB
testcase_03 AC 56 ms
37,152 KB
testcase_04 AC 55 ms
37,152 KB
testcase_05 AC 57 ms
37,316 KB
testcase_06 AC 56 ms
37,424 KB
testcase_07 AC 56 ms
37,200 KB
testcase_08 AC 57 ms
37,296 KB
testcase_09 AC 56 ms
37,200 KB
testcase_10 AC 56 ms
37,240 KB
testcase_11 AC 56 ms
37,364 KB
testcase_12 AC 56 ms
37,392 KB
testcase_13 AC 55 ms
37,056 KB
testcase_14 AC 547 ms
58,368 KB
testcase_15 AC 533 ms
57,736 KB
testcase_16 AC 842 ms
62,260 KB
testcase_17 AC 630 ms
58,936 KB
testcase_18 AC 660 ms
59,636 KB
testcase_19 AC 641 ms
58,980 KB
testcase_20 AC 262 ms
50,388 KB
testcase_21 AC 460 ms
54,184 KB
testcase_22 AC 555 ms
58,232 KB
testcase_23 AC 127 ms
44,168 KB
testcase_24 AC 734 ms
62,220 KB
testcase_25 AC 947 ms
63,884 KB
testcase_26 AC 958 ms
62,512 KB
testcase_27 AC 931 ms
61,160 KB
testcase_28 AC 909 ms
62,480 KB
testcase_29 AC 451 ms
55,032 KB
testcase_30 AC 56 ms
37,412 KB
testcase_31 AC 164 ms
47,508 KB
testcase_32 AC 59 ms
37,152 KB
testcase_33 AC 55 ms
37,432 KB
testcase_34 AC 57 ms
36,940 KB
testcase_35 AC 57 ms
37,404 KB
testcase_36 AC 61 ms
37,176 KB
testcase_37 AC 58 ms
36,812 KB
testcase_38 AC 57 ms
37,376 KB
testcase_39 AC 57 ms
36,832 KB
testcase_40 AC 56 ms
37,244 KB
testcase_41 AC 57 ms
37,416 KB
testcase_42 AC 55 ms
37,160 KB
testcase_43 AC 55 ms
37,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    static int[] ans = new int[30];
    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());
        }
        calc(29, list);
        int sum = 0;
        for (int x : ans) {
            sum += x;
        }
        System.out.println((1 << sum) % MOD);
    }
    
    static void calc(int idx, ArrayList<Integer> list) {
        if (idx < 0) {
            return;
        }
        ArrayList<Integer> ev = new ArrayList<>();
        ArrayList<Integer> od = new ArrayList<>();
        for (int x : list) {
            if ((x & (1 << idx)) == 0) {
                ev.add(x);
            } else {
                od.add(x);
            }
        }
        if (ev.size() == 0) {
            calc(idx - 1, od);
        } else if (od.size() == 0) {
            calc(idx - 1, ev);
        } else {
            ans[idx] = 1;
            calc(idx - 1, ev);
            calc(idx - 1, od);
        }
    }
    
}
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