結果

問題 No.1189 Sum is XOR
ユーザー tentententen
提出日時 2021-12-01 14:14:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 1,601 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 73,856 KB
実行使用メモリ 57,248 KB
最終ジャッジ日時 2023-09-17 19:36:37
合計ジャッジ時間 9,359 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 567 ms
55,728 KB
testcase_01 AC 461 ms
57,028 KB
testcase_02 AC 387 ms
56,856 KB
testcase_03 AC 44 ms
49,288 KB
testcase_04 AC 44 ms
49,240 KB
testcase_05 AC 44 ms
49,328 KB
testcase_06 AC 45 ms
49,208 KB
testcase_07 AC 45 ms
49,480 KB
testcase_08 AC 45 ms
49,636 KB
testcase_09 AC 44 ms
49,460 KB
testcase_10 AC 44 ms
49,476 KB
testcase_11 AC 208 ms
56,168 KB
testcase_12 AC 391 ms
57,248 KB
testcase_13 AC 504 ms
55,560 KB
testcase_14 AC 367 ms
55,552 KB
testcase_15 AC 264 ms
55,812 KB
testcase_16 AC 172 ms
52,996 KB
testcase_17 AC 192 ms
55,444 KB
testcase_18 AC 254 ms
57,100 KB
testcase_19 AC 451 ms
53,712 KB
testcase_20 AC 527 ms
55,592 KB
testcase_21 AC 43 ms
49,292 KB
testcase_22 AC 44 ms
49,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    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;
        }
        int[][] dp = new int[k + 1][1 << 10];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int xor = ((1 << 10) - 1) ^ x;
            for (int j = xor; j > 0; j = ((j - 1) & xor)) {
                for (int a = 1; a <= k; a++) {
                    dp[a][j | x] += dp[a - 1][j];
                    dp[a][j | x] %= MOD;
                }
            }
            dp[1][x]++;
        }
        int ans = 0;
        for (int x : dp[k]) {
            ans += x;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}

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