結果

問題 No.1958 Bit Game
ユーザー ああいい
提出日時 2022-05-28 16:49:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,628 KB
実行使用メモリ 144,068 KB
最終ジャッジ日時 2024-09-20 23:14:16
合計ジャッジ時間 8,424 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

N,X,Y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

P = 998244353

ans = 0
for i in range(18):
    a = 0
    b = 0
    mask = 1 << i
    for j in A:
        if mask & j:a += 1
    for j in B:
        if mask & j:b += 1
    tmp = 0
    x = 1
    y = 1
    if b == 0:continue
    if a == X:
        tmp = pow(X,N - 1,P) * a * pow(Y,N - 1,P) * b % P
        ans += tmp
        continue
    u = a * pow(X - a,N - 1,P) * pow(b,N,P) % P
    r = X * Y * pow(b * (X - a),P - 2,P) % P
    if r == 1:
        v = N
    else:
        v = (1 - pow(r,N,P)) * pow(1 - r,P - 2,P) % P
    ans += u * v % P * mask % P
    
print(ans % P)
    
0