結果

問題 No.1036 Make One With GCD 2
ユーザー d9etd9et
提出日時 2020-04-24 23:01:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,171 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 260,856 KB
最終ジャッジ日時 2024-04-24 18:13:38
合計ジャッジ時間 12,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd
n = int(input())
a = list(map(int,input().split()))
table = [[0 for i in range(n)] for j in range(20)]
def judge(ls):
    ret = 0
    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
for i in range(20):
    if i == 0:
        for j in range(n):
            if a[j] == 1:
                table[i][j] = 1
            else:
                table[i][j] = 0
        continue
    for j in range(n):
        if j*2**i >= n:
            if j == 1:
                print(table[i][0])
                exit()
        table[i][j] = table[i-1][j//2]+table[i-1][j//2+1]+judge(a[j*2**i:(j+1)*2**i])
0