結果

問題 No.2197 Same Dish
ユーザー ygd.ygd.
提出日時 2023-01-20 21:59:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 104,448 KB
最終ジャッジ日時 2024-06-23 09:57:52
合計ジャッジ時間 5,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import math
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
from collections import defaultdict
from collections import deque
import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
dx = [1,0,-1,0]
dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    N,K = map(int,input().split())
    MX = 2*pow(10,5) + 100
    times = [[] for _ in range(MX)]
    for i in range(N):
        L,R = map(int,input().split())
        times[L].append((i,1))
        times[R].append((i,-1))
    # 同じ料理を注文している人が一人もいない。全体から後で引く
    ans = 1
    cnt = 0
    for X in times:
        X.sort(key = lambda x: x[1])
        for p,sng in X:
            if sng == -1: #先に退出する人を引く
                cnt -= 1
            else:
                ans *= (K-cnt)
                ans %= MOD
                cnt += 1
                # print("x",ans)
    ans = pow(K,N,MOD) - ans
    print(ans%MOD)


if __name__ == '__main__':
    main()
0