結果

問題 No.2197 Same Dish
ユーザー lloyzlloyz
提出日時 2023-01-20 23:38:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 95,656 KB
最終ジャッジ日時 2023-09-05 16:04:32
合計ジャッジ時間 6,697 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,088 KB
testcase_01 AC 74 ms
70,768 KB
testcase_02 AC 76 ms
71,036 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 76 ms
70,992 KB
testcase_06 AC 74 ms
71,040 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 76 ms
70,964 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
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 AC 469 ms
95,488 KB
testcase_22 AC 454 ms
95,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
LR.append([10**6, 10**6 + 1])
mod = 998244353

P = [k % mod for _ in range(n + 1)]
for i in range(1, n + 1):
    P[i] = P[i - 1] * (k - i) % mod

LR.sort(key=lambda x: (x[1], x[0]))
ans = 0
num = 0
res = 0
l, r = -1, -1
for i in range(n + 1):
    if l == -1 and r == -1:
        l, r = LR[i]
        r -= 1
        num += 1
    elif r < LR[i][0]:
        if num > 1:
            if ans == 0:
                ans = 1
            ans *= (pow(k, num, mod) - P[num]) % mod
            ans %= mod
        else:
            res += 1
            l, r = LR[i]
            r -= 1
        num = 1
    else:
        l = min(l, LR[i][0])
        r = max(r, LR[i][1] - 1)
        num += 1
    if i == n - 1:
        ans *= pow(k, res, mod)
        ans %= mod
print(ans)
0