結果
問題 | No.402 最も海から遠い場所 |
ユーザー | kotamanegi |
提出日時 | 2016-07-22 23:15:39 |
言語 | C++11 (gcc 11.4.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 4 ms
7,824 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 3 ms
6,816 KB |
testcase_13 | AC | 6 ms
14,008 KB |
testcase_14 | AC | 5 ms
16,640 KB |
testcase_15 | AC | 19 ms
29,728 KB |
testcase_16 | AC | 24 ms
35,700 KB |
testcase_17 | AC | 245 ms
107,180 KB |
testcase_18 | AC | 617 ms
128,564 KB |
testcase_19 | AC | 381 ms
95,924 KB |
testcase_20 | AC | 418 ms
112,824 KB |
testcase_21 | AC | 386 ms
163,404 KB |
ソースコード
#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; } } } }