結果

問題 No.1001 注文の多い順列
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-05 22:27:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 147,328 KB
最終ジャッジ日時 2024-05-05 10:44:31
合計ジャッジ時間 5,978 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
51,968 KB
testcase_01 AC 35 ms
51,968 KB
testcase_02 AC 36 ms
51,712 KB
testcase_03 AC 36 ms
52,352 KB
testcase_04 AC 35 ms
51,712 KB
testcase_05 AC 36 ms
52,224 KB
testcase_06 AC 35 ms
52,480 KB
testcase_07 AC 36 ms
52,224 KB
testcase_08 AC 36 ms
52,480 KB
testcase_09 AC 35 ms
52,480 KB
testcase_10 AC 35 ms
52,352 KB
testcase_11 AC 36 ms
52,224 KB
testcase_12 AC 37 ms
52,096 KB
testcase_13 AC 53 ms
64,384 KB
testcase_14 AC 54 ms
65,664 KB
testcase_15 AC 59 ms
67,200 KB
testcase_16 AC 56 ms
65,024 KB
testcase_17 AC 54 ms
64,768 KB
testcase_18 AC 238 ms
128,384 KB
testcase_19 AC 231 ms
129,024 KB
testcase_20 AC 175 ms
105,856 KB
testcase_21 AC 160 ms
105,856 KB
testcase_22 AC 278 ms
147,328 KB
testcase_23 AC 277 ms
147,276 KB
testcase_24 AC 276 ms
146,560 KB
testcase_25 AC 272 ms
145,536 KB
testcase_26 AC 165 ms
127,744 KB
testcase_27 AC 199 ms
145,408 KB
testcase_28 AC 215 ms
146,048 KB
testcase_29 AC 232 ms
146,560 KB
testcase_30 AC 243 ms
143,488 KB
testcase_31 AC 252 ms
146,944 KB
testcase_32 AC 210 ms
147,200 KB
testcase_33 AC 159 ms
128,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
X = [[] for i in range(2)]
for _ in range(n):
    t,x = map(int,input().split())
    X[t].append(x-1)

mod = 10**9+7
A = sorted(X[0])
B = sorted(X[1])

la = len(A)
lb = len(B)
dp = [[0]*(n+1) for i in range(n+1)]
dp[0][0] = 1

for i in range(n):
    c0 = 0
    c1 = 0
    for x in A:
        if i <= x:
            c0 += 1
    for x in B:
        if i >= x:
            c1 += 1
    
    for x in range(la+1):
        y = i-x
        if y > lb or y < 0:
            continue
        
        if x < la:
            dp[x+1][y] += dp[x][y]*(c0-(la-x-1))%mod
            dp[x+1][y] %= mod
        if y < lb:
            dp[x][y+1] += dp[x][y]*(c1-y)%mod
            dp[x][y+1] %= mod

ans = 0
for i in range(n+1):
    ans += dp[i][n-i]
    ans %= mod
print(ans)        
0