結果

問題 No.1036 Make One With GCD 2
ユーザー d9etd9et
提出日時 2020-04-24 22:52:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 903 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 244,680 KB
最終ジャッジ日時 2024-04-24 18:11:40
合計ジャッジ時間 19,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 774 ms
244,680 KB
testcase_01 AC 1,160 ms
211,516 KB
testcase_02 AC 858 ms
243,760 KB
testcase_03 AC 266 ms
106,688 KB
testcase_04 AC 353 ms
138,552 KB
testcase_05 AC 38 ms
52,608 KB
testcase_06 AC 37 ms
52,224 KB
testcase_07 AC 904 ms
125,768 KB
testcase_08 AC 717 ms
106,360 KB
testcase_09 TLE -
testcase_10 AC 1,896 ms
197,424 KB
testcase_11 TLE -
testcase_12 AC 1,860 ms
203,728 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd
n = int(input())
a = list(map(int,input().split()))
def judge(ls):
    l = len(ls)
    if l == 1:
        if ls[0] == 1:
            return 1
        else:
            return 0
    ret = judge(ls[:l//2])+judge(ls[l//2:])
    stack1 = [ls[l//2-1]]
    stack2 = [ls[l//2]]
    for i in range(l//2):
        if l//2-i-2 >= 0:
            stack1.append(gcd(ls[l//2-i-2],stack1[-1]))
        if i+l//2+1 <= l-1:
            stack2.append(gcd(ls[i+l//2+1],stack2[-1]))
    s1l = len(stack1)
    s2l = len(stack2)
    lf = s1l-1
    r = 0
    for r in range(s2l):
        while lf >= 0 and gcd(stack1[lf],stack2[r]) == 1:
            ret += s2l-r
            if lf > 0:
                lf -= 1
            else:
                break
        if gcd(stack1[lf],stack2[r]) == 1:
            break
    return ret
print(judge(a))
            
            
0