AtCoder Beginner Contest 007

Submission #1359298

Source codeソースコード

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
using namespace std;


char maze[1000][1000];
int N, M;
int sx, sy; 
int gx, gy; 

int d[1000][1000]; 

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


int bfs() {
	queue<pair<int, int>> que;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			d[i][j] = INF;
		}
	}
	que.push(pair<int,int>(sx,sy));
	d[sx][sy] = 0;
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
		if (p.first == gy&&p.second == gx) {
			break;
		}
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (1 <= nx&&nx <= N && 1 <= ny&&ny <= M&&maze[nx][ny] != '#'&&d[nx][ny] == INF) {
				que.push(pair<int,int>(nx,ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gy][gx];
}

int main() {
	cin >> N >> M >> sy >> sx >> gy >> gx;
	string s;
	for (int i = 1; i <= N; i++) {
		cin >> s;
		for (int j = 1; j <= M; j++) {
			maze[i][j] = s[j-1];
		}
	}
	int res = bfs();
	cout << res << endl;
}

Submission

Task問題 C - 幅優先探索
User nameユーザ名 tancahn2380
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1262 Byte
File nameファイル名
Exec time実行時間 2 ms
Memory usageメモリ使用量 2432 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt
All 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample01.txt AC 2 ms 2304 KB
subtask0_sample02.txt AC 2 ms 2304 KB
subtask0_sample03.txt AC 2 ms 2432 KB
subtask1_01.txt AC 2 ms 2432 KB
subtask1_02.txt AC 2 ms 2432 KB
subtask1_03.txt AC 2 ms 2432 KB
subtask1_04.txt AC 2 ms 2432 KB
subtask1_05.txt AC 2 ms 2432 KB
subtask1_06.txt AC 2 ms 2432 KB
subtask1_07.txt AC 2 ms 2304 KB
subtask1_08.txt AC 2 ms 2432 KB
subtask1_09.txt AC 2 ms 2432 KB
subtask1_10.txt AC 2 ms 2432 KB
subtask1_11.txt AC 2 ms 2432 KB
subtask1_12.txt AC 2 ms 2432 KB
subtask1_13.txt AC 2 ms 2432 KB
subtask1_14.txt AC 2 ms 2432 KB
subtask1_15.txt AC 2 ms 2432 KB
subtask1_16.txt AC 2 ms 2432 KB
subtask1_17.txt AC 2 ms 2432 KB
subtask1_18.txt AC 2 ms 2432 KB
subtask1_19.txt AC 2 ms 2432 KB
subtask1_20.txt AC 2 ms 2432 KB
subtask1_21.txt AC 2 ms 2432 KB
subtask1_22.txt AC 2 ms 2432 KB