結果
問題 | No.1884 Sequence |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:47:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,716 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,492 KB |
実行使用メモリ | 149,376 KB |
最終ジャッジ日時 | 2025-03-31 17:48:41 |
合計ジャッジ時間 | 8,100 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 WA * 5 |
ソースコード
import sys import math def is_possible(): n, *rest = list(map(int, sys.stdin.read().split())) A = rest[:n] S = [x for x in A if x != 0] k = len(S) if k == 0: print("Yes") return if k == 1: print("Yes") return S_sorted = sorted(S) a_start = S_sorted[0] a_end = S_sorted[-1] if k == 2: a, b = S_sorted[0], S_sorted[1] D = b - a if D == 0: print("Yes") return required_min_d = D / (n - 1) def get_divisors(d): divisors = set() for i in range(1, int(math.isqrt(d)) + 1): if d % i == 0: divisors.add(i) divisors.add(d // i) return sorted(divisors) divisors = get_divisors(D) found = False for d in divisors: if d < required_min_d: continue m = D // d if m > n -1: continue if (n - 1 - m) < 0: continue if a - 0 * d < 1: continue found = True break print("Yes" if found else "No") return diffs = [] for i in range(k-1): diffs.append(S_sorted[i+1] - S_sorted[i]) current_gcd = diffs[0] for d in diffs[1:]: current_gcd = math.gcd(current_gcd, d) if current_gcd == 0: print("Yes") return valid = True for num in S_sorted: if (num - a_start) % current_gcd != 0: valid = False break last = a_start + current_gcd * (n -1) if last < a_end: valid = False print("Yes" if valid else "No") is_possible()