結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2016-07-22 23:15:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 617 ms / 3,000 ms |
| コード長 | 2,690 bytes |
| コンパイル時間 | 1,104 ms |
| コンパイル使用メモリ | 93,476 KB |
| 実行使用メモリ | 163,404 KB |
| 最終ジャッジ日時 | 2024-11-06 13:07:45 |
| 合計ジャッジ時間 | 4,330 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#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;
}
}
}
}
kotamanegi