結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-24 03:26:45 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,599 bytes |
コンパイル時間 | 288 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 337,252 KB |
最終ジャッジ日時 | 2024-09-28 06:58:46 |
合計ジャッジ時間 | 50,431 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,449 ms
301,888 KB |
testcase_01 | AC | 1,207 ms
279,624 KB |
testcase_02 | AC | 1,236 ms
306,700 KB |
testcase_03 | AC | 355 ms
161,148 KB |
testcase_04 | AC | 620 ms
243,544 KB |
testcase_05 | AC | 38 ms
52,480 KB |
testcase_06 | AC | 38 ms
52,352 KB |
testcase_07 | AC | 428 ms
186,688 KB |
testcase_08 | AC | 357 ms
158,992 KB |
testcase_09 | AC | 1,547 ms
275,184 KB |
testcase_10 | AC | 1,466 ms
335,204 KB |
testcase_11 | AC | 1,662 ms
278,744 KB |
testcase_12 | AC | 1,498 ms
337,252 KB |
testcase_13 | AC | 1,919 ms
292,928 KB |
testcase_14 | AC | 1,909 ms
295,608 KB |
testcase_15 | AC | 1,744 ms
283,104 KB |
testcase_16 | AC | 1,759 ms
284,020 KB |
testcase_17 | AC | 1,865 ms
289,476 KB |
testcase_18 | AC | 61 ms
65,664 KB |
testcase_19 | AC | 64 ms
68,608 KB |
testcase_20 | AC | 68 ms
70,272 KB |
testcase_21 | AC | 65 ms
69,760 KB |
testcase_22 | AC | 1,877 ms
280,460 KB |
testcase_23 | AC | 1,481 ms
263,620 KB |
testcase_24 | AC | 1,891 ms
287,472 KB |
testcase_25 | AC | 1,780 ms
269,940 KB |
testcase_26 | AC | 1,778 ms
276,992 KB |
testcase_27 | AC | 38 ms
51,968 KB |
testcase_28 | AC | 38 ms
52,224 KB |
testcase_29 | AC | 38 ms
52,352 KB |
testcase_30 | AC | 38 ms
52,480 KB |
testcase_31 | AC | 47 ms
60,288 KB |
testcase_32 | AC | 46 ms
60,672 KB |
testcase_33 | AC | 37 ms
52,992 KB |
testcase_34 | AC | 48 ms
60,672 KB |
testcase_35 | AC | 37 ms
52,480 KB |
testcase_36 | AC | 37 ms
52,352 KB |
testcase_37 | AC | 37 ms
52,352 KB |
testcase_38 | AC | 1,223 ms
303,724 KB |
testcase_39 | TLE | - |
testcase_40 | AC | 1,317 ms
264,296 KB |
testcase_41 | AC | 1,955 ms
303,220 KB |
testcase_42 | TLE | - |
testcase_43 | AC | 1,773 ms
303,600 KB |
testcase_44 | AC | 1,934 ms
303,860 KB |
ソースコード
## https://yukicoder.me/problems/no/1036 def calc_gcd(A, B): """ 正の整数A, Bの最大公約数を計算する """ a = max(A, B) b = min(A, B) while a % b > 0: c = a % b a = b b = c return b class SparseTable: def __init__(self, A): self.N = len(A) k = 0 while (1 << k) < self.N: k += 1 self.max_k = k self.table = [[] for _ in range(self.N)] for k in range(self.max_k + 1): for i in range(self.N): if k == 0: self.table[i].append(A[i]) else: if i + (1 << k) - 1 < self.N: if len(self.table[i]) < k: continue if len(self.table[i + (1 << (k - 1))]) < k: continue a = self.table[i][k - 1] b = self.table[i + (1 << (k - 1))][k - 1] self.table[i].append(calc_gcd(a, b)) def query(self, l, r): length = r - l + 1 if length == 1: return self.table[l][0] k = 0 while (1 << k) < length: k += 1 k -= 1 a = self.table[l][k] b = self.table[r - ((1 << k) - 1)][k] return calc_gcd(a, b) def main(): N = int(input()) A = list(map(int, input().split())) st = SparseTable(A) answer = 0 left = 0 right = 0 a = A[0] while left < N and a == 1: answer += N - left left += 1 right += 1 if left < N: a = A[left] else: a = 0 while left < N: while right < N - 1 and calc_gcd(a, A[right + 1]) > 1: a = calc_gcd(a, A[right + 1]) right += 1 if right < N - 1: answer += N - (right + 1) if left < right: left += 1 a = st.query(left, right) else: left += 1 right += 1 a = A[left] while left < N and a == 1: answer += N - left left += 1 right += 1 if left < N: a = A[left] else: a = 0 else: if left < right: left += 1 a = st.query(left, right) else: break print(answer) if __name__ == "__main__": main()