結果
問題 | No.1884 Sequence |
ユーザー |
![]() |
提出日時 | 2022-03-25 23:08:44 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,223 bytes |
コンパイル時間 | 2,461 ms |
コンパイル使用メモリ | 79,624 KB |
実行使用メモリ | 64,388 KB |
最終ジャッジ日時 | 2024-10-14 07:15:34 |
合計ジャッジ時間 | 32,924 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 7 |
ソースコード
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); } sc.close(); Arrays.sort(a); long z = 0; long mind = 1000000000000000000L; Set<Long> set = new HashSet<>(); for (int i = 0; i < n; i++) { if (a[i] == 0) { z++; } else { if (i > 0 && a[i - 1] > 0) { set.add(a[i] - a[i - 1]); mind = Math.min(mind, a[i] - a[i - 1]); } } } if (mind == 0) { System.out.println("Yes"); return; } for (long e : set) { mind = gcd(mind, e); } if (judge(n, a, z, mind)) { System.out.println("Yes"); } else { System.out.println("No"); } } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static boolean judge(int n, long[] a, long z, long mind) { for (int i = (int) z + 1; i < n; i++) { long d = a[i] - a[i - 1]; if (d % mind != 0) { return false; } else { z -= d / mind - 1; if (z < 0) { return false; } } } return true; } }