結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー pengin_2000pengin_2000
提出日時 2022-07-23 15:55:26
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,734 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 30,644 KB
実行使用メモリ 6,368 KB
最終ジャッジ日時 2023-09-18 14:13:02
合計ジャッジ時間 4,182 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,500 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 134 ms
5,328 KB
testcase_08 AC 36 ms
5,232 KB
testcase_09 AC 176 ms
6,364 KB
testcase_10 AC 179 ms
6,368 KB
testcase_11 AC 166 ms
5,696 KB
testcase_12 AC 165 ms
5,796 KB
testcase_13 AC 166 ms
6,240 KB
testcase_14 AC 93 ms
6,356 KB
testcase_15 AC 93 ms
6,328 KB
testcase_16 AC 23 ms
5,276 KB
testcase_17 AC 247 ms
6,096 KB
testcase_18 AC 22 ms
5,268 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 204 ms
5,916 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 128 ms
5,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int h, w, y, x;
long long int a[502][502];
int heap[2000006], hl;
int comp_h(int i, int j)
{
	if (a[heap[i] / w][heap[i] % w] > a[heap[j] / w][heap[j] % w])
		return 1;
	else
		return -1;
}
void swap_h(int i, int j)
{
	int f = heap[i];
	heap[i] = heap[j];
	heap[j] = f;
	return;
}
void push(int ne)
{
	heap[hl] = ne;
	int p = hl;
	hl++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	hl--;
	swap_h(0, hl);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < hl)
		{
			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 < hl)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return heap[hl];
}
int used[502][502];
int main()
{
	scanf("%d %d %d %d", &h, &w, &y, &x);
	int i, j, k;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			scanf("%lld", &a[i][j]);
	int di[4] = { -1,0,1,0 };
	int dj[4] = { 0,-1,0,1 };
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			used[i][j] = 0;
	int ii, jj;
	long long int v = a[y - 1][x - 1];
	a[y - 1][x - 1] = 0;
	hl = 0;
	push(w * (y - 1) + x - 1);
	while (hl > 0)
	{
		i = pop();
		j = i % w;
		i /= w;
		if (used[i][j] > 0)
			continue;
		if (a[i][j] >= v)
		{
			printf("No\n");
			return 0;
		}
		v += a[i][j];
		used[i][j]++;
		for (k = 0; k < 4; k++)
		{
			ii = i + di[k];
			jj = j + dj[k];
			if (ii < 0 || jj < 0 || i == h || j == w)
				continue;
			if (used[ii][jj] > 0)
				continue;
			push(w * ii + jj);
		}
	}
	printf("Yes\n");
	return 0;
}
0