結果

問題 No.1001 注文の多い順列
ユーザー tktk_snsntktk_snsn
提出日時 2022-02-15 19:54:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 78,192 KB
最終ジャッジ日時 2023-09-11 17:02:24
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,924 KB
testcase_01 AC 81 ms
75,720 KB
testcase_02 AC 86 ms
75,928 KB
testcase_03 AC 81 ms
75,808 KB
testcase_04 AC 80 ms
75,800 KB
testcase_05 AC 81 ms
75,784 KB
testcase_06 AC 80 ms
75,752 KB
testcase_07 AC 81 ms
75,924 KB
testcase_08 AC 82 ms
75,760 KB
testcase_09 AC 82 ms
75,856 KB
testcase_10 AC 82 ms
75,780 KB
testcase_11 AC 83 ms
76,028 KB
testcase_12 AC 81 ms
75,784 KB
testcase_13 AC 90 ms
76,032 KB
testcase_14 AC 92 ms
76,028 KB
testcase_15 AC 94 ms
76,424 KB
testcase_16 AC 91 ms
76,196 KB
testcase_17 AC 92 ms
76,104 KB
testcase_18 AC 203 ms
77,944 KB
testcase_19 AC 204 ms
78,168 KB
testcase_20 AC 170 ms
77,700 KB
testcase_21 AC 168 ms
78,164 KB
testcase_22 AC 229 ms
77,896 KB
testcase_23 AC 215 ms
77,784 KB
testcase_24 AC 214 ms
78,092 KB
testcase_25 AC 221 ms
77,868 KB
testcase_26 AC 195 ms
77,872 KB
testcase_27 AC 197 ms
78,192 KB
testcase_28 AC 199 ms
77,872 KB
testcase_29 AC 184 ms
78,036 KB
testcase_30 AC 185 ms
77,932 KB
testcase_31 AC 190 ms
77,960 KB
testcase_32 AC 196 ms
77,684 KB
testcase_33 AC 236 ms
77,836 KB
権限があれば一括ダウンロードができます

ソースコード

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