結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 23:28:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 1,485 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 24,576 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:06:13 |
合計ジャッジ時間 | 832 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
main.cpp:74:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 74 | main() | ^~~~ main.cpp: In function ‘int main()’: main.cpp:81:20: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations] 81 | while (gets(buf[n]) != NULL) { | ~~~~^~~~~~~~ In file included from /usr/include/stdio.h:894, from main.cpp:1: /usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here 240 | gets (char *__str) | ^~~~ main.cpp:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 78 | scanf("%d %d\n", &h, &w); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:79:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 79 | scanf("%d %d %d %d\n", &sx, &sy, &gx, &gy); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/stdio.h:894, from main.cpp:1: In function ‘char* gets(char*)’, inlined from ‘int main()’ at main.cpp:81:13: /usr/include/x86_64-linux-gnu/bits/stdio2.h:244:22: warning: call to ‘__gets_warn’ declared with attribute warning: please use fgets or getline instead, gets can't specify buffer size [-Wattribute-warning] 244 | return __gets_warn (__str); | ~~~~~~~~~~~~^~~~~~~ /usr/bin/ld: /tmp/ccl2aJdb.o: in function `main': main.cpp:(.text.startup+0x68): 警告: the `gets' function is dangerous and should not be used.
ソースコード
#include <stdio.h>char buf[50][100];char visit[50][100];int solve(int x, int y, int gx, int gy){int dx, dy;if (visit[y][x]) {return 0;}visit[y][x] = 1;fprintf(stderr, "in %d %d %d %d\n", x, y, gx, gy);if (x == gx && y == gy) {fprintf(stderr, "OK\n");return 1;}int base = buf[y][x];fprintf(stderr, "baseptr=%s\n", buf[y]);fprintf(stderr, "base = %c\n", base);if (base == 0) {fprintf(stderr, "fail\n");return 0;}int dxdy[4][2] = {{ -1, 0 },{ 1, 0 },{ 0, -1 },{ 0, 1 },};for (int i = 0; i < 4; i++) {dx = dxdy[i][0];dy = dxdy[i][1];int xx = x + dx;int yy = y + dy;if (xx < 0 || yy < 0 || xx >= 50 || yy >= 50) {continue;}int c = buf[yy][xx];if (c == base - 1 || c == base + 1 || c == base) {if (solve(xx, yy, gx, gy)) {fprintf(stderr, "solved\n");return 1;}}xx = x + dx * 2;yy = y + dy * 2;if (xx < 0 || yy < 0 || xx >= 50 || yy >= 50) {continue;}int xx2 = x + dx;int yy2 = y + dy;c = buf[yy2][xx2];if (c >= base) {continue;}c = buf[yy][xx];if (c == base) {if (solve(xx, yy, gx, gy)) {fprintf(stderr, "solved\n");return 1;}}}return 0;}main(){int w, h, sx, sy, gx, gy;scanf("%d %d\n", &h, &w);scanf("%d %d %d %d\n", &sx, &sy, &gx, &gy);int n = 0;while (gets(buf[n]) != NULL) {n++;}sx--;sy--;gx--;gy--;if (solve(sy, sx, gy, gx)) {puts("YES");} else {puts("NO");}}