Submission #1693095
Source Code Expand
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////
struct P{
int y;
int x;
long c;
};
int main(){
int r,c,sy,sx,gy,gx;
C2(r,c);
C4(sy,sx,gy,gx);
sy--;sx--;gy--;gx--;
bool f[r][c]={};
rep(i,0,r){
string s;
cin >> s;
rep(j,0,s.size()){
if(s[j] == '.')
f[i][j] = true;
}
}
queue<struct P> q;
struct P tmp = {sy,sx,0};
q.push(tmp);
long ff[r][c];
rep(i,0,r){
rep(j,0,c){
ff[i][j] = 0xFFFF;
}
}
while(!q.empty()){
struct P p = q.front();
q.pop();
//printf("y:%d x:%d c:%ld\n",p.y,p.x,p.c);
int ny = p.y , nx = p.x;
if(ff[ny][nx] <= p.c ){
//cout << "exit" << endl;
continue;
}
else{
ff[ny][nx] = p.c;
if(ny == gy && nx == gx)
continue;
if(nx > 0){ //left
if(f[ny][nx-1]){
struct P t = {ny,nx-1,p.c+1};
q.push(t);
//cout << "push left" << endl;
}
}
if(nx < c-1){
if(f[ny][nx+1]){ //right
struct P t = {ny,nx+1,p.c+1};
q.push(t);
//cout << "push right" << endl;
}
}
if(ny > 0){ //up
if(f[ny-1][nx]){
struct P t = {ny-1,nx,p.c+1};
q.push(t);
//cout << "push up" << endl;
}
}
if(ny < r-1){ //down
if(f[ny+1][nx]){
struct P t = {ny+1,nx,p.c+1};
q.push(t);
//cout << "push down" << endl;
}
}
}
}
P(ff[gy][gx]);
ret 0;
}
Submission Info
Submission Time |
|
Task |
C - 幅優先探索 |
User |
walk_to_work |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2453 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt |
All |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_sample01.txt |
AC |
1 ms |
256 KB |
subtask0_sample02.txt |
AC |
1 ms |
256 KB |
subtask0_sample03.txt |
AC |
2 ms |
256 KB |
subtask1_01.txt |
AC |
2 ms |
256 KB |
subtask1_02.txt |
AC |
2 ms |
256 KB |
subtask1_03.txt |
AC |
2 ms |
256 KB |
subtask1_04.txt |
AC |
2 ms |
256 KB |
subtask1_05.txt |
AC |
2 ms |
256 KB |
subtask1_06.txt |
AC |
2 ms |
256 KB |
subtask1_07.txt |
AC |
1 ms |
256 KB |
subtask1_08.txt |
AC |
2 ms |
256 KB |
subtask1_09.txt |
AC |
2 ms |
256 KB |
subtask1_10.txt |
AC |
2 ms |
256 KB |
subtask1_11.txt |
AC |
2 ms |
256 KB |
subtask1_12.txt |
AC |
2 ms |
256 KB |
subtask1_13.txt |
AC |
2 ms |
256 KB |
subtask1_14.txt |
AC |
2 ms |
256 KB |
subtask1_15.txt |
AC |
2 ms |
256 KB |
subtask1_16.txt |
AC |
2 ms |
256 KB |
subtask1_17.txt |
AC |
2 ms |
256 KB |
subtask1_18.txt |
AC |
2 ms |
256 KB |
subtask1_19.txt |
AC |
2 ms |
256 KB |
subtask1_20.txt |
AC |
2 ms |
256 KB |
subtask1_21.txt |
AC |
2 ms |
256 KB |
subtask1_22.txt |
AC |
2 ms |
256 KB |