結果
問題 | No.1884 Sequence |
ユーザー | tenten |
提出日時 | 2022-04-02 16:57:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 676 ms / 2,000 ms |
コード長 | 2,375 bytes |
コンパイル時間 | 2,454 ms |
コンパイル使用メモリ | 80,436 KB |
実行使用メモリ | 67,816 KB |
最終ジャッジ日時 | 2024-05-01 13:28:31 |
合計ジャッジ時間 | 18,266 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,908 KB |
testcase_01 | AC | 48 ms
50,516 KB |
testcase_02 | AC | 49 ms
50,248 KB |
testcase_03 | AC | 48 ms
50,024 KB |
testcase_04 | AC | 47 ms
50,552 KB |
testcase_05 | AC | 47 ms
50,024 KB |
testcase_06 | AC | 49 ms
50,192 KB |
testcase_07 | AC | 48 ms
50,248 KB |
testcase_08 | AC | 49 ms
50,284 KB |
testcase_09 | AC | 48 ms
50,344 KB |
testcase_10 | AC | 654 ms
66,852 KB |
testcase_11 | AC | 676 ms
67,092 KB |
testcase_12 | AC | 183 ms
56,116 KB |
testcase_13 | AC | 184 ms
56,256 KB |
testcase_14 | AC | 201 ms
56,284 KB |
testcase_15 | AC | 414 ms
64,176 KB |
testcase_16 | AC | 574 ms
65,280 KB |
testcase_17 | AC | 246 ms
59,324 KB |
testcase_18 | AC | 309 ms
64,828 KB |
testcase_19 | AC | 278 ms
60,948 KB |
testcase_20 | AC | 373 ms
62,744 KB |
testcase_21 | AC | 332 ms
59,656 KB |
testcase_22 | AC | 404 ms
62,540 KB |
testcase_23 | AC | 623 ms
65,484 KB |
testcase_24 | AC | 653 ms
65,920 KB |
testcase_25 | AC | 562 ms
67,324 KB |
testcase_26 | AC | 605 ms
67,816 KB |
testcase_27 | AC | 190 ms
56,500 KB |
testcase_28 | AC | 182 ms
55,916 KB |
testcase_29 | AC | 190 ms
56,680 KB |
testcase_30 | AC | 197 ms
56,084 KB |
testcase_31 | AC | 381 ms
61,564 KB |
testcase_32 | AC | 637 ms
65,604 KB |
testcase_33 | AC | 380 ms
65,816 KB |
testcase_34 | AC | 358 ms
65,576 KB |
testcase_35 | AC | 208 ms
55,728 KB |
testcase_36 | AC | 321 ms
65,004 KB |
testcase_37 | AC | 377 ms
65,812 KB |
testcase_38 | AC | 354 ms
65,032 KB |
testcase_39 | AC | 257 ms
56,532 KB |
testcase_40 | AC | 264 ms
58,604 KB |
testcase_41 | AC | 547 ms
65,484 KB |
testcase_42 | AC | 545 ms
65,132 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int zeros = 0; ArrayList<Long> values = new ArrayList<>(); for (int i = 0; i < n; i++) { long x = sc.nextLong(); if (x == 0) { zeros++; } else { values.add(x); } } if (values.size() == 0) { System.out.println("Yes"); return; } Collections.sort(values); HashMap<Long, Integer> counts = new HashMap<>(); for (int i = 0; i < values.size() - 1; i++) { long x = values.get(i + 1) - values.get(i); counts.put(x, counts.getOrDefault(x, 0) + 1); } if (counts.containsKey(0L)) { if (counts.size() == 1) { System.out.println("Yes"); } else { System.out.println("No"); } return; } long gcd = 0; for (long x : counts.keySet()) { if (gcd == 0) { gcd = x; } else { gcd = getGCD(gcd, x); } } long sum = 0; for (long x : counts.keySet()) { sum += (x / gcd - 1) * counts.get(x); } if (sum <= zeros) { System.out.println("Yes"); } else { System.out.println("No"); } } static long getGCD(long x, long y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }