結果

問題 No.1036 Make One With GCD 2
ユーザー ptotqptotq
提出日時 2020-04-25 06:27:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,798 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 93,992 KB
最終ジャッジ日時 2023-10-14 19:42:25
合計ジャッジ時間 39,169 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,381 ms
74,296 KB
testcase_01 AC 1,134 ms
44,744 KB
testcase_02 AC 1,010 ms
93,992 KB
testcase_03 AC 181 ms
11,596 KB
testcase_04 AC 297 ms
14,320 KB
testcase_05 AC 16 ms
8,336 KB
testcase_06 AC 15 ms
8,340 KB
testcase_07 AC 370 ms
23,028 KB
testcase_08 AC 300 ms
20,404 KB
testcase_09 AC 1,331 ms
64,852 KB
testcase_10 AC 1,236 ms
58,004 KB
testcase_11 AC 1,302 ms
63,864 KB
testcase_12 AC 1,189 ms
59,620 KB
testcase_13 AC 1,471 ms
71,268 KB
testcase_14 AC 1,501 ms
68,504 KB
testcase_15 AC 1,392 ms
68,096 KB
testcase_16 AC 1,402 ms
65,328 KB
testcase_17 AC 1,450 ms
66,928 KB
testcase_18 AC 18 ms
7,956 KB
testcase_19 AC 19 ms
8,536 KB
testcase_20 AC 21 ms
8,644 KB
testcase_21 AC 21 ms
8,612 KB
testcase_22 AC 1,380 ms
64,236 KB
testcase_23 AC 1,004 ms
52,788 KB
testcase_24 AC 1,446 ms
66,316 KB
testcase_25 AC 1,314 ms
61,072 KB
testcase_26 AC 1,347 ms
63,400 KB
testcase_27 AC 16 ms
8,336 KB
testcase_28 AC 16 ms
8,380 KB
testcase_29 AC 16 ms
8,392 KB
testcase_30 AC 16 ms
8,376 KB
testcase_31 AC 16 ms
8,336 KB
testcase_32 AC 16 ms
8,332 KB
testcase_33 AC 15 ms
8,264 KB
testcase_34 AC 15 ms
8,432 KB
testcase_35 AC 16 ms
8,272 KB
testcase_36 AC 15 ms
8,268 KB
testcase_37 AC 15 ms
8,480 KB
testcase_38 AC 1,020 ms
71,076 KB
testcase_39 AC 1,798 ms
70,860 KB
testcase_40 AC 1,033 ms
49,184 KB
testcase_41 AC 1,416 ms
71,016 KB
testcase_42 AC 1,429 ms
70,852 KB
testcase_43 AC 1,389 ms
70,932 KB
testcase_44 AC 1,457 ms
70,868 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