結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-06 01:02:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,552 bytes |
| コンパイル時間 | 1,213 ms |
| コンパイル使用メモリ | 88,784 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 22:28:12 |
| 合計ジャッジ時間 | 1,391 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 2 |
| other | AC * 20 WA * 1 |
ソースコード
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
//#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
return y?gcd(y,x%y):x;
}
bool f[55][55];
int main(){
int h,w,a,b,c,d;
cin>>h>>w>>a>>b>>c>>d;
a--,b--,c--,d--;
vector<string>p(h);
for(int i=0;i<h;i++)
cin>>p[i];
queue<int>x,y;
x.push(a),y.push(b);
while(x.size()){
int t=x.front(),r=y.front();
//cout<<t<<r<<endl;;
if(t==c&&r==d){
cout<<"YES"<<endl;
return 0;
}
if(t<h-1){if(abs(p[t][r]-p[t+1][r])<2&&t<h-1&&!f[t+1][r])f[t+1][r]=1,x.push(t+1),y.push(r);}
if(t){if(abs(p[t][r]-p[t-1][r])<2&&t>0&&!f[t-1][r])f[t-1][r]=1,x.push(t-1),y.push(r);}
if(r<w-1){if(abs(p[t][r]-p[t][r+1])<2&&r<w-1&&!f[t][r+1])f[t][r+1]=1,x.push(t),y.push(r+1);}
if(r){if(abs(p[t][r]-p[t][r-1])<2&&r>0&&!f[t][r-1])f[t][r-1]=1,x.push(t),y.push(r-1);}
if(t<h-2){if(p[t][r]>p[t+2][r]&&abs(p[t][r]-p[t+2][r])<1&&t<h-2&&!f[t+2][r])f[t+2][r]=1,x.push(t+2),y.push(r);}
if(t>1){if(p[t][r]>p[t-2][r]&&abs(p[t][r]-p[t-2][r])<1&&t>1&&!f[t-2][r])f[t-2][r]=1,x.push(t-2),y.push(r);}
if(r<w-2){if(p[t][r]>p[t][r+2]&&abs(p[t][r]-p[t][r+2])<1&&r<w-2&&!f[t][r+2])f[t][r+2]=1,x.push(t),y.push(r+2);}
if(r>1){if(abs(p[t][r]>p[t][r-2]&&p[t][r]-p[t][r-2])<1&&r>1&&!f[t][r-2])f[t][r-2]=1,x.push(t),y.push(r-2);}
x.pop(),y.pop();
}
cout<<"NO"<<endl;
return 0;
}