結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-30 10:43:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,596 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 74,984 KB
最終ジャッジ日時 2023-09-12 03:21:28
合計ジャッジ時間 17,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
34,280 KB
testcase_01 AC 142 ms
29,872 KB
testcase_02 AC 142 ms
29,896 KB
testcase_03 AC 832 ms
31,328 KB
testcase_04 AC 665 ms
31,080 KB
testcase_05 AC 721 ms
31,140 KB
testcase_06 AC 576 ms
30,900 KB
testcase_07 AC 525 ms
30,836 KB
testcase_08 AC 679 ms
31,068 KB
testcase_09 AC 756 ms
31,276 KB
testcase_10 AC 414 ms
30,432 KB
testcase_11 AC 502 ms
30,768 KB
testcase_12 AC 370 ms
30,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0