結果

問題 No.1884 Sequence
ユーザー ThetaTheta
提出日時 2022-10-27 11:14:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 817,144 KB
最終ジャッジ日時 2023-09-18 04:55:02
合計ジャッジ時間 6,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,192 KB
testcase_01 AC 16 ms
8,296 KB
testcase_02 AC 16 ms
8,156 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 16 ms
8,220 KB
testcase_06 AC 15 ms
8,340 KB
testcase_07 AC 15 ms
8,348 KB
testcase_08 AC 16 ms
8,220 KB
testcase_09 AC 15 ms
8,228 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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