結果

問題 No.1036 Make One With GCD 2
ユーザー d9etd9et
提出日時 2020-04-24 23:02:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 267,512 KB
最終ジャッジ日時 2024-04-24 18:15:03
合計ジャッジ時間 20,301 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 884 ms
259,648 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 WA -
testcase_11 TLE -
testcase_12 TLE -
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()))
table = [[0 for i in range(n)] for j in range(20)]
def judge(ls):
    l = len(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()
            else:
                break
        table[i][j] = table[i-1][j//2]+table[i-1][j//2+1]+judge(a[j*2**i:(j+1)*2**i])
0