結果

問題 No.1001 注文の多い順列
ユーザー chinchillachinchilla
提出日時 2020-03-03 15:50:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 386 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-22 00:12:35
合計ジャッジ時間 9,140 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 28 ms
10,752 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 26 ms
10,752 KB
testcase_08 AC 27 ms
10,752 KB
testcase_09 AC 27 ms
10,752 KB
testcase_10 AC 26 ms
10,624 KB
testcase_11 AC 26 ms
10,752 KB
testcase_12 AC 28 ms
10,624 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 32 ms
10,752 KB
testcase_15 AC 37 ms
10,752 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 29 ms
10,752 KB
testcase_18 AC 877 ms
11,520 KB
testcase_19 AC 780 ms
11,392 KB
testcase_20 AC 476 ms
11,264 KB
testcase_21 AC 440 ms
11,136 KB
testcase_22 AC 980 ms
11,520 KB
testcase_23 AC 1,069 ms
11,520 KB
testcase_24 AC 749 ms
11,648 KB
testcase_25 AC 995 ms
11,520 KB
testcase_26 AC 35 ms
11,392 KB
testcase_27 AC 91 ms
11,392 KB
testcase_28 AC 160 ms
11,392 KB
testcase_29 AC 195 ms
11,520 KB
testcase_30 AC 249 ms
11,648 KB
testcase_31 AC 324 ms
11,520 KB
testcase_32 AC 33 ms
11,392 KB
testcase_33 AC 34 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
m = 10**9+7
n = int(input())
l = [list(map(int, s.split())) for s in sys.stdin]
l = sorted((x-t, t) for t, x in l)
if sum(t for x, t in l) > len(l)//2:
    l = [(n-x, 1-t) for x, t in reversed(l)]
c = [1]+[0]*n
d = 1
for i, (x, t) in enumerate(l):
    d += t
    for j in range(d-1, -1, -1):
        c[j] = (c[j-1]*j - c[j]*(x-i+j) if t else c[j]*(x-i+j)) % m
print(sum(c)%m)
0