結果
| 問題 | No.1036 Make One With GCD 2 |
| コンテスト | |
| ユーザー |
d9et
|
| 提出日時 | 2020-04-24 22:52:12 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 903 bytes |
| 記録 | |
| コンパイル時間 | 612 ms |
| コンパイル使用メモリ | 85,900 KB |
| 実行使用メモリ | 244,952 KB |
| 最終ジャッジ日時 | 2026-05-07 11:01:20 |
| 合計ジャッジ時間 | 20,563 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 TLE * 9 |
ソースコード
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))
d9et