結果
問題 |
No.424 立体迷路
|
ユーザー |
|
提出日時 | 2016-09-26 03:57:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 34,908 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:10:18 |
合計ジャッジ時間 | 880 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &gx, &gy); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:37:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%s", x[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; int n, m, sx, sy, gx, gy; char x[50][51]; bool d[50][50]; bool range(int a, int b){ return 0 <= a && a < n && 0 <= b && b < m; } void dfs(int a, int b){ rep(i, 4){ int p = dx[i], q = dy[i]; if(range(a + p, b + q) && !d[a + p][b + q] && abs(x[a + p][b + q] - x[a][b]) <= 1){ d[a + p][b + q] = true; dfs(a + p, b + q); } if(range(a + p * 2, b + q * 2) && !d[a + p * 2][b + q * 2] && x[a + p][b + q] < x[a][b] && x[a + p * 2][b + q * 2] == x[a][b]){ d[a + p * 2][b + q * 2] = true; dfs(a + p * 2, b + q * 2); } } } int main(){ scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &gx, &gy); --sx; --sy; --gx; --gy; rep(i, n){ scanf("%s", x[i]); rep(j, m){ x[i][j] -= '0'; } } d[sx][sy] = true; dfs(sx, sy); printf("%s\n", d[gx][gy] ? "YES" : "NO"); return 0; }