結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-18 06:52:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,696 bytes |
| コンパイル時間 | 1,036 ms |
| コンパイル使用メモリ | 98,796 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 20:13:14 |
| 合計ジャッジ時間 | 2,072 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s[55];
int b1[4] = { 0,0,1,-1 };
int b2[4] = { 1,-1,0,0 };
int b3[4] = { 0,0,2,-2 };
int b4[4] = { 2,-2,0,0 };
bool b[55][55] = { false };
int main() {
int h, w;
cin >> h >> w;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sx--; sy--; gx--; gy--;
for (int i = 0; i < h; i++) {
cin >> s[i];
}
queue<pair<int, int>> que;
que.push(make_pair(sx, sy));
b[sx][sy] = true;
while (!que.empty()) {
int x = que.front().first;
int y = que.front().second;
if (x == gx && y == gy) {
cout << "YES" << endl;
return 0;
}
for (int i = 0; i < 4; i++) {
if (x + b1[i] < 0 || x + b1[i] >= h || y + b2[i] < 0 || y + b2[i] >= w) {
continue;
}
if (abs(int(s[x][y] - s[x + b1[i]][y + b2[i]])) <= 1) {
if (!b[x + b1[i]][y + b2[i]]) {
b[x + b1[i]][y + b2[i]] = true;
que.push(make_pair(x + b1[i], y + b2[i]));
}
}
}
for (int j = 0; j < 4; j++) {
if(x + b3[j] < 0 || x + b3[j] >= h || y + b4[j] < 0 || y + b4[j] >= w) {
continue;
}
if(s[x][y] == s[x + b3[j]][y + b4[j]]) {
if(s[x][y] > s[x + b1[j]][y + b2[j]]) {
if(!b[x + b3[j]][y + b4[j]]) {
b[x + b3[j]][y + b4[j]] = true;
que.push(make_pair(x + b3[j], y + b4[j]));
}
}
}
}
if (x == gx && y == gy) {
cout << "YES" << endl;
return 0;
}
que.pop();
}
cout << "NO" << endl;
return 0;
}