結果

問題 No.424 立体迷路
ユーザー autumn-eelautumn-eel
提出日時 2016-09-22 22:40:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 820 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 157,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 18:55:35
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 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 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &gx, &gy);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:30:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         rep(i, h)rep(j, w)scanf("%1d", &mp[i][j]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int h, w, sx, sy, gx, gy;
int mp[50][50];
bool flag[50][50];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int dx2[]{ 2,-2,0,0 }, dy2[]{ 0,0,2,-2 };

void dfs(int x, int y) {
	rep(i, 4) {
		int nx = x + dy[i], ny = y + dx[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w && !flag[nx][ny] && abs(mp[x][y] - mp[nx][ny]) <= 1) {
			flag[nx][ny] = true;
			dfs(nx, ny);
		}
	}
	rep(i, 4) {
		int nx = x + dx2[i], ny = y + dy2[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w && !flag[nx][ny] && mp[x][y] == mp[nx][ny]) {
			flag[nx][ny] = true;
			dfs(nx, ny);
		}
	}
}
int main() {
	scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &gx, &gy);
	sx--; sy--; gx--; gy--;
	rep(i, h)rep(j, w)scanf("%1d", &mp[i][j]);
	dfs(sx, sy);
	puts(flag[gx][gy] ? "YES" : "NO");
}
0