結果

問題 No.1001 注文の多い順列
ユーザー tktk_snsntktk_snsn
提出日時 2022-02-15 19:54:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 717 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 13,228 KB
最終ジャッジ日時 2023-09-11 17:02:16
合計ジャッジ時間 5,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,432 KB
testcase_01 AC 17 ms
8,188 KB
testcase_02 AC 16 ms
8,028 KB
testcase_03 AC 17 ms
8,076 KB
testcase_04 AC 17 ms
8,308 KB
testcase_05 AC 17 ms
8,056 KB
testcase_06 AC 17 ms
8,052 KB
testcase_07 AC 17 ms
8,432 KB
testcase_08 AC 17 ms
8,048 KB
testcase_09 AC 17 ms
8,140 KB
testcase_10 AC 18 ms
7,980 KB
testcase_11 AC 17 ms
8,060 KB
testcase_12 AC 17 ms
7,976 KB
testcase_13 AC 26 ms
8,192 KB
testcase_14 AC 40 ms
8,396 KB
testcase_15 AC 69 ms
8,408 KB
testcase_16 AC 40 ms
8,492 KB
testcase_17 AC 38 ms
8,036 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
mod = 10 ** 9 + 7
fact = [1] * 3333
for i in range(1, 3333):
    fact[i] = fact[i-1] * i % mod

N = int(input())
down = 0
tX = []
for _ in range(N):
    t, x = map(int, input().split())
    if t == 0:
        down += 1
        tX.append((t, x))
    else:
        tX.append((t, x-1))

tX.sort(key=itemgetter(1))

dp = [0] * (N + 1)
dp[0] = 1
for t, x in tX:
    ndp = [0] * (N + 1)
    for i in range(N):
        ndp[i+1] = dp[i] * max(0, x-i) % mod
    if t == 1:
        for i in range(N+1):
            ndp[i] += dp[i]
            ndp[i] %= mod
    dp = ndp

ans = 0
sgn = 1
for i in range(down, N+1):
    ans += sgn * dp[i] * fact[N-i] % mod
    ans %= mod
    sgn = -sgn
print(ans)
0