結果

問題 No.1001 注文の多い順列
ユーザー shotoyooshotoyoo
提出日時 2021-05-28 00:47:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 77,708 KB
最終ジャッジ日時 2024-04-24 10:38:38
合計ジャッジ時間 4,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 40 ms
52,736 KB
testcase_02 AC 39 ms
52,480 KB
testcase_03 AC 39 ms
52,480 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 40 ms
52,096 KB
testcase_06 AC 41 ms
52,096 KB
testcase_07 AC 39 ms
52,608 KB
testcase_08 AC 39 ms
52,480 KB
testcase_09 AC 39 ms
52,608 KB
testcase_10 AC 41 ms
52,480 KB
testcase_11 AC 39 ms
52,736 KB
testcase_12 AC 40 ms
52,224 KB
testcase_13 AC 49 ms
62,208 KB
testcase_14 AC 51 ms
62,208 KB
testcase_15 AC 53 ms
63,104 KB
testcase_16 AC 51 ms
62,336 KB
testcase_17 AC 50 ms
62,336 KB
testcase_18 AC 137 ms
76,928 KB
testcase_19 AC 140 ms
77,056 KB
testcase_20 AC 114 ms
76,672 KB
testcase_21 AC 114 ms
76,800 KB
testcase_22 AC 155 ms
76,928 KB
testcase_23 AC 152 ms
76,800 KB
testcase_24 AC 152 ms
76,624 KB
testcase_25 AC 154 ms
77,328 KB
testcase_26 AC 115 ms
76,800 KB
testcase_27 AC 121 ms
76,628 KB
testcase_28 AC 126 ms
76,544 KB
testcase_29 AC 191 ms
77,312 KB
testcase_30 AC 190 ms
77,440 KB
testcase_31 AC 190 ms
77,708 KB
testcase_32 AC 107 ms
76,492 KB
testcase_33 AC 146 ms
76,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n = int(input())
l = [0]*n
r = [0]*n
ll = 0
for i in range(n):
    t,x = list(map(int, input().split()))
    x -= 1
    if t==1:
        r[x] += 1
    else:
        l[x] += 1
        ll += 1
dp = [0]*(n+1)
dp[0] = 1
M = 10**9+7
vl = vr = 0
for i in range(n):
    for _ in range(r[i]):
        ndp = dp[:]
        for j in range(n):
            num = i-(vl+j)
            if num<=0:
                continue
            ndp[j+1] += dp[j]*num%M
            ndp[j+1] %= M
        dp = ndp
        vr += 1
    for _ in range(l[i]):
        ndp = [0]*(n+1)
        for j in range(n):
            num = i+1-(vl+j)
            if num<=0:
                continue
            ndp[j] += dp[j]*num%M
            ndp[j] %= M
        vl += 1
        dp = ndp
g1 = [1]
for i in range(n+10):
    g1.append(g1[-1]*(i+1)%M)
ans = 0
s = -1
for j in range(n+1):
    s *= -1
    if dp[j]==0:
        continue
    ans += s * (dp[j] * g1[vr-j] % M)
    ans %= M
print(ans%M)
0