結果

問題 No.1958 Bit Game
ユーザー tentententen
提出日時 2022-05-31 13:18:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,946 bytes
コンパイル時間 5,317 ms
コンパイル使用メモリ 77,556 KB
実行使用メモリ 69,856 KB
最終ジャッジ日時 2023-10-21 00:36:44
合計ジャッジ時間 18,614 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 267 ms
60,696 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 207 ms
59,536 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 262 ms
60,140 KB
testcase_30 AC 50 ms
52,400 KB
testcase_31 AC 50 ms
52,376 KB
testcase_32 AC 50 ms
51,484 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 x = sc.nextInt();
        int y = sc.nextInt();
        int[] countsX = new int[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;
            }
        }
        int[] countsY = new int[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];
                            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();
    }
}
0