結果

問題 No.402 最も海から遠い場所
ユーザー kotamanegikotamanegi
提出日時 2016-07-22 23:15:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 2,690 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 90,980 KB
実行使用メモリ 179,068 KB
最終ジャッジ日時 2023-08-06 10:07:35
合計ジャッジ時間 4,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,476 KB
testcase_01 AC 2 ms
7,424 KB
testcase_02 AC 3 ms
10,004 KB
testcase_03 AC 2 ms
5,532 KB
testcase_04 AC 3 ms
7,420 KB
testcase_05 AC 2 ms
7,476 KB
testcase_06 AC 2 ms
5,464 KB
testcase_07 AC 2 ms
7,432 KB
testcase_08 AC 2 ms
5,484 KB
testcase_09 AC 2 ms
7,536 KB
testcase_10 AC 2 ms
7,588 KB
testcase_11 AC 2 ms
7,656 KB
testcase_12 AC 2 ms
7,588 KB
testcase_13 AC 6 ms
12,436 KB
testcase_14 AC 5 ms
16,804 KB
testcase_15 AC 18 ms
30,948 KB
testcase_16 AC 24 ms
35,440 KB
testcase_17 AC 218 ms
107,924 KB
testcase_18 AC 561 ms
144,548 KB
testcase_19 AC 366 ms
95,768 KB
testcase_20 AC 396 ms
124,420 KB
testcase_21 AC 365 ms
179,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
long long dijk[5000][5000] = {};
bool ok[5000][5000] = {};
int main() {
	int h, w;
	cin >> h >> w;
	queue<pair<int, int>> go[2];
	for (int i = 1;i <= h;++i) {
		go[0].push(make_pair(i,0));
		go[0].push(make_pair(i, w + 1));
	}
	for (int i = 1;i <= w;++i) {
		go[0].push(make_pair(0, i));
		go[0].push(make_pair(h + 1, i));
	}
	REP(i, h) {
		string hoge;
		cin >> hoge;
		REP(q, w) {
			if (hoge[q] == '.') {
				ok[i + 1][q + 1] = 1;
				go[0].push(make_pair(i + 1, q + 1));
			}
			else {
				dijk[i + 1][q + 1] = -1;
			}
		}
	}
	for (int i = 0;i >= 0;++i) {
		if (go[i % 2].empty() == true) {
			cout << i-1 << endl;
			return 0;
		}
		while (go[i % 2].empty() == false) {
			pair<int, int> now = go[i % 2].front();
			go[i % 2].pop();
			if (dijk[now.first+1][now.second] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first + 1, now.second));
				dijk[now.first + 1][now.second] = i+1;
			}
			if (now.first != 0&&dijk[now.first - 1][now.second] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first - 1, now.second));
				dijk[now.first - 1][now.second] = i+1;
			}
			if (dijk[now.first][now.second + 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first, now.second + 1));
				dijk[now.first][now.second + 1] = i+1;
			}
			if (now.second != 0&&dijk[now.first][now.second - 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first, now.second - 1));
				dijk[now.first][now.second - 1] = i+1;
			}
			if (dijk[now.first + 1][now.second + 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first + 1, now.second + 1));
				dijk[now.first + 1][now.second + 1] = i + 1;
			}
			if (now.first != 0&&dijk[now.first - 1][now.second + 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first - 1, now.second + 1));
				dijk[now.first - 1][now.second + 1] = i + 1;
			}
			if (now.second != 0 && dijk[now.first + 1][now.second - 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first + 1, now.second - 1));
				dijk[now.first + 1][now.second - 1] = i + 1;
			}
			if (now.second != 0 && now.first != 0 && dijk[now.first - 1][now.second - 1] == -1) {
				go[(i + 1) % 2].push(make_pair(now.first - 1, now.second - 1));
				dijk[now.first - 1][now.second - 1] = i + 1;
			}
		}
	}
}
0