結果

問題 No.1884 Sequence
ユーザー 👑 ygussanyygussany
提出日時 2022-03-07 15:46:08
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 29,584 KB
実行使用メモリ 4,968 KB
最終ジャッジ日時 2023-09-29 16:36:19
合計ジャッジ時間 5,029 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 62 ms
4,840 KB
testcase_11 AC 62 ms
4,840 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 21 ms
4,604 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 46 ms
4,836 KB
testcase_16 AC 62 ms
4,896 KB
testcase_17 AC 30 ms
4,852 KB
testcase_18 AC 36 ms
4,848 KB
testcase_19 AC 30 ms
4,508 KB
testcase_20 AC 41 ms
4,820 KB
testcase_21 AC 35 ms
4,844 KB
testcase_22 AC 43 ms
4,864 KB
testcase_23 AC 61 ms
4,816 KB
testcase_24 AC 62 ms
4,820 KB
testcase_25 AC 60 ms
4,816 KB
testcase_26 AC 62 ms
4,796 KB
testcase_27 AC 24 ms
4,956 KB
testcase_28 AC 25 ms
4,900 KB
testcase_29 AC 24 ms
4,968 KB
testcase_30 AC 24 ms
4,932 KB
testcase_31 AC 37 ms
4,376 KB
testcase_32 AC 60 ms
4,892 KB
testcase_33 AC 43 ms
4,848 KB
testcase_34 AC 44 ms
4,964 KB
testcase_35 AC 27 ms
4,936 KB
testcase_36 AC 39 ms
4,820 KB
testcase_37 AC 43 ms
4,900 KB
testcase_38 AC 40 ms
4,948 KB
testcase_39 AC 30 ms
4,780 KB
testcase_40 AC 31 ms
4,968 KB
testcase_41 AC 55 ms
4,852 KB
testcase_42 AC 54 ms
4,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void merge_sort(int n, long long x[])
{
	static long long y[200001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

long long gcd(long long a, long long b)
{
	if (a == 0) return b;
	else return gcd(b % a, a);
}

int solve(int N, long long A[])
{
	int i;
	long long g;
	merge_sort(N, A);
	for (i = 0; i < N && A[i] == 0; i++);
	if (i >= N - 2) return 1;
	
	long long min = A[i], max = A[N-1];
	g = A[i+1] - A[i];
	for (i++; i < N - 1; i++) {
		if ((g == 0 && A[i+1] != A[i]) || (g != 0 && A[i+1] == A[i])) return 0;
		else if (g != 0) g = gcd(g, A[i+1] - A[i]);
	}
	if (g == 0 || (max - min) / g < N) return 1;
	else return 0;
}

int main()
{
	int i, N;
	long long A[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%lld", &(A[i]));
	if (solve(N, A) == 0) printf("No\n");
	else printf("Yes\n");
	fflush(stdout);
	return 0;
}
0