結果
| 問題 |
No.1884 Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-27 11:16:46 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,155 bytes |
| コンパイル時間 | 78 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 827,240 KB |
| 最終ジャッジ日時 | 2024-07-04 21:30:46 |
| 合計ジャッジ時間 | 5,021 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 MLE * 1 -- * 32 |
ソースコード
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()