結果

問題 No.424 立体迷路
ユーザー Yut176
提出日時 2016-10-04 20:09:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,691 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 88,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:11:21
合計ジャッジ時間 1,399 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
int main(){
int h, w;
cin >> h >> w;
vector< vector<int> > mp(h, vector<int>(w) );
vector< vector<bool> > f(h, vector<bool>(w, false) );
vector<int> s(2);
vector<int> g(2);
cin >> s[0] >> s[1] >> g[0] >> g[1];
for(int i=0; i<h; i++){
string tmp;
cin >> tmp;
for(int j=0; j<w; j++){
mp[i][j] = tmp[j]-'0';
}
}
s[0]--;
s[1]--;
g[0]--;
g[1]--;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
queue< pair<int, int> > q;
q.push(make_pair(s[0], s[1]));
f[s[0]][s[1]] = true;
while(true){
if( q.empty() ) break;
int x = q.front().first;
int y = q.front().second;
// cout << x << " " << y << endl;
if( x == g[0] && y == g[1] ){
cout << "YES" << endl;
return 0;
}
q.pop();
for(int i=0; i<4; i++){
int tx = x + dx[i];
int ty = y + dy[i];
if( tx < 0 || tx >= h || ty < 0 || ty >= w ) continue;
if( f[tx][ty] ) continue;
if( mp[tx][ty] == mp[x][y]+1 || mp[tx][ty] == mp[x][y] || mp[tx][ty] == mp[x][y]-1 ){
q.push(make_pair(tx, ty));
f[tx][ty] = true;
}
}
for(int i=0; i<4; i++){
int tx = x + dx[i] + dx[i];
int ty = y + dy[i] + dy[i];
if( tx < 0 || tx >= h || ty < 0 || ty >= w ) continue;
if( f[tx][ty] ) continue;
if( mp[tx][ty] == mp[x][y] && mp[tx-dx[i]][ty-dy[i]] <= mp[x][y] ){
q.push(make_pair(tx, ty));
f[tx][ty] = true;
}
}
}
cout << "NO" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0