結果

問題 No.1884 Sequence
ユーザー ks2mks2m
提出日時 2022-03-25 23:14:19
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,140 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 2,643 ms
コンパイル使用メモリ 76,784 KB
実行使用メモリ 72,792 KB
最終ジャッジ日時 2023-08-04 10:27:47
合計ジャッジ時間 33,658 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,104 KB
testcase_01 AC 123 ms
55,564 KB
testcase_02 AC 125 ms
55,920 KB
testcase_03 AC 123 ms
55,976 KB
testcase_04 AC 122 ms
56,268 KB
testcase_05 AC 124 ms
55,824 KB
testcase_06 AC 126 ms
53,656 KB
testcase_07 AC 122 ms
56,224 KB
testcase_08 AC 123 ms
55,968 KB
testcase_09 AC 123 ms
55,936 KB
testcase_10 AC 1,140 ms
68,452 KB
testcase_11 AC 1,122 ms
68,196 KB
testcase_12 AC 575 ms
62,848 KB
testcase_13 AC 602 ms
65,260 KB
testcase_14 AC 565 ms
63,132 KB
testcase_15 AC 875 ms
66,956 KB
testcase_16 AC 1,082 ms
68,064 KB
testcase_17 AC 731 ms
72,792 KB
testcase_18 AC 786 ms
66,732 KB
testcase_19 AC 774 ms
64,552 KB
testcase_20 AC 805 ms
67,000 KB
testcase_21 AC 707 ms
66,748 KB
testcase_22 AC 840 ms
68,828 KB
testcase_23 AC 1,092 ms
68,012 KB
testcase_24 AC 1,075 ms
67,264 KB
testcase_25 AC 1,053 ms
67,428 KB
testcase_26 AC 1,061 ms
67,172 KB
testcase_27 AC 623 ms
67,340 KB
testcase_28 AC 663 ms
66,288 KB
testcase_29 AC 627 ms
67,328 KB
testcase_30 AC 633 ms
66,256 KB
testcase_31 AC 772 ms
64,756 KB
testcase_32 AC 1,055 ms
67,508 KB
testcase_33 AC 879 ms
66,800 KB
testcase_34 AC 876 ms
67,028 KB
testcase_35 AC 672 ms
67,028 KB
testcase_36 AC 839 ms
66,748 KB
testcase_37 AC 889 ms
66,888 KB
testcase_38 AC 886 ms
68,868 KB
testcase_39 AC 649 ms
66,852 KB
testcase_40 AC 674 ms
67,164 KB
testcase_41 AC 968 ms
66,588 KB
testcase_42 AC 1,000 ms
67,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]);
				}
			}
		}
		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 (mind == 0) {
				if (d > 0) {
					return false;
				}
			} else if (d % mind != 0 || d == 0) {
				return false;
			} else {
				z -= d / mind - 1;
				if (z < 0) {
					return false;
				}
			}
		}
		return true;
	}
}
0