結果

問題 No.2336 Do you like typical problems?
ユーザー titiatitia
提出日時 2023-10-04 05:04:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 880 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 225,356 KB
最終ジャッジ日時 2023-10-04 05:04:38
合計ジャッジ時間 18,897 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
152,260 KB
testcase_01 AC 130 ms
152,428 KB
testcase_02 AC 129 ms
152,464 KB
testcase_03 AC 128 ms
152,396 KB
testcase_04 AC 127 ms
152,448 KB
testcase_05 AC 127 ms
152,704 KB
testcase_06 AC 126 ms
152,188 KB
testcase_07 AC 129 ms
152,204 KB
testcase_08 AC 168 ms
154,868 KB
testcase_09 AC 171 ms
154,768 KB
testcase_10 AC 167 ms
154,792 KB
testcase_11 AC 173 ms
155,084 KB
testcase_12 AC 169 ms
154,880 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 536 ms
223,896 KB
testcase_19 AC 564 ms
214,580 KB
testcase_20 AC 1,074 ms
222,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from operator import itemgetter

mod=998244353

N=int(input())
LIST=[list(map(int,input().split())) for i in range(N)]

Q=[]

for b,c in LIST:
    Q.append((b,c-b+1,1))
    Q.append((c+1,c-b+1,2))

Q.sort(key=itemgetter(1))
Q.sort(key=itemgetter(0))

now1=0

ANS1=0

for i in range(len(Q)):
    x,length,com=Q[i]
    
    if com==1:
        now1+=pow(length,-1,mod)
    else:
        now1-=pow(length,-1,mod)

    if i+1<len(Q) and x!=Q[i+1][0]:
        z=Q[i+1][0]

        # [x,z)の間を考え、答えに加算。

        ANS1+=now1*now1*(z-x)%mod
        #print("!",now1)
        ANS1%=mod

for b,c in LIST:
    k=c-b+1

    ANS1-=pow(k,-1,mod)
    ANS1%=mod

#print(ANS1)



ANS2=(N*(N-1)//2-ANS1*pow(2,-1,mod))%mod

#print(ANS2)


F=[1]
for i in range(1,1000000):
    F.append(F[-1]*i%mod)


print(ANS2*F[N]*pow(2,mod-2,mod)%mod)


0