結果

問題 No.1189 Sum is XOR
ユーザー tentententen
提出日時 2023-04-25 09:17:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 2,286 bytes
コンパイル時間 2,683 ms
コンパイル使用メモリ 87,512 KB
実行使用メモリ 56,176 KB
最終ジャッジ日時 2024-04-26 16:39:12
合計ジャッジ時間 7,264 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
55,732 KB
testcase_01 AC 233 ms
55,876 KB
testcase_02 AC 229 ms
55,700 KB
testcase_03 AC 55 ms
50,160 KB
testcase_04 AC 56 ms
50,168 KB
testcase_05 AC 55 ms
50,184 KB
testcase_06 AC 56 ms
50,272 KB
testcase_07 AC 57 ms
50,108 KB
testcase_08 AC 56 ms
50,036 KB
testcase_09 AC 54 ms
50,052 KB
testcase_10 AC 55 ms
50,604 KB
testcase_11 AC 153 ms
54,660 KB
testcase_12 AC 228 ms
55,660 KB
testcase_13 AC 238 ms
55,760 KB
testcase_14 AC 206 ms
55,900 KB
testcase_15 AC 184 ms
54,644 KB
testcase_16 AC 183 ms
52,856 KB
testcase_17 AC 165 ms
54,544 KB
testcase_18 AC 197 ms
56,176 KB
testcase_19 AC 256 ms
55,872 KB
testcase_20 AC 245 ms
55,880 KB
testcase_21 AC 66 ms
50,604 KB
testcase_22 AC 69 ms
50,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    static long[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (k > 10) {
            System.out.println(0);
            return;
        }
        long[][] dp = new long[k][1 << 10];
        for (int i = 0; i < n; i++) {
            dp[0][sc.nextInt()]++;
        }
        for (int i = 1; i < k; i++) {
            for (int j = 1; j < (1 << 10); j++) {
                for (int s = j + 1; s < (1 << 10); s++) {
                    if ((j & s) == 0) {
                        dp[i][j ^ s] += dp[i - 1][j] * dp[0][s] % MOD;
                        dp[i][j ^ s] %= MOD;
                    }
                }
            }
        }
        long ans = 0;
        for (int i = 1; i < (1 << 10); i++) {
            ans += dp[k - 1][i];
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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