結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー 👑 KazunKazun
提出日時 2023-06-25 23:31:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 105,292 KB
最終ジャッジ日時 2024-02-23 00:18:53
合計ジャッジ時間 20,907 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 203 ms
76,888 KB
testcase_02 AC 147 ms
75,984 KB
testcase_03 AC 141 ms
76,072 KB
testcase_04 AC 174 ms
93,924 KB
testcase_05 AC 175 ms
84,248 KB
testcase_06 AC 353 ms
79,108 KB
testcase_07 AC 349 ms
79,412 KB
testcase_08 AC 183 ms
104,508 KB
testcase_09 AC 178 ms
104,972 KB
testcase_10 AC 184 ms
104,816 KB
testcase_11 AC 156 ms
99,576 KB
testcase_12 AC 166 ms
105,292 KB
testcase_13 AC 195 ms
77,192 KB
testcase_14 AC 205 ms
77,204 KB
testcase_15 AC 187 ms
76,928 KB
testcase_16 AC 205 ms
77,332 KB
testcase_17 AC 190 ms
77,084 KB
testcase_18 AC 197 ms
77,072 KB
testcase_19 AC 200 ms
77,200 KB
testcase_20 AC 200 ms
77,308 KB
testcase_21 AC 195 ms
77,068 KB
testcase_22 AC 187 ms
77,224 KB
testcase_23 AC 147 ms
76,240 KB
testcase_24 AC 147 ms
76,276 KB
testcase_25 AC 137 ms
76,932 KB
testcase_26 AC 146 ms
76,820 KB
testcase_27 AC 141 ms
76,724 KB
testcase_28 AC 167 ms
76,400 KB
testcase_29 AC 142 ms
76,248 KB
testcase_30 AC 150 ms
76,720 KB
testcase_31 AC 159 ms
76,116 KB
testcase_32 AC 140 ms
76,216 KB
testcase_33 AC 141 ms
87,896 KB
testcase_34 AC 169 ms
96,180 KB
testcase_35 AC 157 ms
88,616 KB
testcase_36 AC 163 ms
86,720 KB
testcase_37 AC 155 ms
92,124 KB
testcase_38 AC 157 ms
87,068 KB
testcase_39 AC 158 ms
96,096 KB
testcase_40 AC 150 ms
87,928 KB
testcase_41 AC 168 ms
85,300 KB
testcase_42 AC 142 ms
89,256 KB
testcase_43 AC 388 ms
79,420 KB
testcase_44 AC 388 ms
79,792 KB
testcase_45 AC 389 ms
79,176 KB
testcase_46 AC 451 ms
79,924 KB
testcase_47 AC 397 ms
79,636 KB
testcase_48 AC 388 ms
79,912 KB
testcase_49 AC 379 ms
79,280 KB
testcase_50 AC 384 ms
79,676 KB
testcase_51 AC 362 ms
79,516 KB
testcase_52 AC 368 ms
79,024 KB
testcase_53 AC 169 ms
104,104 KB
testcase_54 AC 181 ms
104,500 KB
testcase_55 AC 151 ms
99,592 KB
testcase_56 AC 160 ms
104,056 KB
testcase_57 AC 179 ms
104,620 KB
testcase_58 AC 127 ms
105,276 KB
testcase_59 AC 143 ms
105,288 KB
testcase_60 AC 181 ms
104,184 KB
testcase_61 AC 192 ms
104,572 KB
testcase_62 AC 165 ms
105,080 KB
testcase_63 AC 92 ms
76,072 KB
testcase_64 AC 89 ms
76,072 KB
testcase_65 AC 90 ms
76,072 KB
testcase_66 AC 116 ms
76,496 KB
testcase_67 AC 116 ms
76,372 KB
testcase_68 AC 116 ms
76,628 KB
testcase_69 AC 161 ms
76,868 KB
testcase_70 AC 161 ms
76,872 KB
testcase_71 AC 174 ms
77,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    Mod = 998244353

    K = A.count(-1)
    if K == 1:
        i = A.index(-1)
        A[i] = (- sum(A[j] for j in range(N) if i != j)) % M

    if -1 not in A:
        if sum(A) % M != 0:
            return 0

        cum = 0
        k = 0
        for a in A:
            cum += a; cum %= M
            if cum == 0:
                k += 1
        return N - k

    left = min(i for i in range(N) if A[i] == -1)
    right = max (i for i in range(N) if A[i] == -1)

    cum = 0
    H = (M - sum(A[i] for i in range(N) if A[i] != -1 and not(left < i < right))) % M
    S = 0

    for i in range(N):
        if i < left:
            cum += A[i]; cum %= M
            if cum == 0:
                S += pow(M, K-1, Mod)
        elif left <= i < right:
            S += pow(M, K-2, Mod)
        else:
            if i == right:
                cum += H
            else:
                cum += A[i]
            cum %= M
            if cum == 0:
                S += pow(M, K-1, Mod)

    return (N * pow(M, K-1, Mod) - S) % Mod

#==================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

T=int(input())
write("\n".join(map(str, [solve() for _ in range(T)])))
0