結果
| 問題 |
No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2022-04-30 10:43:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,596 bytes |
| コンパイル時間 | 94 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 44,700 KB |
| 最終ジャッジ日時 | 2024-06-29 16:23:51 |
| 合計ジャッジ時間 | 19,898 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 18 |
ソースコード
from collections import deque
import numpy as np
mod = 998244353
def convolve(A, B):
n = len(A) + len(B) - 1
fftlen = 1 << (n-1).bit_length()
fa = np.fft.rfft(A, fftlen)
fb = np.fft.rfft(B, fftlen)
inv = (np.fft.irfft(fa * fb, fftlen) + 0.5).astype(np.int64)
return inv[:n]
def mod_convolve_15(A, B, mod):
a1, a2 = np.divmod(A, 1 << 15)
b1, b2 = np.divmod(B, 1 << 15)
x = convolve(a1, b1) % mod
y = convolve(a2, b2) % mod
xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod
res = (x << 30) + (xy << 15) + y
return res % mod
def mod_convolve_10(A, B, mod):
a1, a2 = np.divmod(A, 1 << 20)
a2, a3 = np.divmod(a2, 1 << 10)
b1, b2 = np.divmod(B, 1 << 20)
b2, b3 = np.divmod(b2, 1 << 10)
x = convolve(a1, b1) % mod
y = convolve(a2, b2) % mod
z = convolve(a3, b3) % mod
xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod
yz = (convolve(a2 + a3, b2 + b3) - (y + z)) % mod
zx = (convolve(a3 + a1, b3 + b1) - (z + x)) % mod
res = ((((x << 20) % mod) << 20) +
(((xy << 20) % mod) << 10) +
((y + zx) << 20) +
(yz << 10) % mod + z) % mod
return res
def main():
N, Q = map(int, input().split())
A = list(map(int, input().split()))
que = deque()
for a in A:
que.append(np.array([a-1, 1], dtype=np.int64))
while len(que) >= 2:
f = que.popleft()
g = que.popleft()
h = mod_convolve_10(f, g, mod)
que.append(h)
F = que.pop()
B = np.array(input().split(), dtype=np.intc)
print(*F[B], sep="\n")
main()
tktk_snsn