結果

問題 No.1036 Make One With GCD 2
ユーザー d9et
提出日時 2020-04-24 22:52:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 903 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 244,560 KB
最終ジャッジ日時 2024-11-07 03:00:15
合計ジャッジ時間 20,695 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 9 TLE * 5 -- * 27
権限があれば一括ダウンロードができます

ソースコード

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