結果
問題 | No.402 最も海から遠い場所 |
ユーザー | moti |
提出日時 | 2016-07-23 00:51:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 493 ms / 3,000 ms |
コード長 | 1,892 bytes |
コンパイル時間 | 1,059 ms |
コンパイル使用メモリ | 121,124 KB |
実行使用メモリ | 156,228 KB |
最終ジャッジ日時 | 2024-04-24 06:32:00 |
合計ジャッジ時間 | 4,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 15 ms
9,472 KB |
testcase_16 | AC | 19 ms
11,136 KB |
testcase_17 | AC | 226 ms
57,600 KB |
testcase_18 | AC | 493 ms
53,376 KB |
testcase_19 | AC | 409 ms
156,228 KB |
testcase_20 | AC | 375 ms
47,968 KB |
testcase_21 | AC | 376 ms
102,756 KB |
ソースコード
#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[8] = {-1,0,1,0,-1,1,1,-1}; int dy[8] = {0,-1,0,1,-1,-1,1,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[3010][3010]; int dist[3010][3010]; 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; queue<tuple<int, int, int>> q; rep(i, H) rep(j, W) { dist[i][j] = inf; if(G[i][j] == '.') dist[i][j] = 0, q.emplace(0, i, j); } int max = 0; while(!q.empty()) { int c, y, x; tie(c, y, x) = q.front(); q.pop(); rep(k, 8) { int ny = y + dy[k], nx = x + dx[k]; if(!in_range(ny, nx, H, W)) continue; if(dist[ny][nx] > c + 1) { dist[ny][nx] = c + 1; maximize(max, c + 1); q.emplace(c + 1, ny, nx); } } } cout << max << endl; return 0; }