結果

問題 No.2336 Do you like typical problems?
ユーザー hir355hir355
提出日時 2023-06-02 22:11:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 268,144 KB
最終ジャッジ日時 2024-06-08 23:26:03
合計ジャッジ時間 17,171 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,224 KB
testcase_01 AC 41 ms
51,968 KB
testcase_02 AC 43 ms
52,096 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 43 ms
52,608 KB
testcase_05 AC 43 ms
52,352 KB
testcase_06 AC 44 ms
52,224 KB
testcase_07 AC 43 ms
52,096 KB
testcase_08 AC 121 ms
77,568 KB
testcase_09 AC 122 ms
77,312 KB
testcase_10 AC 121 ms
77,312 KB
testcase_11 AC 121 ms
77,312 KB
testcase_12 AC 120 ms
77,056 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 944 ms
92,832 KB
testcase_19 AC 969 ms
92,548 KB
testcase_20 AC 1,600 ms
266,996 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