結果

問題 No.2215 Slide Subset Sum
ユーザー ShirotsumeShirotsume
提出日時 2023-01-14 01:18:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,245 ms / 3,000 ms
コード長 2,155 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 419,136 KB
最終ジャッジ日時 2023-09-17 10:41:23
合計ジャッジ時間 31,853 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 326 ms
106,112 KB
testcase_01 AC 900 ms
106,260 KB
testcase_02 AC 917 ms
106,184 KB
testcase_03 AC 919 ms
106,388 KB
testcase_04 AC 1,047 ms
222,904 KB
testcase_05 AC 89 ms
71,248 KB
testcase_06 AC 93 ms
71,400 KB
testcase_07 AC 92 ms
71,080 KB
testcase_08 AC 98 ms
71,408 KB
testcase_09 AC 93 ms
71,212 KB
testcase_10 AC 94 ms
71,264 KB
testcase_11 AC 89 ms
71,244 KB
testcase_12 AC 100 ms
76,684 KB
testcase_13 AC 105 ms
77,116 KB
testcase_14 AC 105 ms
76,708 KB
testcase_15 AC 91 ms
71,260 KB
testcase_16 AC 113 ms
77,504 KB
testcase_17 AC 1,131 ms
292,936 KB
testcase_18 AC 1,083 ms
283,896 KB
testcase_19 AC 1,032 ms
180,724 KB
testcase_20 AC 1,033 ms
359,168 KB
testcase_21 AC 1,158 ms
279,336 KB
testcase_22 AC 1,028 ms
361,404 KB
testcase_23 AC 1,131 ms
418,336 KB
testcase_24 AC 1,135 ms
419,136 KB
testcase_25 AC 1,117 ms
399,444 KB
testcase_26 AC 1,050 ms
362,868 KB
testcase_27 AC 164 ms
79,108 KB
testcase_28 AC 182 ms
93,988 KB
testcase_29 AC 189 ms
89,848 KB
testcase_30 AC 478 ms
92,824 KB
testcase_31 AC 432 ms
195,084 KB
testcase_32 AC 207 ms
87,244 KB
testcase_33 AC 844 ms
280,004 KB
testcase_34 AC 674 ms
257,140 KB
testcase_35 AC 221 ms
92,956 KB
testcase_36 AC 313 ms
137,800 KB
testcase_37 AC 608 ms
268,860 KB
testcase_38 AC 204 ms
107,384 KB
testcase_39 AC 911 ms
106,080 KB
testcase_40 AC 246 ms
105,616 KB
testcase_41 AC 93 ms
71,252 KB
testcase_42 AC 973 ms
291,992 KB
testcase_43 AC 1,245 ms
288,904 KB
testcase_44 AC 1,243 ms
289,056 KB
testcase_45 AC 1,081 ms
377,320 KB
testcase_46 AC 1,083 ms
377,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n, m, k = mi()
a = li()

#以降, k を MAXI とおく
MAXI = k

#生の値を持つstack2つと、dpテーブルを持つstack2つを用意
valuetop = []
valuebottom = []
dptop = []
dpbottom = []

#番兵として、空集合に対応するdpテーブルを用意する
X = [0] * MAXI
X[0] = 1
dptop.append(X)
dpbottom.append(X)

def push(x):
    #queueへのpush操作。bottomに値を追加してdpを更新するだけ
    valuebottom.append(x)
    ndp = [0] * MAXI
    for v in range(MAXI):
        ndp[(v+x)%MAXI] += dpbottom[-1][v]
        ndp[v] += dpbottom[-1][v]
        ndp[(v+x)%MAXI] %= mod
        ndp[v] %= mod
    dpbottom.append(ndp)

def pop():
    #queueからのpop操作。topのstackに値が入っていればそこからpop。入っていなければ、今bottomにある要素を全部出して反転させてtopに入れる。
    #各要素について、範囲外→top→bottom→範囲外(途中で終わる可能性もある)と移動するので、計算量は償却O(NK)
    if not valuetop:
        valuebottom.reverse()
        for x in valuebottom:
            ndp = [0] * MAXI
            for v in range(MAXI):
                ndp[(v+x)%MAXI] += dptop[-1][v]
                ndp[v] += dptop[-1][v]
                ndp[(v+x)%MAXI] %= mod
                ndp[v] %= mod
            dptop.append(ndp)
            valuetop.append(x)
        while valuebottom:
            valuebottom.pop()
        while len(dpbottom) > 1:
            dpbottom.pop()
    dptop.pop()
    valuetop.pop()

def fold():
    #2つのテーブルdptopとdpbottomの結果を統合する。計算量O(K)
    ans = 0
    for v in range(MAXI):
        ans += dptop[-1][v] * dpbottom[-1][(MAXI-v) % MAXI]
        ans %= mod
    return ans


for i in range(m):
    push(a[i])
ans = []
ans.append(fold())

for i in range(m, n):
    pop()
    push(a[i])
    ans.append(fold())

for v in ans:
    print((v-1) % mod)




        

0