結果

問題 No.1884 Sequence
ユーザー ks2mks2m
提出日時 2022-03-25 23:08:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,223 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 79,848 KB
実行使用メモリ 71,716 KB
最終ジャッジ日時 2024-04-22 08:01:32
合計ジャッジ時間 36,163 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,432 KB
testcase_01 AC 133 ms
41,604 KB
testcase_02 AC 132 ms
41,544 KB
testcase_03 AC 132 ms
41,592 KB
testcase_04 AC 136 ms
41,472 KB
testcase_05 AC 133 ms
41,628 KB
testcase_06 AC 133 ms
41,308 KB
testcase_07 AC 135 ms
41,668 KB
testcase_08 AC 133 ms
41,480 KB
testcase_09 WA -
testcase_10 AC 1,180 ms
64,540 KB
testcase_11 AC 1,183 ms
64,476 KB
testcase_12 AC 669 ms
53,404 KB
testcase_13 AC 702 ms
54,000 KB
testcase_14 AC 677 ms
52,256 KB
testcase_15 AC 1,019 ms
58,100 KB
testcase_16 AC 1,106 ms
59,380 KB
testcase_17 AC 830 ms
59,660 KB
testcase_18 AC 966 ms
58,744 KB
testcase_19 AC 911 ms
53,712 KB
testcase_20 AC 955 ms
58,232 KB
testcase_21 AC 817 ms
54,500 KB
testcase_22 AC 928 ms
57,480 KB
testcase_23 AC 1,123 ms
60,360 KB
testcase_24 AC 1,083 ms
59,120 KB
testcase_25 AC 1,052 ms
59,880 KB
testcase_26 AC 1,096 ms
59,504 KB
testcase_27 AC 710 ms
54,152 KB
testcase_28 AC 742 ms
53,816 KB
testcase_29 AC 728 ms
54,348 KB
testcase_30 AC 775 ms
54,976 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 899 ms
58,788 KB
testcase_34 AC 901 ms
59,052 KB
testcase_35 AC 756 ms
54,188 KB
testcase_36 AC 950 ms
58,852 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1,086 ms
58,896 KB
testcase_42 AC 1,098 ms
58,832 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]);
				}
			}
		}
		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;
	}
}
0