AtCoder Beginner Contest 007

Submission #1419400

Source codeソースコード

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <queue>
#define _USE_MATH_DEFINES
#define LL long long
using namespace std;

int smax(int *ary) {
	int m = 0;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (m < ary[i]) m = ary[i];
	return m;
}

int nmax(int *ary) {
	int max = 0, num;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) {
			max = ary[i];
			num = i;
		}
	return max, num;
}

int main() {
	int h, w, sy, sx, gy, gx, cnt[50][50] = {}, num = 0;
	char c[51][51];
	cin >> h >> w >> sy >> sx >> gy >> gx;
	for (int i = 0; i < h; i++) cin >> c[i];
	sx--;
	sy--;
	gx--;
	gy--;
	int x_sarch[4] = { -1,0,1,0 },
		y_sarch[4] = { 0,-1,0,1 };
	queue<int> qx, qy;
	qx.push(sx);
	qy.push(sy);
	while (!qx.empty()) {
		for (int i = 0; i < 4; i++) {
			if (qx.front() + x_sarch[i] == gx && qy.front() + y_sarch[i] == gy) {
				cout << cnt[qy.front()][qx.front()] + 1 << endl;
				return 0;
			}
			if (c[qy.front() + y_sarch[i]][qx.front() + x_sarch[i]] == '.' 
				&& cnt[qy.front() + y_sarch[i]][qx.front() + x_sarch[i]] == 0 
				&&( qy.front() + y_sarch[i] != sy 
				|| qx.front() + x_sarch[i] != sx))
			{
				qx.push(qx.front() + x_sarch[i]);
				qy.push(qy.front() + y_sarch[i]);
				cnt[qy.front() + y_sarch[i]][qx.front() + x_sarch[i]] = cnt[qy.front()][qx.front()] + 1;
			}
		}
		qx.pop();
		qy.pop();
	}
	return 0;
}

Submission

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