結果
問題 | No.1127 変形パスカルの三角形 |
ユーザー | Theta |
提出日時 | 2022-10-20 15:44:21 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,120 ms / 1,500 ms |
コード長 | 2,833 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-30 08:26:25 |
合計ジャッジ時間 | 21,222 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,008 KB |
testcase_01 | AC | 1,120 ms
11,008 KB |
testcase_02 | AC | 781 ms
11,008 KB |
testcase_03 | AC | 581 ms
11,008 KB |
testcase_04 | AC | 160 ms
11,008 KB |
testcase_05 | AC | 526 ms
11,008 KB |
testcase_06 | AC | 1,107 ms
10,880 KB |
testcase_07 | AC | 341 ms
11,008 KB |
testcase_08 | AC | 329 ms
11,136 KB |
testcase_09 | AC | 928 ms
11,008 KB |
testcase_10 | AC | 927 ms
10,880 KB |
testcase_11 | AC | 789 ms
10,880 KB |
testcase_12 | AC | 733 ms
11,008 KB |
testcase_13 | AC | 671 ms
11,008 KB |
testcase_14 | AC | 550 ms
11,008 KB |
testcase_15 | AC | 302 ms
11,008 KB |
testcase_16 | AC | 612 ms
11,008 KB |
testcase_17 | AC | 316 ms
11,008 KB |
testcase_18 | AC | 660 ms
11,008 KB |
testcase_19 | AC | 795 ms
11,008 KB |
testcase_20 | AC | 805 ms
11,008 KB |
testcase_21 | AC | 835 ms
11,008 KB |
testcase_22 | AC | 312 ms
11,008 KB |
testcase_23 | AC | 917 ms
11,008 KB |
testcase_24 | AC | 575 ms
11,008 KB |
testcase_25 | AC | 623 ms
11,008 KB |
testcase_26 | AC | 680 ms
10,880 KB |
testcase_27 | AC | 777 ms
11,008 KB |
testcase_28 | AC | 774 ms
10,880 KB |
testcase_29 | AC | 288 ms
11,008 KB |
testcase_30 | AC | 209 ms
11,008 KB |
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): ans_a_coeff = current_a_coeff ans_b_coeff = current_b_coeff elif k_ == (n+1-k): ans_a_coeff = current_b_coeff ans_b_coeff = current_a_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()