結果

問題 No.1834 1D Gravity
ユーザー 👑 ygussanyygussany
提出日時 2022-01-09 13:03:05
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 19:46:26
合計ジャッジ時間 11,800 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 40 ms
5,376 KB
testcase_14 AC 36 ms
5,376 KB
testcase_15 AC 44 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 27 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void chmax(int* a, int b)
{
	if (*a < b) *a = b;
}

int main()
{
	int i, N, m[200001], p[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(m[i]));
		p[m[i]] = i;
	}
	
	int j, k, max[200001], len, num;
	for (i = 1; i <= N; i++) max[i] = m[i];
	for (k = 1; k <= 1000; k++) {
		for (i = 1; i <= N; i++) {
			if (p[i] == 1) p[i] = 2;
			else if (p[i] == N) p[i] = N - 1;
			else if (max[p[i]-1] > max[p[i]+1]) p[i]--;
			else p[i]++;
		}
		
		for (i = 1; i <= N; i++) max[i] = 0;
		for (i = 1; i <= N; i++) chmax(&(max[p[i]]), i);
		
		for (i = 1, num = 0, len = 0; i <= N; i = j) {
			if (max[i] == 0) {
				j = i + 1;
				continue;
			}
			num++;
			for (j = i + 1; j <= N && max[j] != 0; j++);
			chmax(&len, j - i);
		}
		if (len == 2) break;
	}
	if (k <= 1000) printf("%d %d\n", k, num);
	fflush(stdout);
	return 0;
}
0