結果
問題 | No.1958 Bit Game |
ユーザー | tenten |
提出日時 | 2022-05-31 14:42:45 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 585 ms / 2,000 ms |
コード長 | 2,958 bytes |
コンパイル時間 | 2,789 ms |
コンパイル使用メモリ | 77,968 KB |
実行使用メモリ | 66,576 KB |
最終ジャッジ日時 | 2024-09-21 01:17:35 |
合計ジャッジ時間 | 18,245 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 515 ms
66,028 KB |
testcase_01 | AC | 511 ms
66,104 KB |
testcase_02 | AC | 513 ms
66,576 KB |
testcase_03 | AC | 515 ms
66,068 KB |
testcase_04 | AC | 519 ms
66,212 KB |
testcase_05 | AC | 519 ms
66,128 KB |
testcase_06 | AC | 530 ms
66,080 KB |
testcase_07 | AC | 514 ms
66,036 KB |
testcase_08 | AC | 520 ms
66,040 KB |
testcase_09 | AC | 516 ms
66,188 KB |
testcase_10 | AC | 250 ms
57,156 KB |
testcase_11 | AC | 352 ms
57,296 KB |
testcase_12 | AC | 443 ms
60,540 KB |
testcase_13 | AC | 400 ms
60,592 KB |
testcase_14 | AC | 387 ms
57,516 KB |
testcase_15 | AC | 435 ms
60,548 KB |
testcase_16 | AC | 384 ms
59,476 KB |
testcase_17 | AC | 477 ms
63,004 KB |
testcase_18 | AC | 456 ms
62,484 KB |
testcase_19 | AC | 379 ms
59,580 KB |
testcase_20 | AC | 372 ms
59,396 KB |
testcase_21 | AC | 440 ms
61,532 KB |
testcase_22 | AC | 222 ms
56,568 KB |
testcase_23 | AC | 324 ms
57,824 KB |
testcase_24 | AC | 461 ms
63,220 KB |
testcase_25 | AC | 332 ms
57,396 KB |
testcase_26 | AC | 359 ms
59,504 KB |
testcase_27 | AC | 585 ms
65,932 KB |
testcase_28 | AC | 405 ms
62,356 KB |
testcase_29 | AC | 285 ms
57,420 KB |
testcase_30 | AC | 56 ms
50,284 KB |
testcase_31 | AC | 55 ms
50,100 KB |
testcase_32 | AC | 56 ms
49,940 KB |
ソースコード
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(); long x = sc.nextInt(); long y = sc.nextInt(); long[] countsX = new long[19]; for (int i = 0; i < x; i++) { int v = sc.nextInt(); for (int j = 0; j <= 18 && v > 0; j++) { countsX[j] += v % 2; v >>= 1; } } long[] countsY = new long[19]; for (int i = 0; i < y; i++) { int v = sc.nextInt(); for (int j = 0; j <= 18 && v > 0; j++) { countsY[j] += v % 2; v >>= 1; } } long ans = 0; for (int i = 0; i <= 18; i++) { long[][][] matrix = new long[19][2][2]; matrix[0][0][0] = (x * y - countsX[i] * countsY[i]) % MOD; matrix[0][0][1] = x * (y - countsY[i]) % MOD; matrix[0][1][0] = countsX[i] * countsY[i] % MOD; matrix[0][1][1] = x * countsY[i] % MOD; for (int j = 1; j <= 18; j++) { for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { for (int c = 0; c < 2; c++) { matrix[j][a][c] += matrix[j - 1][a][b] * matrix[j - 1][b][c] % MOD; matrix[j][a][c] %= MOD; } } } } long[] current = new long[2]; current[0] = (1 << i); int z = n; for (int j = 18; j >= 0; j--) { if (z >= (1 << j)) { z -= (1 << j); long[] next = new long[2]; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { next[a] += matrix[j][a][b] * current[b] % MOD; next[a] %= MOD; } } current = next; } } ans += current[1]; 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(); } }