結果

問題 No.1036 Make One With GCD 2
ユーザー rkyiolklorkyiolklo
提出日時 2020-05-12 20:28:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,799 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 985 ms
コンパイル使用メモリ 10,680 KB
実行使用メモリ 93,992 KB
最終ジャッジ日時 2023-10-11 21:57:42
合計ジャッジ時間 38,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,396 ms
74,200 KB
testcase_01 AC 1,139 ms
44,516 KB
testcase_02 AC 1,039 ms
93,992 KB
testcase_03 AC 174 ms
11,532 KB
testcase_04 AC 298 ms
14,116 KB
testcase_05 AC 16 ms
7,932 KB
testcase_06 AC 17 ms
8,276 KB
testcase_07 AC 379 ms
23,028 KB
testcase_08 AC 303 ms
20,520 KB
testcase_09 AC 1,294 ms
62,648 KB
testcase_10 AC 1,188 ms
57,988 KB
testcase_11 AC 1,288 ms
63,788 KB
testcase_12 AC 1,206 ms
59,492 KB
testcase_13 AC 1,462 ms
71,048 KB
testcase_14 AC 1,502 ms
68,524 KB
testcase_15 AC 1,422 ms
68,240 KB
testcase_16 AC 1,409 ms
65,288 KB
testcase_17 AC 1,453 ms
67,080 KB
testcase_18 AC 19 ms
8,044 KB
testcase_19 AC 20 ms
8,536 KB
testcase_20 AC 24 ms
8,632 KB
testcase_21 AC 23 ms
8,528 KB
testcase_22 AC 1,399 ms
64,080 KB
testcase_23 AC 1,021 ms
52,588 KB
testcase_24 AC 1,432 ms
66,172 KB
testcase_25 AC 1,342 ms
61,032 KB
testcase_26 AC 1,382 ms
63,400 KB
testcase_27 AC 17 ms
8,240 KB
testcase_28 AC 17 ms
8,356 KB
testcase_29 AC 16 ms
8,296 KB
testcase_30 AC 17 ms
8,388 KB
testcase_31 AC 17 ms
8,408 KB
testcase_32 AC 17 ms
8,384 KB
testcase_33 AC 16 ms
8,256 KB
testcase_34 AC 17 ms
8,292 KB
testcase_35 AC 16 ms
8,212 KB
testcase_36 AC 17 ms
8,344 KB
testcase_37 AC 17 ms
8,284 KB
testcase_38 AC 1,008 ms
70,944 KB
testcase_39 AC 1,799 ms
71,008 KB
testcase_40 AC 1,019 ms
49,172 KB
testcase_41 AC 1,441 ms
70,864 KB
testcase_42 AC 1,488 ms
70,836 KB
testcase_43 AC 1,407 ms
71,080 KB
testcase_44 AC 1,469 ms
70,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
readline = sys.stdin.readline


def push(a, x):
    a.append((x, gcd(x, a[-1][1])))


def pop(front, back):
    if len(back) == 1:
        for _ in range(len(front)-1):
            back.append(gcd(front.pop()[0], back[-1]))
    back.pop()


def fold(front, back):
    return gcd(front[-1][1], back[-1])


N = int(input())
a = list(map(int, input().split()))

r = 0
ans = 0
front, back = [(0, 0)], [0]

for l in range(N):
    while r < N and gcd(fold(front, back), a[r]) != 1:
        push(front, a[r])
        r += 1

    ans += N - r

    if l < r:
        pop(front, back)
    else:
        r += 1

print(ans)
0