結果
| 問題 |
No.402 最も海から遠い場所
|
| ユーザー |
|
| 提出日時 | 2016-07-23 00:36:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 670 ms / 3,000 ms |
| コード長 | 1,887 bytes |
| コンパイル時間 | 1,228 ms |
| コンパイル使用メモリ | 108,152 KB |
| 実行使用メモリ | 179,532 KB |
| 最終ジャッジ日時 | 2024-11-06 12:26:37 |
| 合計ジャッジ時間 | 4,405 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
if(p) cout << fixed << setprecision(p) << a << "\n";
else cout << a << "\n";
}
// end of template
int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int H, W;
cin >> H >> W;
vector<string> A(H);
rep(i, H) cin >> A[i];
vector<vector<int>> B(H + 2, vector<int>(W + 2, -1));
vector<pair<int, int>> st;
rep(i, H + 2){
B[i][0] = 0, st.pb(mp(i, 0));
B[i][W + 1] = 0, st.pb(mp(i, W + 1));
}
rep(i, W + 2){
B[0][i] = 0, st.pb(mp(0, i));
B[H + 1][i] = 0, st.pb(mp(H + 1, i));
}
rep(i, H) rep(j, W){
if(A[i][j] == '.') B[i + 1][j + 1] = 0, st.pb(mp(i + 1, j + 1));
}
int cur = 0;
while(!st.empty()){
cur++;
vector<pair<int, int>> tmp;
for(auto itr: st) {
int y = itr.first, x = itr.second;
rep(i, 8){
int ny = y + dy[i], nx = x + dx[i];
if(ny >= 0 && ny < H + 2 && nx >= 0 && nx < W + 2){
if(B[ny][nx] == -1){
B[ny][nx] = cur;
tmp.pb(mp(ny, nx));
}
}
}
}
st = tmp;
}
output(cur - 1, 0);
return 0;
}