結果
問題 | No.1127 変形パスカルの三角形 |
ユーザー | Theta |
提出日時 | 2022-10-20 15:40:07 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,738 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-30 08:23:26 |
合計ジャッジ時間 | 21,746 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,008 KB |
testcase_01 | AC | 1,105 ms
11,008 KB |
testcase_02 | WA | - |
testcase_03 | AC | 580 ms
11,136 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 331 ms
11,008 KB |
testcase_09 | AC | 915 ms
11,008 KB |
testcase_10 | AC | 940 ms
11,136 KB |
testcase_11 | AC | 789 ms
11,008 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 619 ms
11,008 KB |
testcase_17 | WA | - |
testcase_18 | AC | 672 ms
11,008 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 314 ms
11,008 KB |
testcase_23 | AC | 921 ms
11,008 KB |
testcase_24 | AC | 586 ms
11,008 KB |
testcase_25 | WA | - |
testcase_26 | AC | 681 ms
11,008 KB |
testcase_27 | AC | 788 ms
11,008 KB |
testcase_28 | AC | 766 ms
11,008 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 826 ms
11,008 KB |
ソースコード
from itertools import pairwise from math import ceil class Modint: MOD = int(1e9+7) def __init__(self, value: int) -> None: self.num = int(value) % self.MOD def __str__(self) -> str: return str(self.num) __repr__ = __str__ def __add__(self, __x): if isinstance(__x, Modint): return Modint((self.num + __x.num)) return Modint(self.num + __x) def __sub__(self, __x): if isinstance(__x, Modint): return Modint(self.num - __x.num) return Modint(self.num - __x) def __mul__(self, __x): if isinstance(__x, Modint): return Modint(self.num * __x.num) return Modint(self.num * __x) __radd__ = __add__ __rmul__ = __mul__ def __rsub__(self, __x): if isinstance(__x, Modint): return Modint(__x.num - self.num) return Modint(__x - self.num) def __pow__(self, __x): if isinstance(__x, Modint): return Modint(pow(self.num, __x.num, self.MOD)) return Modint(pow(self.num, __x, self.MOD)) def __rpow__(self, __x): if isinstance(__x, Modint): return Modint(pow(__x.num, self.num, self.MOD)) return Modint(pow(__x, self.num, self.MOD)) def __truediv__(self, __x): if isinstance(__x, Modint): return Modint(self.num * pow(__x.num, self.MOD - 2, self.MOD)) return Modint(self.num * pow(__x, self.MOD - 2, self.MOD)) def __rtruediv__(self, __x): if isinstance(__x, Modint): return Modint(__x.num * pow(self.num, self.MOD - 2, self.MOD)) return Modint(__x * pow(self.num, self.MOD - 2, self.MOD)) def main(): a, b = map(int, input().split()) n, k = map(int, input().split()) current_a_coeff = Modint(1) current_b_coeff = Modint(0) ans_a_coeff = 1 ans_b_coeff = 0 coeff_two = Modint(1) coeff_ab = Modint(0) for k_ in range(1, (n+2)//2): current_b_coeff = current_a_coeff current_a_coeff = current_a_coeff * (n-k_)/k_ if k_ == (k-1) or k_ == (n+1-k): ans_a_coeff = current_a_coeff ans_b_coeff = current_b_coeff # current.append([current[-1][0]*(n-k_)//k_, current[-1][0]]) coeff_two += current_a_coeff ** 2 coeff_two += current_b_coeff ** 2 coeff_ab += 4 * current_a_coeff * current_b_coeff if n % 2 == 0: coeff_two -= current_a_coeff ** 2 coeff_ab -= 2 * current_a_coeff * current_b_coeff print(Modint(a) * ans_a_coeff + Modint(b) * ans_b_coeff) print(coeff_two * Modint(a)**2 + coeff_two * Modint(b) ** 2 + coeff_ab * Modint(a) * Modint(b)) if __name__ == "__main__": main()