結果

問題 No.424 立体迷路
ユーザー JotaroJotaro
提出日時 2017-02-14 15:33:08
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,521 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 87,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:14:03
合計ジャッジ時間 1,340 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:109:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  109 |                 scanf("%s",str);
      |                 ~~~~~^~~~~~~~~~

ソースコード

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

//include
//------------------------------------------
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <ctime>
#include <queue>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define WHITE 0
#define BLACK 1
#define INFTY 1000000000
#define MAX 200000
int maze[500][500];
int v[500][500];
int h,w;
int sx,sy,gx,gy;
void dfs(int y, int x){
//mark as visited
// cout << x << y << ":" << maze[y][x] << endl;
v[y][x] = BLACK;
//tobikoe
if(x >= 2 && maze[y][x]==maze[y][x-2] &&maze[y][x-1]<maze[y][x] && v[y][x-2]==WHITE)dfs(y,x-2);
if(x <= w-3 && maze[y][x]==maze[y][x+2] &&maze[y][x+1]<maze[y][x] && v[y][x+2]==WHITE)dfs(y,x+2);
if(y >= 2 && maze[y][x]==maze[y-2][x] &&maze[y-1][x]<maze[y][x] && v[y-2][x]==WHITE)dfs(y-2,x);
if(y <= h-3 && maze[y][x]==maze[y+2][x] &&maze[y+1][x]<maze[y][x] && v[y+2][x]==WHITE)dfs(y+2,x);
//hasigo
if(x >= 1 && abs(maze[y][x]-maze[y][x-1])<=1 && v[y][x-1]==WHITE)dfs(y,x-1);
if(x <= w-2 && abs(maze[y][x]-maze[y][x+1])<=1 && v[y][x+1]==WHITE)dfs(y,x+1);
if(y >= 1 && abs(maze[y][x]-maze[y-1][x])<=1 && v[y-1][x]==WHITE)dfs(y-1,x);
if(y <= h-2 && abs(maze[y][x]-maze[y+1][x])<=1 && v[y+1][x]==WHITE)dfs(y+1,x);
return ;
}
int main()
{
cin >> h >> w;
cin >> sy >> sx >> gy >> gx;
REP(i,h){
char str[256];
scanf("%s",str);
REP(j,w){
maze[i][j] = str[j]-'0';
v[i][j] = WHITE;
}
}
dfs(sy-1,sx-1);
// REP(i,h){
// REP(j,w){
// if(i==sy-1 && j == sx-1)
// cout << "S";
// else cout << maze[i][j];
// }cout<<endl;
// }
// cout << maze[sy-1][sx-1] << endl;
// REP(i,h){
// REP(j,w){
// if(i==gy-1 && j == gx-1)
// cout << "G" ;
// else cout << v[i][j];
// }cout<<endl;
// }
// cout << endl << gx << gy << endl;
if(v[gy-1][gx-1]==BLACK)cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0