結果

問題 No.2336 Do you like typical problems?
ユーザー hir355hir355
提出日時 2023-06-02 22:11:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 269,120 KB
最終ジャッジ日時 2023-08-28 03:49:37
合計ジャッジ時間 17,347 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,072 KB
testcase_01 AC 72 ms
71,512 KB
testcase_02 AC 73 ms
71,496 KB
testcase_03 AC 73 ms
71,480 KB
testcase_04 AC 74 ms
71,288 KB
testcase_05 AC 74 ms
71,492 KB
testcase_06 AC 73 ms
71,580 KB
testcase_07 AC 75 ms
71,436 KB
testcase_08 AC 139 ms
78,560 KB
testcase_09 AC 139 ms
78,664 KB
testcase_10 AC 137 ms
78,560 KB
testcase_11 AC 136 ms
78,688 KB
testcase_12 AC 137 ms
78,312 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 935 ms
94,612 KB
testcase_19 AC 959 ms
94,368 KB
testcase_20 AC 1,483 ms
268,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import factorial
compress = lambda arr: {e: i for i, e in enumerate(sorted(set(arr)))}
compress2 = lambda arr: {i: e for i, e in enumerate(sorted(set(arr)))}
MOD = 998244353
n = int(input())
b = [0] * n
c = [0] * n
l = []
for i in range(n):
    b[i], c[i] = map(int, input().split())
    b[i] -= 1
    l.append(b[i])
    l.append(c[i])
cp = compress(l)
cp2 = compress2(l)
# ans = 0
# for j in range(n):
#     for k in range(j + 1, n):
#         ans += (1 - max(0, min(c[j] - b[j], c[k] - b[k], c[j] - b[k], c[k] - b[j]) + 1) * pow((c[j] - b[j] + 1) * (c[k] - b[k] + 1), MOD - 2, MOD)) * f % MOD

ans = 0
m = len(cp)
w = [0] * m
x = [0] * m
y = [0] * m
for j in range(n):
    x[cp[b[j]]] += pow(c[j] - b[j], MOD - 2, MOD)
    x[cp[c[j]]] -= pow(c[j] - b[j], MOD - 2, MOD)
    y[cp[b[j]]] += pow((c[j] - b[j]) ** 2, MOD - 2, MOD)
    y[cp[c[j]]] -= pow((c[j] - b[j]) ** 2, MOD - 2, MOD)
s = 0
s2 = 0
f = 1
for i in range(n - 2):
    f *= (i + 1)
    f %= MOD
v = pow(2, MOD - 2, MOD)
for j in range(m - 1):
    s += x[j]
    s2 += y[j]
    ans += (s ** 2 - s2) * v * (cp2[j + 1] - cp2[j])
    ans %= MOD
print(((n * (n - 1) // 2 - ans) * n * (n - 1) // 2) * f % MOD)
0