結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2018-08-19 17:36:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,410 bytes |
コンパイル時間 | 872 ms |
コンパイル使用メモリ | 104,164 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:16:52 |
合計ジャッジ時間 | 1,569 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <stdio.h>#include <algorithm>#include <iostream>#include <string>#include <vector>#include <functional>#include <map>#include <iomanip>#include <math.h>#include <stack>#include <queue>#include <bitset>#include <cstdlib>#include <tuple>#include <cctype>using namespace std;int i, j, k;int h, w, sx, sy, gx, gy;vector<string>b;vector<vector<bool>>matrix(100, vector<bool>(100, false));int func(int x, int y) {/*cout << "x->" << x << " y->" << y << endl;for (int i = 0; i <= h; i++) {for (int j = 0; j <= w; j++) {cout << matrix[i][j] << " ";}cout << endl;}cout << endl; cout << endl;*/if (x == gx && y == gy) {cout << "YES" << endl;getchar();getchar();exit(0);//return 0;}int taka = (int)b[y][x] - 48;if (y - 1 >= 0 && matrix[y - 1][x] == false && abs(taka - ((int)b[y - 1][x] - 48)) <= 1) {matrix[y - 1][x] = true;func(x, y - 1);}if (y + 1 <= h && matrix[y + 1][x] == false && abs(taka - ((int)b[y + 1][x] - 48)) <= 1) {matrix[y + 1][x] = true;func(x, y + 1);}if (x + 1 <= w && matrix[y][x + 1] == false && abs(taka - ((int)b[y][x + 1] - 48)) <= 1) {matrix[y][x + 1] = true;func(x + 1, y);}if (x - 1 >= 0 && matrix[y][x - 1] == false && abs(taka - ((int)b[y][x - 1] - 48)) <= 1) {matrix[y][x - 1] = true;func(x - 1, y);}if (y - 2 >= 0 && matrix[y - 2][x] == false && (int)b[y - 1][x] - 48 < taka && taka - ((int)b[y - 2][x] - 48) == 0) {matrix[y - 2][x] = true;func(x, y - 2);}if (y + 2 <= h && matrix[y + 2][x] == false && (int)b[y + 1][x] - 48 < taka && taka - ((int)b[y + 2][x] - 48) == 0) {matrix[y + 2][x] = true;func(x, y + 2);}if (x + 2 <= w && matrix[y][x + 2] == false && (int)b[y][x + 1] - 48 < taka && taka - ((int)b[y][x + 2] - 48) == 0) {matrix[y][x + 2] = true;func(x + 2, y);}if (x - 2 >= 0 && matrix[y][x - 2] == false && (int)b[y][x - 1] - 48 < taka && taka - ((int)b[y][x - 2] - 48) == 0) {matrix[y][x - 2] = true;func(x - 2, y);}return 0;}int main() {cin >> h >> w;//cin >> w >> h;//cin >> sx >> sy >> gx >> gy;cin >> sy >> sx >> gy >> gx;h--; w--;sx--; sy--; gx--; gy--;for (i = 0; i <= h; i++) {//for (i = 0; i <= w; i++) {string st;cin >> st;b.push_back(st);}matrix[sy][sx] = true;//func(sy, sx);func(sx, sy);cout << "NO" << endl;getchar();getchar();return 0;}