結果

問題 No.1884 Sequence
ユーザー pengin_2000pengin_2000
提出日時 2022-08-20 13:47:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 12:39:01
合計ジャッジ時間 4,076 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 66 ms
5,376 KB
testcase_11 AC 63 ms
5,376 KB
testcase_12 AC 20 ms
5,376 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 49 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 AC 44 ms
5,376 KB
testcase_19 AC 39 ms
5,376 KB
testcase_20 AC 44 ms
5,376 KB
testcase_21 AC 38 ms
5,376 KB
testcase_22 AC 47 ms
5,376 KB
testcase_23 AC 63 ms
5,376 KB
testcase_24 AC 63 ms
5,376 KB
testcase_25 AC 63 ms
5,376 KB
testcase_26 AC 62 ms
5,376 KB
testcase_27 AC 28 ms
5,376 KB
testcase_28 AC 27 ms
5,376 KB
testcase_29 AC 27 ms
5,376 KB
testcase_30 AC 26 ms
5,376 KB
testcase_31 AC 38 ms
5,376 KB
testcase_32 AC 58 ms
5,376 KB
testcase_33 AC 42 ms
5,376 KB
testcase_34 AC 42 ms
5,376 KB
testcase_35 AC 31 ms
5,376 KB
testcase_36 AC 42 ms
5,376 KB
testcase_37 AC 43 ms
5,376 KB
testcase_38 AC 41 ms
5,376 KB
testcase_39 AC 34 ms
5,376 KB
testcase_40 AC 35 ms
5,376 KB
testcase_41 AC 56 ms
5,376 KB
testcase_42 AC 58 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[200005], l;
int comp_h(long long int a, long long int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(long long int ne)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop()
{
	l--;
	swap_h(0, l);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
long long int gcd(long long int a, long long int b)
{
	if (a * b == 0)
		return 0;
	long long int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
long long int a[200005];
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(a[i]);
	for (i = 0; i < n; i++)
		a[i] = pop();
	a[n] = 1;
	for (j = 0; a[j] == 0; j++);
	if (j > n - 2)
	{
		printf("Yes\n");
		return 0;
	}
	long long int g = a[j + 1] - a[j];
	for (i = j + 1; i < n; i++)
		g = gcd(g, a[i] - a[i - 1]);
	if (g == 0)
	{
		if (a[n - 1] == a[j])
			printf("Yes\n");
		else
			printf("No\n");
		return 0;
	}
	if (a[n - 1] / g - a[j] / g < n)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}
0