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
Task C - 幅優先探索
User peroon
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1877 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
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 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 1 ms 256 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 256 KB
subtask1_15.txt AC 1 ms 256 KB
subtask1_16.txt AC 1 ms 256 KB
subtask1_17.txt AC 1 ms 256 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 1 ms 256 KB
subtask1_21.txt AC 1 ms 256 KB
subtask1_22.txt AC 1 ms 256 KB