結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | 草苺奶昔 |
提出日時 | 2023-03-10 18:28:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 767 ms / 2,000 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,032 KB |
実行使用メモリ | 253,808 KB |
最終ジャッジ日時 | 2024-09-18 03:20:40 |
合計ジャッジ時間 | 19,543 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 305 ms
177,436 KB |
testcase_01 | AC | 240 ms
158,760 KB |
testcase_02 | AC | 407 ms
251,792 KB |
testcase_03 | AC | 96 ms
96,944 KB |
testcase_04 | AC | 115 ms
119,896 KB |
testcase_05 | AC | 55 ms
67,572 KB |
testcase_06 | AC | 56 ms
67,412 KB |
testcase_07 | AC | 156 ms
111,516 KB |
testcase_08 | AC | 139 ms
104,296 KB |
testcase_09 | AC | 580 ms
162,788 KB |
testcase_10 | AC | 596 ms
149,428 KB |
testcase_11 | AC | 446 ms
162,908 KB |
testcase_12 | AC | 404 ms
149,448 KB |
testcase_13 | AC | 567 ms
159,796 KB |
testcase_14 | AC | 611 ms
164,564 KB |
testcase_15 | AC | 728 ms
183,752 KB |
testcase_16 | AC | 563 ms
184,528 KB |
testcase_17 | AC | 767 ms
187,080 KB |
testcase_18 | AC | 71 ms
74,588 KB |
testcase_19 | AC | 75 ms
74,852 KB |
testcase_20 | AC | 75 ms
75,452 KB |
testcase_21 | AC | 71 ms
75,388 KB |
testcase_22 | AC | 701 ms
182,892 KB |
testcase_23 | AC | 553 ms
142,212 KB |
testcase_24 | AC | 570 ms
186,456 KB |
testcase_25 | AC | 553 ms
171,780 KB |
testcase_26 | AC | 721 ms
181,692 KB |
testcase_27 | AC | 60 ms
66,688 KB |
testcase_28 | AC | 60 ms
66,688 KB |
testcase_29 | AC | 59 ms
66,048 KB |
testcase_30 | AC | 61 ms
66,560 KB |
testcase_31 | AC | 62 ms
67,328 KB |
testcase_32 | AC | 62 ms
67,200 KB |
testcase_33 | AC | 60 ms
66,944 KB |
testcase_34 | AC | 61 ms
66,944 KB |
testcase_35 | AC | 60 ms
66,176 KB |
testcase_36 | AC | 61 ms
66,304 KB |
testcase_37 | AC | 61 ms
66,432 KB |
testcase_38 | AC | 360 ms
253,808 KB |
testcase_39 | AC | 342 ms
174,480 KB |
testcase_40 | AC | 465 ms
141,812 KB |
testcase_41 | AC | 373 ms
174,304 KB |
testcase_42 | AC | 361 ms
174,052 KB |
testcase_43 | AC | 388 ms
215,656 KB |
testcase_44 | AC | 364 ms
183,644 KB |
ソースコード
from math import gcd from typing import Callable, Generic, List, TypeVar E = TypeVar("E") class SlidingWindowAggregation(Generic[E]): """SlidingWindowAggregation Api: 1. append value to tail,O(1). 2. pop value from head,O(1). 3. query aggregated value in window,O(1). """ __slots__ = ["_stack0", "_stack1", "_stack2", "_stack3", "_e0", "_e1", "_size", "_op", "_e"] def __init__(self, e: Callable[[], E], op: Callable[[E, E], E]): """ Args: e: unit element op: merge function """ self._stack0 = [] self._stack1 = [] self._stack2 = [] self._stack3 = [] self._e = e self._e0 = e() self._e1 = e() self._size = 0 self._op = op def append(self, value: E) -> None: if not self._stack0: self._push0(value) self._transfer() else: self._push1(value) self._size += 1 def popleft(self) -> None: if not self._size: return if not self._stack0: self._transfer() self._stack0.pop() self._stack2.pop() self._e0 = self._stack2[-1] if self._stack2 else self._e() self._size -= 1 def query(self) -> E: return self._op(self._e0, self._e1) def _push0(self, value): self._stack0.append(value) self._e0 = self._op(value, self._e0) self._stack2.append(self._e0) def _push1(self, value): self._stack1.append(value) self._e1 = self._op(self._e1, value) self._stack3.append(self._e1) def _transfer(self): while self._stack1: self._push0(self._stack1.pop()) while self._stack3: self._stack3.pop() self._e1 = self._e() @property def size(self): return self._size if __name__ == "__main__": n = int(input()) nums = list(map(int, input().split())) S = SlidingWindowAggregation(lambda: 0, gcd) res = 0 right = 0 for left in range(n): right = max(right, left) while right < n and gcd(S.query(), nums[right]) != 1: S.append(nums[right]) right += 1 res += n - right S.popleft() print(res)