結果
問題 |
No.1189 Sum is XOR
|
ユーザー |
![]() |
提出日時 | 2024-07-22 17:14:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 403 ms / 2,000 ms |
コード長 | 2,019 bytes |
コンパイル時間 | 2,881 ms |
コンパイル使用メモリ | 78,696 KB |
実行使用メモリ | 123,276 KB |
最終ジャッジ日時 | 2024-07-22 17:14:31 |
合計ジャッジ時間 | 8,891 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; static int[] counts = new int[1 << 10]; 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; } while (n-- > 0) { counts[sc.nextInt()]++; } dp = new long[k][1 << 10][1 << 10]; for (long[][] arr1 : dp) { for (long[] arr2 : arr1) { Arrays.fill(arr2, -1); } } System.out.println(dfw(k - 1, (1 << 10) - 1, (1 << 10) - 1)); } static long dfw(int c, int idx, int v) { if (c < 0) { return 1; } if (idx == 0) { return 0; } if (dp[c][idx][v] < 0) { dp[c][idx][v] = (dfw(c, idx - 1, v) + ((v & idx) == idx ? dfw(c - 1, idx - 1, v ^ idx) * counts[idx] : 0)) % MOD; } return dp[c][idx][v]; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }