結果

問題 No.1884 Sequence
コンテスト
ユーザー Theta
提出日時 2022-10-27 11:14:43
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
RE  
実行時間 -
コード長 1,088 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,037 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 1,311,392 KB
最終ジャッジ日時 2026-03-26 03:59:14
合計ジャッジ時間 8,470 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 RE * 7 TLE * 8 MLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import pairwise


def gcd(*numbers: int) -> int:
    if len(numbers) == 1:
        return numbers[0]
    if len(numbers) == 2:
        a, b = numbers
        if a < b:
            a, b = b, a

        while True:

            if a % b == 0:
                return b
            a, b = b, a % b

    first_gcd = gcd(*numbers[:2])
    return gcd(first_gcd, *numbers[2:])


def is_positive(num: int) -> bool:
    return num > 0


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_fixed = list(filter(is_positive, A))
    A_fixed.sort()
    A_diff = [a_elm2 - a_elm1 for a_elm1, a_elm2 in pairwise(A_fixed)]

    if (diff_zero_num := A_diff.count(0)):
        if diff_zero_num == len(A_diff):
            print("Yes")
        else:
            print("No")
        return

    A_diff_gcd = gcd(*A_diff)
    A_diff_interpolated_num = list(map(
        lambda num: num // A_diff_gcd - 1, A_diff))

    if sum(A_diff_interpolated_num) <= len(A) - len(A_fixed):
        print("Yes")
    else:
        print("No")


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