結果
問題 | No.2111 Sum of Diff |
ユーザー | Theta |
提出日時 | 2022-10-31 14:23:27 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,126 ms / 2,000 ms |
コード長 | 2,297 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 61,796 KB |
最終ジャッジ日時 | 2024-07-08 03:38:38 |
合計ジャッジ時間 | 13,712 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 1,126 ms
61,696 KB |
testcase_03 | AC | 760 ms
43,340 KB |
testcase_04 | AC | 175 ms
17,412 KB |
testcase_05 | AC | 1,108 ms
61,796 KB |
testcase_06 | AC | 1,121 ms
61,680 KB |
testcase_07 | AC | 286 ms
23,584 KB |
testcase_08 | AC | 387 ms
26,780 KB |
testcase_09 | AC | 97 ms
13,952 KB |
testcase_10 | AC | 123 ms
14,904 KB |
testcase_11 | AC | 540 ms
35,980 KB |
testcase_12 | AC | 514 ms
35,988 KB |
testcase_13 | AC | 341 ms
25,704 KB |
testcase_14 | AC | 897 ms
48,020 KB |
testcase_15 | AC | 1,083 ms
61,320 KB |
testcase_16 | AC | 455 ms
29,400 KB |
testcase_17 | AC | 1,106 ms
61,576 KB |
testcase_18 | AC | 350 ms
26,032 KB |
testcase_19 | AC | 823 ms
45,760 KB |
testcase_20 | AC | 1,104 ms
61,572 KB |
testcase_21 | AC | 46 ms
11,648 KB |
ソースコード
from functools import lru_cache class Modint: MOD = 998244353 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)) @lru_cache def power_of_two(power: int | Modint) -> Modint: if power == 0: return Modint(1) return Modint(2) * power_of_two(power-1) def main(): N = int(input()) A = list(map(int, input().split())) power_of_two_dict = {0: Modint(1)} for idx in range(1, N): power_of_two_dict[idx] = power_of_two_dict[idx-1]*2 sum_ = Modint(0) for idx, value in enumerate(A): start_patterns = power_of_two_dict[N - 1 - idx] - 1 end_patterns = power_of_two_dict[idx] - 1 sum_ += value * (start_patterns - end_patterns) print(sum_) if __name__ == "__main__": main()