Submission #3785137


Source Code Expand

#include <climits>
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

unsigned int m[52][52];

struct Pos {
	int x;
	int y;
};

queue<Pos> went;
// const unsigned int MAX=;

int main(int, char**)
{
	int y_num, x_num;
	cin >> y_num >> x_num;
	Pos g,s;
	cin >> s.y >> s.x;
	cin >> g.y >> g.x;

	for (int i = 0; i <= x_num+1; i++) {
		m[0][i] = 0;
		m[y_num+1][i] = 0;
	}
	for (int i = 1; i <= y_num; i++) {
		m[i][0] = 0;
		m[i][y_num+1] = 0;
	}
	went.push(s);

	for (int i = 1; i <= y_num; i++) {
		for (int j = 1; j <= x_num; j++) {
			char n;
			cin >> n;
			if (n == '#') {
				m[i][j] = 0;
				// cerr << "g=" << j << ", " << i << endl;
			} else {
				m[i][j] = UINT_MAX;
			}
		}
	}

	m[s.y][s.x] = 0;

	while (went.size() > 0) {
		Pos n;
		n.x = went.front().x; n.y = went.front().y;
		// cerr << n.y << ", " << n.x << endl;
		went.pop();
		unsigned int now = m[n.y][n.x];

		n.x++;
		if (n.x == g.x && n.y == g.y) {
			cout << now+1 << endl;
			return 0;
		}
		if (m[n.y][n.x] > now + 1) {
			went.push(n);
			m[n.y][n.x] = now + 1;
		}
		n.x -= 2;
		if (n.x == g.x && n.y == g.y) {
			cout << now+1 << endl;
			return 0;
		}
		if (m[n.y][n.x] > now + 1) {
			went.push(n);
			m[n.y][n.x] = now + 1;
		}
		n.x++; n.y++;
		if (n.x == g.x && n.y == g.y) {
			cout << now+1 << endl;
			return 0;
		}
		if (m[n.y][n.x] > now + 1) {
			went.push(n);
			m[n.y][n.x] = now + 1;
		}
		n.y -= 2;
		if (n.x == g.x && n.y == g.y) {
			cout << now+1 << endl;
			return 0;
		}
		if (m[n.y][n.x] > now + 1) {
			went.push(n);
			m[n.y][n.x] = now + 1;
		}
	}

	return 0;
}

Submission Info

Submission Time
Task A - 植木算
User mhi3
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1695 Byte
Status RE
Exec Time 312 ms
Memory 764 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
WA × 2
RE × 1
WA × 4
RE × 13
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
Case Name Status Exec Time Memory
subtask0_sample01.txt WA 10 ms 764 KB
subtask0_sample02.txt RE 312 ms 256 KB
subtask0_sample03.txt WA 1 ms 256 KB
subtask1_01.txt RE 102 ms 256 KB
subtask1_02.txt RE 102 ms 256 KB
subtask1_03.txt RE 100 ms 256 KB
subtask1_04.txt RE 102 ms 256 KB
subtask1_05.txt RE 101 ms 256 KB
subtask1_06.txt RE 100 ms 256 KB
subtask1_07.txt RE 101 ms 256 KB
subtask1_08.txt RE 103 ms 256 KB
subtask1_09.txt RE 102 ms 256 KB
subtask1_10.txt RE 102 ms 256 KB
subtask1_11.txt RE 104 ms 256 KB
subtask1_12.txt RE 103 ms 256 KB
subtask1_13.txt WA 1 ms 256 KB
subtask1_14.txt WA 1 ms 256 KB