結果

問題 No.1001 注文の多い順列
ユーザー mkawa2mkawa2
提出日時 2020-02-29 10:59:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,430 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 222,720 KB
最終ジャッジ日時 2024-04-21 21:31:12
合計ジャッジ時間 12,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 32 ms
10,880 KB
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 31 ms
10,880 KB
testcase_14 AC 36 ms
11,136 KB
testcase_15 AC 38 ms
11,776 KB
testcase_16 AC 34 ms
11,136 KB
testcase_17 AC 34 ms
11,136 KB
testcase_18 AC 783 ms
93,568 KB
testcase_19 AC 756 ms
90,240 KB
testcase_20 AC 446 ms
58,880 KB
testcase_21 AC 417 ms
55,936 KB
testcase_22 AC 975 ms
118,912 KB
testcase_23 AC 951 ms
113,408 KB
testcase_24 AC 243 ms
46,080 KB
testcase_25 AC 903 ms
109,952 KB
testcase_26 AC 652 ms
101,376 KB
testcase_27 AC 590 ms
96,384 KB
testcase_28 AC 517 ms
89,472 KB
testcase_29 AC 210 ms
33,024 KB
testcase_30 AC 260 ms
38,656 KB
testcase_31 AC 333 ms
47,104 KB
testcase_32 AC 40 ms
11,392 KB
testcase_33 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    md = 10 ** 9 + 7
    n = II()
    xt = []
    one = 0
    for _ in range(n):
        t, x = MI()
        if t:
            x -= 1
            one += 1
        xt.append((x, t))
    tt = []
    xx = []
    for x, t in sorted(xt):
        tt.append(t)
        xx.append(x)
    #print(tt)
    #print(xx)
    # dp[i][j]...i個まで見たとき、t=1の処理をj個飛ばしたときの場合の数
    dp = [[0] * (one + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    dpi=dp[0]
    for i in range(n):
        dpi1=dp[i+1]
        for j in range(min(i, one) + 1):
            pre = dpi[j]
            if pre == 0: continue
            # 処理する
            dpi1[j] = (dpi1[j]+(xx[i] - i + j) * pre)%md
            # 処理しない
            if tt[i]: dpi1[j + 1] = (pre+dpi1[j + 1])%md
        dpi=dpi1
    #p2D(dp)
    fac=[1]
    for i in range(1,one+1):fac.append(fac[-1]*i%md)
    ans=0
    for j in range(one+1):
        if (one-j)&1:ans-=dp[n][j]*fac[j]
        else:ans+=dp[n][j]*fac[j]
        ans%=md
    print(ans)

main()
0