結果

問題 No.1884 Sequence
ユーザー gew1fw
提出日時 2025-06-12 15:50:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 136,960 KB
最終ジャッジ日時 2025-06-12 15:50:41
合計ジャッジ時間 10,970 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 3 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def get_divisors(n):
    divisors = set()
    for i in range(1, int(math.isqrt(n)) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return sorted(divisors)

def main():
    N, *rest = map(int, sys.stdin.read().split())
    A = rest[:N]
    S = [x for x in A if x > 0]
    
    if not S:
        print("Yes")
        return
    
    if len(S) == 1:
        print("Yes")
        return
    
    all_equal = True
    first = S[0]
    for x in S:
        if x != first:
            all_equal = False
            break
    if all_equal:
        print("Yes")
        return
    
    S.sort()
    diffs = []
    for i in range(1, len(S)):
        diffs.append(S[i] - S[i-1])
    
    def compute_gcd(list_numbers):
        current_gcd = list_numbers[0]
        for num in list_numbers[1:]:
            current_gcd = math.gcd(current_gcd, num)
            if current_gcd == 0:
                break
        return current_gcd
    
    g = compute_gcd(diffs)
    divisors = get_divisors(g)
    
    for d in divisors:
        if d <= 0:
            continue
        r = S[0] % d
        valid = True
        for x in S:
            if x % d != r:
                valid = False
                break
        if not valid:
            continue
        
        a = S[0]
        if a + (N-1)*d >= S[-1]:
            print("Yes")
            return
    
    print("No")

if __name__ == "__main__":
    main()
0