結果

問題 No.1001 注文の多い順列
ユーザー maspy
提出日時 2020-04-15 12:26:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 731 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 44,756 KB
最終ジャッジ日時 2024-10-01 18:41:56
合計ジャッジ時間 22,740 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

N = int(readline())
TX = np.array(read().split(), np.int32)
T = TX[::2]
X = TX[1::2]
X[T == 1] -= 1
ind = X.argsort()
X = X[ind].tolist()
T = T[ind].tolist()

dp = np.zeros(1, np.int64)
dp[0] = 1
for t, x in zip(T, X):
    newdp = np.zeros(len(dp) + 1, np.int64)
    newdp[1:] = dp * np.arange(x, x - len(dp), -1)
    newdp[x + 1:] = 0
    if t == 1:
        newdp[:-1] += dp
    newdp %= MOD
    dp = newdp

fact = 1
for i in range(1, N + 1):
    fact *= i
    fact %= MOD
    dp[N - i] *= fact

n = (N - sum(T)) & 1

dp[n ^ 1::2] *= - 1
answer = dp.sum() % MOD
print(answer)
0