結果

問題 No.1189 Sum is XOR
ユーザー tentententen
提出日時 2020-08-24 07:16:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,765 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 77,032 KB
実行使用メモリ 58,732 KB
最終ジャッジ日時 2024-04-23 20:31:55
合計ジャッジ時間 19,669 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,765 ms
58,720 KB
testcase_01 AC 1,419 ms
58,592 KB
testcase_02 AC 1,448 ms
58,732 KB
testcase_03 AC 107 ms
41,384 KB
testcase_04 AC 107 ms
41,264 KB
testcase_05 AC 98 ms
40,120 KB
testcase_06 AC 98 ms
40,236 KB
testcase_07 AC 105 ms
41,324 KB
testcase_08 AC 100 ms
40,336 KB
testcase_09 AC 110 ms
41,064 KB
testcase_10 AC 105 ms
40,956 KB
testcase_11 AC 545 ms
48,352 KB
testcase_12 AC 1,469 ms
58,552 KB
testcase_13 AC 1,443 ms
58,496 KB
testcase_14 AC 1,029 ms
58,312 KB
testcase_15 AC 563 ms
48,024 KB
testcase_16 AC 444 ms
48,032 KB
testcase_17 AC 510 ms
48,044 KB
testcase_18 AC 865 ms
57,972 KB
testcase_19 AC 1,265 ms
58,428 KB
testcase_20 AC 1,267 ms
58,268 KB
testcase_21 AC 121 ms
41,380 KB
testcase_22 AC 109 ms
41,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 998244353;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	if (k > 10) {
    	    System.out.println(0);
    	    return;
    	}
    	int[] arr = new int[n + 1];
    	for (int i = 1; i <= n; i++) {
    	    arr[i] = sc.nextInt();
    	}
    	int[][] dp = new int[12][1 << 10];
    	dp[0][0] = 1;
    	for (int i = 1; i <= n; i++) {
    	    for (int l = (1 << 10) - 1; l >= 0; l--) {
    	        if ((l ^ arr[i]) == l + arr[i]) {
    	            for (int j = 1; j <= 10; j++) {
    	                dp[j][arr[i] + l] += dp[j - 1][l];
    	                dp[j][arr[i] + l] %= MOD;
    	            }
    	        } 
    	    }
    	}
    	int ans = 0;
    	for (int x : dp[k]) {
    	    ans += x;
    	    ans %= MOD;
    	}
    	System.out.println(ans);
    }
}

0