結果

問題 No.1884 Sequence
ユーザー horitaka1999
提出日時 2022-03-25 22:27:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 134,044 KB
最終ジャッジ日時 2024-10-14 06:22:59
合計ジャッジ時間 6,581 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
from math import sqrt,ceil,floor
def yaku(n):#nの約数を列挙するO(sqrt(n))
    rev = []
    for i in range(1,ceil(sqrt(n))+1):
        if n % i == 0:
            rev.append(i)
            if n //i == i:
                continue
            rev.append(n//i)
    rev = list(set(rev))
    return sorted(rev)
N = int(input())
A = list(map(int,input().split()))
cnt = 0
def diff_list(List):
    rev = []
    for i in range(len(List)):
        if i + 1 < (len(List)):
            tmp = List[i+1] - List[i]
            rev.append(tmp)
    return rev
    
newA = []
for a in A:
    if a != 0:
        newA.append(a)
    else:
        cnt += 1
def is_ok(d):
    tmp = 0
    if d == 0:
        if max(newA) - min(newA) == 0:
            return True
        else:
            return False
    for di in dis:
        tmp += di // d - 1

    if tmp <= cnt:
        return True
    else:
        return False
if len(newA) <= 1:
    print('Yes')
else:
    newA.sort()
    dis = diff_list(newA)
    g = dis[0]
    for a in dis:
        if a == 0:
            g = 0
            break
        g = gcd(g,a)
    if is_ok(g):
        print('Yes')
        exit()

    print('No')
    
0