結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 22:43:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 780 bytes |
| コンパイル時間 | 1,852 ms |
| コンパイル使用メモリ | 157,576 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 13:54:42 |
| 合計ジャッジ時間 | 1,981 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &gx, &gy);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:27:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | rep(i, h)rep(j, w)scanf("%1d", &mp[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#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) {
flag[x][y] = true;
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)
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])
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");
}