結果
問題 | No.402 最も海から遠い場所 |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2016-07-23 00:50:49 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,309 ms / 3,000 ms |
コード長 | 1,635 bytes |
コンパイル時間 | 2,011 ms |
コンパイル使用メモリ | 171,872 KB |
実行使用メモリ | 355,684 KB |
最終ジャッジ日時 | 2024-04-24 06:29:30 |
合計ジャッジ時間 | 10,449 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,948 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 3 ms
6,948 KB |
testcase_07 | AC | 3 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 9 ms
8,612 KB |
testcase_14 | AC | 6 ms
12,276 KB |
testcase_15 | AC | 36 ms
22,584 KB |
testcase_16 | AC | 59 ms
27,056 KB |
testcase_17 | AC | 663 ms
124,364 KB |
testcase_18 | AC | 2,309 ms
110,560 KB |
testcase_19 | AC | 1,452 ms
355,684 KB |
testcase_20 | AC | 1,469 ms
94,548 KB |
testcase_21 | AC | 1,273 ms
225,020 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) typedef long long ll; int H, W; string S[3010]; //----------------------------------------------------------------- struct Comp { bool operator() (pair<int, ll> a, pair<int, ll> b) { return a.second > b.second; } }; #define INF INT_MAX/2 int dx[8] = { 0,1,1,1,0,-1,-1,-1 }; int dy[8] = { -1,-1,0,1,1,1,0,-1 }; bool done[3010][3010]; ll dist[3010][3010]; ll solve() { priority_queue<pair<int, ll>, vector<pair<int, ll> >, Comp> que; rep(y, 0, H) rep(x, 0, W) dist[y][x] = INF; rep(y, 0, H) rep(x, 0, W) { if ((x != 0 && x != W - 1) && (y != 0 && y != H - 1)) continue; if (S[y][x] == '#') { dist[y][x] = 1; done[y][x] = true; que.push(make_pair(y * 10000 + x, 1)); } } rep(y, 0, H) rep(x, 0, W) if(S[y][x] == '.'){ dist[y][x] = 0; done[y][x] = true; que.push(make_pair(y * 10000 + x, 0)); } while (!que.empty()) { auto q = que.top(); que.pop(); int x = q.first % 10000; int y = q.first / 10000; ll c = q.second; rep(i, 0, 8) { int yy = y + dy[i]; int xx = x + dx[i]; if (yy < 0 || H <= yy) continue; if (xx < 0 || W <= xx) continue; if (done[yy][xx]) continue; int cc = c + 1; if (S[yy][xx] == '.') cc = 0; if (cc < dist[yy][xx]) { dist[yy][xx] = cc; done[yy][xx] = true; que.push(make_pair(yy * 10000 + xx, cc)); } } } ll ans = 0; rep(y, 0, H) rep(x, 0, W) ans = max(ans, dist[y][x]); return ans; } //----------------------------------------------------------------- int main() { cin >> H >> W; rep(y, 0, H) cin >> S[y]; cout << solve() << endl; }