結果
| 問題 | No.402 最も海から遠い場所 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-22 23:48:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,214 bytes |
| 記録 | |
| コンパイル時間 | 939 ms |
| コンパイル使用メモリ | 95,436 KB |
| 実行使用メモリ | 443,772 KB |
| 最終ジャッジ日時 | 2024-11-06 13:28:15 |
| 合計ジャッジ時間 | 10,701 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 TLE * 2 |
ソースコード
#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};
string A[3000];
bool B[3000][3000];
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int H, W;
cin >> H >> W;
rep(i, H) rep(j, W) B[i][j] = false;
rep(i, H) cin >> A[i];
// vector<vector<int>> B(H, vector<int>(W, -1));
set<pair<int, int>> st;
rep(i, H) rep(j, W){
if(A[i][j] == '.') B[i][j] = true, st.insert(mp(i, j));
}
int cur = 0;
while(!st.empty() || cur == 0){
cur++;
set<pair<int, int>> tmp;
for(auto itr = st.begin(); itr != st.end(); ++itr) {
int y = (*itr).first, x = (*itr).second;
rep(i, 8){
if(y + dy[i] >= 0 && y + dy[i] < H && x + dx[i] >= 0 && x + dx[i] < W){
if(B[y + dy[i]][x + dx[i]] == false){
B[y + dy[i]][x + dx[i]] = true;
tmp.insert(mp(y + dy[i], x + dx[i]));
}
}
}
}
if(cur == 1){
rep(i, H){
if(B[i][0] == false) B[i][0] = true, tmp.insert(mp(i, 0));
if(B[i][W - 1] == false) B[i][W - 1] = true, tmp.insert(mp(i, W - 1));
}
rep(i, W){
if(B[0][i] == false) B[0][i] = true, tmp.insert(mp(0, i));
if(B[H - 1][i] == false) B[H - 1][i] = true, tmp.insert(mp(H - 1, i));
}
}
st = tmp;
}
output(cur - 1, 0);
return 0;
}