結果
| 問題 |
No.1001 注文の多い順列
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-02-29 10:52:09 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,284 bytes |
| コンパイル時間 | 134 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 16,256 KB |
| 最終ジャッジ日時 | 2024-10-13 19:52:07 |
| 合計ジャッジ時間 | 4,452 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 1 -- * 15 |
ソースコード
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]
class mint:
def __init__(self, x):
self.__x = x % md
def __str__(self):
return str(self.__x)
def __add__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x + other)
def __sub__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x - other)
def __rsub__(self, other):
return mint(other - self.__x)
def __mul__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * other)
__radd__ = __add__
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * pow(other, md - 2, md))
def __rtruediv__(self, other):
return mint(other * pow(self.__x, md - 2, md))
def __pow__(self, power, modulo=None):
return mint(pow(self.__x, power, md))
md = 10**9+7
def main():
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] = mint(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] += (xx[i] - i + j) * pre
# 処理しない
if tt[i]: dp[i + 1][j + 1] += pre
#p2D(dp)
fac=[mint(1)]
for i in range(1,one+1):fac.append(fac[-1]*i)
ans=mint(0)
for j in range(one+1):
if (one-j)&1:ans-=dp[n][j]*fac[j]
else:ans+=dp[n][j]*fac[j]
print(ans)
main()
mkawa2