結果
問題 | No.2111 Sum of Diff |
ユーザー | Mr.Haruta |
提出日時 | 2022-11-17 08:25:16 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,176 ms / 2,000 ms |
コード長 | 2,296 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 61,660 KB |
最終ジャッジ日時 | 2024-09-18 22:02:19 |
合計ジャッジ時間 | 15,253 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
11,008 KB |
testcase_01 | AC | 32 ms
11,008 KB |
testcase_02 | AC | 1,171 ms
61,660 KB |
testcase_03 | AC | 787 ms
43,468 KB |
testcase_04 | AC | 177 ms
17,404 KB |
testcase_05 | AC | 1,176 ms
61,656 KB |
testcase_06 | AC | 1,132 ms
61,532 KB |
testcase_07 | AC | 292 ms
23,404 KB |
testcase_08 | AC | 391 ms
26,892 KB |
testcase_09 | AC | 98 ms
13,952 KB |
testcase_10 | AC | 126 ms
14,780 KB |
testcase_11 | AC | 551 ms
35,920 KB |
testcase_12 | AC | 535 ms
35,896 KB |
testcase_13 | AC | 354 ms
25,452 KB |
testcase_14 | AC | 914 ms
48,024 KB |
testcase_15 | AC | 1,104 ms
61,276 KB |
testcase_16 | AC | 467 ms
29,400 KB |
testcase_17 | AC | 1,142 ms
61,524 KB |
testcase_18 | AC | 359 ms
26,036 KB |
testcase_19 | AC | 851 ms
45,504 KB |
testcase_20 | AC | 1,138 ms
61,536 KB |
testcase_21 | AC | 49 ms
11,776 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()