結果

問題 No.2465 Dilated Water Simulation
ユーザー 👑 ygussanyygussany
提出日時 2023-09-08 23:18:49
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,085 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 30,152 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-08 23:18:56
合計ジャッジ時間 6,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

void naive(int L, int V[], long long N, int ans[])
{
	int i, j, k, x;
	for (i = 2, ans[1] = V[1]; i <= L; i++) ans[i] = 0;
	for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) {
		if (j > L) j = 1;
		if (k > L) k = 1;
		x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k];
		ans[j] -= x;
		ans[k] += x;
		for (x = 1; x <= L; x++) printf("%d ", ans[x]);
		printf("\n");
	}
}

void naive2(int L, int V[], long long N, int ans[])
{
	int i, j, k, x, prev[200001];
	for (i = 2, ans[1] = V[1]; i <= L; i++) ans[i] = 0;
	for (i = 1; i <= L; i++) prev[i] = 0;
	for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) {
		if (j > L) j = 1;
		if (k > L) k = 1;
		if (j == 1) {
			for (x = 1; x <= L; x++) if (ans[x] != prev[x]) break;
			if (x <= L) {
				for (x = 1; x <= L; x++) prev[x] = ans[x];
			} else break;
		}
		
		x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k];
		ans[j] -= x;
		ans[k] += x;
	}
	if (i < N) {
		N = (N - i) % L;
		for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) {
			if (j > L) j = 1;
			if (k > L) k = 1;
			x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k];
			ans[j] -= x;
			ans[k] += x;
		}
	}
}

void naive3(int L, int V[], long long N, int ans[])
{
	int i, j, k, x, min = 1 << 30;
	for (i = 2; i <= L; i++) {
		if (V[i] > V[1]) V[i] = V[1];
		if (min > V[i]) min = V[i];
	}
	for (i = 2; V[i] != min; i++);
	for (; i <= L; i++) V[i] = min;
	for (i = L; i >= 2 && V[i] == min; i--) ans[i] = 0;
	for (ans[1] = V[1]; i >= 2; i--) {
		x = (ans[1] - min <= V[i] - min)? ans[1] - min: V[i] - min;
		ans[i] = x;
		ans[1] -= x;
	}
	N = N % L;
	for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) {
		if (j > L) j = 1;
		if (k > L) k = 1;
		x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k];
		ans[j] -= x;
		ans[k] += x;
	}
}

int main()
{
	int i, L, V[200001];
	long long N;
	scanf("%d", &L);
	for (i = 1; i <= L; i++) scanf("%d", &(V[i]));
	scanf("%lld", &N);
	
	int ans[200001];
	if (N >= (long long)L * L) naive3(L, V, N, ans);
	else naive2(L, V, N, ans);
	for (i = 1; i <= L; i++) printf("%d ", ans[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}
0