結果

問題 No.1884 Sequence
ユーザー ThetaTheta
提出日時 2022-10-27 11:16:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 817,016 KB
最終ジャッジ日時 2023-09-18 04:57:44
合計ジャッジ時間 4,548 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,196 KB
testcase_01 AC 16 ms
8,328 KB
testcase_02 AC 16 ms
8,184 KB
testcase_03 AC 17 ms
8,284 KB
testcase_04 AC 16 ms
8,208 KB
testcase_05 AC 16 ms
8,400 KB
testcase_06 AC 16 ms
8,196 KB
testcase_07 AC 16 ms
8,384 KB
testcase_08 AC 16 ms
8,196 KB
testcase_09 AC 16 ms
8,392 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))
    if len(A_fixed) in (0, 1):
        print("Yes")
        return
    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