結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
53,460 KB
testcase_01 AC 161 ms
76,836 KB
testcase_02 AC 76 ms
76,284 KB
testcase_03 AC 76 ms
75,932 KB
testcase_04 AC 92 ms
93,796 KB
testcase_05 AC 93 ms
83,992 KB
testcase_06 AC 208 ms
77,936 KB
testcase_07 AC 216 ms
78,064 KB
testcase_08 AC 93 ms
104,380 KB
testcase_09 AC 89 ms
104,972 KB
testcase_10 AC 102 ms
104,688 KB
testcase_11 AC 94 ms
99,448 KB
testcase_12 AC 91 ms
105,292 KB
testcase_13 AC 135 ms
76,900 KB
testcase_14 AC 135 ms
76,796 KB
testcase_15 AC 137 ms
77,380 KB
testcase_16 AC 131 ms
76,804 KB
testcase_17 AC 134 ms
76,872 KB
testcase_18 AC 156 ms
76,908 KB
testcase_19 AC 139 ms
77,380 KB
testcase_20 AC 162 ms
77,404 KB
testcase_21 AC 158 ms
76,916 KB
testcase_22 AC 132 ms
76,732 KB
testcase_23 AC 89 ms
76,280 KB
testcase_24 AC 91 ms
76,224 KB
testcase_25 AC 91 ms
76,112 KB
testcase_26 AC 93 ms
76,996 KB
testcase_27 AC 87 ms
76,200 KB
testcase_28 AC 91 ms
76,892 KB
testcase_29 AC 87 ms
76,348 KB
testcase_30 AC 84 ms
76,872 KB
testcase_31 AC 88 ms
76,712 KB
testcase_32 AC 91 ms
76,732 KB
testcase_33 AC 97 ms
87,044 KB
testcase_34 AC 103 ms
94,740 KB
testcase_35 AC 99 ms
88,616 KB
testcase_36 AC 95 ms
86,604 KB
testcase_37 AC 94 ms
96,736 KB
testcase_38 AC 97 ms
90,016 KB
testcase_39 AC 96 ms
97,736 KB
testcase_40 AC 100 ms
93,572 KB
testcase_41 AC 99 ms
85,800 KB
testcase_42 AC 91 ms
89,128 KB
testcase_43 AC 235 ms
78,836 KB
testcase_44 AC 282 ms
78,468 KB
testcase_45 AC 274 ms
78,776 KB
testcase_46 AC 281 ms
78,844 KB
testcase_47 AC 245 ms
78,860 KB
testcase_48 AC 236 ms
78,496 KB
testcase_49 AC 260 ms
78,708 KB
testcase_50 AC 260 ms
78,680 KB
testcase_51 AC 256 ms
78,780 KB
testcase_52 AC 244 ms
78,720 KB
testcase_53 AC 98 ms
103,976 KB
testcase_54 AC 97 ms
104,372 KB
testcase_55 AC 110 ms
99,328 KB
testcase_56 AC 97 ms
103,928 KB
testcase_57 AC 107 ms
104,500 KB
testcase_58 AC 90 ms
105,276 KB
testcase_59 AC 98 ms
105,288 KB
testcase_60 AC 100 ms
104,056 KB
testcase_61 AC 102 ms
104,444 KB
testcase_62 AC 98 ms
105,080 KB
testcase_63 AC 81 ms
76,072 KB
testcase_64 AC 78 ms
76,072 KB
testcase_65 AC 86 ms
76,072 KB
testcase_66 AC 119 ms
76,368 KB
testcase_67 AC 98 ms
76,372 KB
testcase_68 AC 101 ms
76,632 KB
testcase_69 AC 131 ms
76,816 KB
testcase_70 AC 122 ms
76,692 KB
testcase_71 AC 137 ms
76,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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

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

    cum = 0
    S = 0
    M_pow_Q1 = pow(M, Q - 1, Mod); M_pow_Q2 = pow(M, Q - 2, Mod)

    for i in range(N):
        if i < left:
            cum += X[i]; cum %= M
            if cum == 0:
                S += M_pow_Q1
        elif left <= i < right:
            S += M_pow_Q2
        else:
            if i == right:
                cum = (M - sum(X[i] for i in range(right + 1, N))) % M
            else:
                cum += X[i]
                cum %= M

            if cum == 0:
                S += M_pow_Q1

    return (N * M_pow_Q1 - 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