結果

問題 No.2345 max(l,r)
ユーザー minimumminimum
提出日時 2023-06-09 23:02:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,070 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 129,332 KB
最終ジャッジ日時 2023-08-30 14:14:04
合計ジャッジ時間 25,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 208 ms
99,280 KB
testcase_01 WA -
testcase_02 AC 424 ms
103,256 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 418 ms
103,712 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 279 ms
126,100 KB
testcase_23 AC 279 ms
124,536 KB
testcase_24 AC 229 ms
107,876 KB
testcase_25 AC 254 ms
100,652 KB
testcase_26 AC 251 ms
100,820 KB
testcase_27 AC 243 ms
100,720 KB
testcase_28 AC 232 ms
114,628 KB
testcase_29 AC 240 ms
118,204 KB
testcase_30 AC 219 ms
104,496 KB
testcase_31 AC 252 ms
127,640 KB
testcase_32 AC 228 ms
110,332 KB
testcase_33 AC 234 ms
114,116 KB
testcase_34 AC 206 ms
99,444 KB
testcase_35 AC 217 ms
105,072 KB
testcase_36 AC 222 ms
106,540 KB
testcase_37 AC 224 ms
110,512 KB
testcase_38 AC 258 ms
124,068 KB
testcase_39 AC 272 ms
123,992 KB
testcase_40 AC 269 ms
124,028 KB
testcase_41 AC 261 ms
123,976 KB
testcase_42 AC 259 ms
123,768 KB
testcase_43 AC 263 ms
123,948 KB
testcase_44 AC 271 ms
123,844 KB
testcase_45 AC 282 ms
129,332 KB
testcase_46 AC 280 ms
126,260 KB
testcase_47 AC 238 ms
124,012 KB
testcase_48 AC 228 ms
101,088 KB
testcase_49 AC 229 ms
100,992 KB
testcase_50 AC 235 ms
100,996 KB
testcase_51 AC 239 ms
100,968 KB
testcase_52 AC 233 ms
101,084 KB
testcase_53 AC 230 ms
101,192 KB
testcase_54 AC 236 ms
101,156 KB
testcase_55 AC 237 ms
100,952 KB
testcase_56 AC 236 ms
100,952 KB
testcase_57 AC 239 ms
101,316 KB
testcase_58 AC 255 ms
101,176 KB
testcase_59 AC 250 ms
100,904 KB
testcase_60 AC 250 ms
101,408 KB
testcase_61 AC 247 ms
101,100 KB
testcase_62 AC 251 ms
101,264 KB
testcase_63 AC 256 ms
101,028 KB
testcase_64 AC 247 ms
101,212 KB
testcase_65 AC 253 ms
101,000 KB
testcase_66 AC 252 ms
101,108 KB
testcase_67 AC 246 ms
101,412 KB
testcase_68 AC 848 ms
102,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import e


class Combination:

    def __init__(self, MX=10**6, MOD=998244353):
        self.MX = MX
        self.MOD = MOD
        self.fact = [1] * (MX + 1)
        self.inv = [1] * (MX + 1)
        self.f_inv = [1] * (MX + 1)
        for i in range(2, MX + 1):
            self.fact[i] = (self.fact[i - 1] * i) % self.MOD
            self.inv[i] = ( - (self.MOD // i) * (self.inv[self.MOD % i])) % self.MOD
            self.f_inv[i] = (self.f_inv[i - 1] * self.inv[i]) % self.MOD
    
    def invs(self, n):
        if n <= self.MX:
            return self.inv[n]
        else:
            return pow(n, self.MOD - 2, self.MOD)
    
    def p(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r]) % self.MOD
    
    def c(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r] * self.f_inv[n - r]) % self.MOD

com = Combination()

def solve():

    MOD = 998244353
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    dic = dict()
    for i in range(N):
        if N - A[i] not in dic:
            dic[N - A[i]] = 0
        dic[N - A[i]] += 1
    ls = list(dic.keys())
    ls.sort()

    lsum = 0
    rsum = 0
    L, R = [], []

    ans = 1
    for i in range(len(ls)):
        now = ls[i]
        j = now - lsum
        k = now - rsum
        if lsum + dic[now] == now:
            L.append(dic[now])
            lsum = now
            if rsum + dic[now] == now and i != len(ls) - 1:
                ans *= 2
                ans %= MOD
        elif rsum + dic[now] == now:
            R.append(dic[now])
            rsum = now
        elif j + k == dic[now] and j > 0 and k > 0:
            lsum = now
            rsum = now
            L.append(j)
            R.append(k)
            ans *= com.c(dic[now], j)
            ans %= MOD
        else:
            print(0)
            return
    ans *= com.c(M, len(L) + len(R))
    ans %= MOD
    print(ans)
    return
        

T = int(input())
for _ in range(T):
    solve()
0