Contest Duration: ~ (local time) (120 minutes) Back to Home

Submission #4074284

Source Code Expand

Copy
```#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
for(auto v : V){
cout << v << " ";
}
cout << endl;
}

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Point{
ll x;
ll y;
Point(ll x, ll y): x(x), y(y) {}
};

int main(){
cin.tie(0);
ios::sync_with_stdio(false);

// input
ll R, C;
cin >> R >> C;

bool visited[R][C];
int d[R][C];
FOR(i, 0, R){
FOR(j, 0, C){
d[i][j] = -1;
visited[i][j] = false;
}
}

int sy, sx;
cin >> sy >> sx;
sx--;
sy--;

int gy, gx;
cin >> gy >> gx;
gx--;
gy--;

vector<string> m;
FOR(i, 0, R){
string s;
cin >> s;
m.push_back(s);
}

queue<Point> que;
que.push(Point(sx, sy));
d[sy][sx] = 0;
visited[sy][sx] = true;

while(!que.empty()){
auto p = que.front();
que.pop();

FOR(i, 0, 4){
int nx = p.x + dx[i];
int ny = p.y + dy[i];

if(0<=nx && nx<C && 0<=ny && ny<R && m[ny][nx] == '.' && !visited[ny][nx]){
que.push(Point(nx, ny));
d[ny][nx] = d[p.y][p.x] + 1;
visited[ny][nx] = true;
}
}
}

p(d[gy][gx]);

return 0;
}```

Submission Info

Submission Time 2019-01-23 20:44:54+0900 C - 幅優先探索 peroon C++14 (GCC 5.4.1) 100 1877 Byte AC 1 ms 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
 AC × 3
 AC × 25
Set Name Test Cases
Case Name Status Exec Time Memory