結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー mkawa2mkawa2
提出日時 2024-02-23 23:19:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,816 KB
最終ジャッジ日時 2024-02-23 23:20:21
合計ジャッジ時間 10,782 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,600 KB
testcase_01 AC 118 ms
76,848 KB
testcase_02 AC 72 ms
75,928 KB
testcase_03 AC 72 ms
76,184 KB
testcase_04 AC 80 ms
90,128 KB
testcase_05 AC 83 ms
86,976 KB
testcase_06 AC 177 ms
77,540 KB
testcase_07 AC 166 ms
77,548 KB
testcase_08 AC 88 ms
104,300 KB
testcase_09 AC 90 ms
98,936 KB
testcase_10 AC 91 ms
104,816 KB
testcase_11 AC 90 ms
98,708 KB
testcase_12 AC 95 ms
98,856 KB
testcase_13 AC 103 ms
76,516 KB
testcase_14 AC 112 ms
76,800 KB
testcase_15 AC 108 ms
76,640 KB
testcase_16 AC 109 ms
76,896 KB
testcase_17 AC 107 ms
76,644 KB
testcase_18 AC 107 ms
76,640 KB
testcase_19 AC 104 ms
76,516 KB
testcase_20 AC 103 ms
76,644 KB
testcase_21 AC 106 ms
76,640 KB
testcase_22 AC 107 ms
76,644 KB
testcase_23 AC 78 ms
75,856 KB
testcase_24 AC 89 ms
76,420 KB
testcase_25 AC 79 ms
75,876 KB
testcase_26 AC 83 ms
75,888 KB
testcase_27 AC 82 ms
75,604 KB
testcase_28 AC 81 ms
76,120 KB
testcase_29 AC 82 ms
76,108 KB
testcase_30 AC 85 ms
75,900 KB
testcase_31 AC 80 ms
75,860 KB
testcase_32 AC 82 ms
76,008 KB
testcase_33 AC 90 ms
87,472 KB
testcase_34 AC 96 ms
94,448 KB
testcase_35 AC 94 ms
88,328 KB
testcase_36 AC 115 ms
86,064 KB
testcase_37 AC 92 ms
94,548 KB
testcase_38 AC 93 ms
90,168 KB
testcase_39 AC 85 ms
87,440 KB
testcase_40 AC 96 ms
93,208 KB
testcase_41 AC 88 ms
90,280 KB
testcase_42 AC 89 ms
89,732 KB
testcase_43 AC 161 ms
77,524 KB
testcase_44 AC 160 ms
77,020 KB
testcase_45 AC 186 ms
77,796 KB
testcase_46 AC 163 ms
77,400 KB
testcase_47 AC 159 ms
77,020 KB
testcase_48 AC 166 ms
77,424 KB
testcase_49 AC 175 ms
77,532 KB
testcase_50 AC 165 ms
77,396 KB
testcase_51 AC 174 ms
77,420 KB
testcase_52 AC 171 ms
77,400 KB
testcase_53 AC 94 ms
104,064 KB
testcase_54 AC 97 ms
104,276 KB
testcase_55 AC 97 ms
98,744 KB
testcase_56 AC 93 ms
104,132 KB
testcase_57 AC 97 ms
104,400 KB
testcase_58 AC 99 ms
98,840 KB
testcase_59 AC 102 ms
98,572 KB
testcase_60 AC 93 ms
103,980 KB
testcase_61 AC 94 ms
104,244 KB
testcase_62 AC 97 ms
98,440 KB
testcase_63 AC 94 ms
76,472 KB
testcase_64 AC 94 ms
76,472 KB
testcase_65 AC 94 ms
76,364 KB
testcase_66 AC 99 ms
76,512 KB
testcase_67 AC 103 ms
76,500 KB
testcase_68 AC 100 ms
76,512 KB
testcase_69 AC 102 ms
76,508 KB
testcase_70 AC 108 ms
76,512 KB
testcase_71 AC 105 ms
76,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

from collections import defaultdict

def solve():
    n, m = LI()
    xx = LI()
    l = r = -1
    c = 0
    for i, x in enumerate(xx):
        if x == -1:
            if l == -1: l = i
            r = i
            c += 1
    if c == 0:
        ans = n
        s = 0
        for x in xx:
            s += x
            s %= m
            if s == 0: ans -= 1
        if s: print(0)
        else: print(ans)

        return
    ans = (n-1)*pow(m, c-1, md)%md

    p = pow(m, c-1, md)
    s = 0
    for i in range(l):
        s += xx[i]
        s %= m
        if s == 0:
            ans -= p
            ans %= md
    s = 0
    for i in range(n-1, r, -1):
        s += xx[i]
        s %= m
        if s == 0:
            ans -= p
            ans %= md

    if c>1:ans -= pow(m, c-2, md)*(r-l)%md
    print(ans%md)

for _ in range(II()): solve()
0