結果
問題 | No.1001 注文の多い順列 |
ユーザー | mkawa2 |
提出日時 | 2020-02-29 10:52:44 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,253 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 523,776 KB |
最終ジャッジ日時 | 2024-10-13 19:52:21 |
合計ジャッジ時間 | 10,985 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,864 KB |
testcase_01 | AC | 38 ms
52,352 KB |
testcase_02 | AC | 38 ms
52,224 KB |
testcase_03 | AC | 37 ms
52,864 KB |
testcase_04 | AC | 38 ms
52,224 KB |
testcase_05 | AC | 39 ms
52,224 KB |
testcase_06 | AC | 37 ms
51,968 KB |
testcase_07 | AC | 39 ms
52,352 KB |
testcase_08 | AC | 38 ms
52,096 KB |
testcase_09 | AC | 39 ms
52,480 KB |
testcase_10 | AC | 39 ms
52,608 KB |
testcase_11 | AC | 38 ms
52,480 KB |
testcase_12 | AC | 38 ms
52,096 KB |
testcase_13 | AC | 60 ms
65,152 KB |
testcase_14 | AC | 65 ms
67,968 KB |
testcase_15 | AC | 66 ms
70,528 KB |
testcase_16 | AC | 61 ms
67,456 KB |
testcase_17 | AC | 59 ms
66,560 KB |
testcase_18 | AC | 492 ms
284,032 KB |
testcase_19 | AC | 398 ms
259,456 KB |
testcase_20 | AC | 271 ms
188,672 KB |
testcase_21 | AC | 249 ms
172,032 KB |
testcase_22 | AC | 603 ms
323,712 KB |
testcase_23 | AC | 565 ms
318,080 KB |
testcase_24 | AC | 566 ms
317,056 KB |
testcase_25 | AC | 536 ms
311,680 KB |
testcase_26 | AC | 1,192 ms
501,760 KB |
testcase_27 | AC | 1,160 ms
496,000 KB |
testcase_28 | AC | 1,054 ms
480,256 KB |
testcase_29 | AC | 152 ms
114,688 KB |
testcase_30 | AC | 177 ms
129,408 KB |
testcase_31 | AC | 200 ms
148,224 KB |
testcase_32 | AC | 70 ms
72,576 KB |
testcase_33 | MLE | - |
ソースコード
import sys 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()