結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
34,196 KB
testcase_01 AC 142 ms
29,952 KB
testcase_02 AC 137 ms
29,920 KB
testcase_03 AC 803 ms
32,652 KB
testcase_04 AC 637 ms
31,956 KB
testcase_05 AC 704 ms
32,136 KB
testcase_06 AC 558 ms
31,656 KB
testcase_07 AC 523 ms
31,508 KB
testcase_08 AC 682 ms
32,008 KB
testcase_09 AC 766 ms
32,112 KB
testcase_10 AC 409 ms
31,020 KB
testcase_11 AC 500 ms
31,548 KB
testcase_12 AC 374 ms
30,896 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 #

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):
    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):
    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()))
    B = np.array(input().split(), dtype=np.intc)

    que = []
    for a in A:
        que.append(np.array([a-1, 1], dtype=np.int64))

    i = 0
    while i < len(que):
        if i + 1 == len(que):
            break
        que.append(mod_convolve_10(que[i], que[i+1]))
        i += 2

    F = que[-1]
    print(*F[B], sep="\n")


main()
0