結果
| 問題 | No.402 最も海から遠い場所 |
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2016-07-22 23:38:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,396 bytes |
| 記録 | |
| コンパイル時間 | 1,474 ms |
| コンパイル使用メモリ | 128,240 KB |
| 実行使用メモリ | 23,344 KB |
| 最終ジャッジ日時 | 2024-11-06 13:21:19 |
| 合計ジャッジ時間 | 7,129 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | AC * 1 WA * 12 TLE * 1 -- * 5 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
typedef long long ll;
int const inf = 1<<29;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }
char G[3003][3003];
int dist[3003][3003];
template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W; cin >> H >> W;
rep(i, H + 2) {
if(i == 0 || i == H + 1) rep(j, W + 2) G[i][j] = '.';
else {
cin >> (G[i] + 1);
G[i][0] = G[i][W+1] = '.';
}
}
H += 2, W += 2;
priority_queue<tuple<int, int, int, int, int>> q;
rep(i, H) rep(j, W) {
if(G[i][j] == '.') {
q.push({0, i, j, i, j});
dist[i][j] = 0;
} else {
dist[i][j] = inf;
}
}
// rep(i, H) { rep(j, W) { printf("%c", G[i][j]); } puts(""); }
int ans = 0;
while(!q.empty()) {
int c, y, x, sy, sx; tie(c, y, x, sy, sx) = q.top(); q.pop();
rep(k, 4) {
int ny = y + dy[k], nx = x + dx[k];
if(!in_range(ny, nx, H, W)) continue;
if(G[ny][nx] == '.') {
if(dist[ny][nx] == 0) continue;
dist[ny][nx] = 0;
q.emplace(0, ny, nx, sy, sx);
}
else {
int me = max(abs(ny - sy), abs(nx - sx));
if(dist[ny][nx] <= me) continue;
dist[ny][nx] = me;
maximize(ans, me);
q.emplace(me, ny, nx, sy, sx);
}
}
}
// rep(i, H) rep(j, W) { printf("%2d%c", dist[i][j], j == W-1 ? '\n' : ' '); }
cout << ans << endl;
return 0;
}
moti