結果

問題 No.1001 注文の多い順列
ユーザー mkawa2mkawa2
提出日時 2020-02-29 10:56:47
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 219,436 KB
最終ジャッジ日時 2023-08-03 22:43:24
合計ジャッジ時間 12,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,992 KB
testcase_01 AC 17 ms
8,024 KB
testcase_02 AC 17 ms
7,972 KB
testcase_03 AC 17 ms
7,976 KB
testcase_04 AC 16 ms
8,052 KB
testcase_05 AC 17 ms
8,164 KB
testcase_06 AC 17 ms
8,060 KB
testcase_07 AC 16 ms
7,992 KB
testcase_08 AC 17 ms
8,096 KB
testcase_09 AC 16 ms
8,024 KB
testcase_10 AC 16 ms
8,052 KB
testcase_11 AC 17 ms
8,052 KB
testcase_12 AC 17 ms
8,040 KB
testcase_13 AC 17 ms
8,100 KB
testcase_14 AC 21 ms
8,456 KB
testcase_15 AC 25 ms
9,032 KB
testcase_16 AC 20 ms
8,460 KB
testcase_17 AC 20 ms
8,460 KB
testcase_18 AC 791 ms
91,088 KB
testcase_19 AC 774 ms
87,620 KB
testcase_20 AC 464 ms
56,312 KB
testcase_21 AC 432 ms
53,444 KB
testcase_22 AC 1,038 ms
116,248 KB
testcase_23 AC 991 ms
110,884 KB
testcase_24 AC 238 ms
43,624 KB
testcase_25 AC 937 ms
107,196 KB
testcase_26 AC 663 ms
98,776 KB
testcase_27 AC 603 ms
93,672 KB
testcase_28 AC 529 ms
86,940 KB
testcase_29 AC 203 ms
30,372 KB
testcase_30 AC 253 ms
35,856 KB
testcase_31 AC 326 ms
44,588 KB
testcase_32 AC 23 ms
8,840 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
    for i in range(n):
        for j in range(min(i, one) + 1):
            pre = dp[i][j]
            if pre == 0: continue
            # 処理する
            dp[i + 1][j] = (dp[i + 1][j]+(xx[i] - i + j) * pre)%md
            # 処理しない
            if tt[i]: dp[i + 1][j + 1] = (pre+dp[i + 1][j + 1])%md
    #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