結果
問題 | No.402 最も海から遠い場所 |
ユーザー | y_mazun |
提出日時 | 2017-01-20 15:17:39 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 585 ms / 3,000 ms |
コード長 | 1,380 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 49,996 KB |
実行使用メモリ | 121,120 KB |
最終ジャッジ日時 | 2023-08-24 18:18:14 |
合計ジャッジ時間 | 4,551 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
38,848 KB |
testcase_01 | AC | 11 ms
38,800 KB |
testcase_02 | AC | 11 ms
39,012 KB |
testcase_03 | AC | 11 ms
38,780 KB |
testcase_04 | AC | 10 ms
38,832 KB |
testcase_05 | AC | 11 ms
38,848 KB |
testcase_06 | AC | 11 ms
38,832 KB |
testcase_07 | AC | 11 ms
38,844 KB |
testcase_08 | AC | 10 ms
38,768 KB |
testcase_09 | AC | 11 ms
38,776 KB |
testcase_10 | AC | 11 ms
38,800 KB |
testcase_11 | AC | 11 ms
38,920 KB |
testcase_12 | AC | 11 ms
38,884 KB |
testcase_13 | AC | 13 ms
39,456 KB |
testcase_14 | AC | 12 ms
39,568 KB |
testcase_15 | AC | 23 ms
41,236 KB |
testcase_16 | AC | 28 ms
41,556 KB |
testcase_17 | AC | 239 ms
62,412 KB |
testcase_18 | AC | 585 ms
50,716 KB |
testcase_19 | AC | 442 ms
121,120 KB |
testcase_20 | AC | 379 ms
47,116 KB |
testcase_21 | AC | 401 ms
83,744 KB |
ソースコード
#define IN(x,s,g) ((x) >= (s) && (x) < (g)) #define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h))) #include <cstring> #include <queue> #define REP(i,n) for(int i=0; i<(int)(n); i++) #include <cstdio> inline int getInt(){ int s; scanf("%d", &s); return s; } #include <set> using namespace std; int d[3000][3000]; char g[3000][3010]; int main(){ const int h = getInt(); const int w = getInt(); REP(i,h) scanf("%s", g[i]); memset(d, -1, sizeof(d)); queue<pair<int, int> > q; REP(i,h) REP(j,w) if(g[i][j] == '.') { d[i][j] = 0; q.push(make_pair(j, i)); } REP(i,h) { if(d[i][0] == -1) { d[i][0] = 1; q.push(make_pair(0, i)); } if(d[i][w-1] == -1) { d[i][w-1] = 1; q.push(make_pair(w-1, i)); } } REP(i,w) { if(d[0][i] == -1) { d[0][i] = 1; q.push(make_pair(i, 0)); } if(d[h-1][i] == -1) { d[h-1][i] = 1; q.push(make_pair(i, h-1)); } } while (q.size()){ const auto data = q.front (); q.pop(); const int x = data.first; const int y = data.second; REP(i,3) REP(j,3) { const int xx = x + i - 1; const int yy = y + j - 1; if(ISIN(xx, yy, w, h) && d[yy][xx] == -1){ q.push(make_pair(xx, yy)); d[yy][xx] = d[y][x] + 1; } } } // REP(i,h) { REP(j,w) printf("%02d ", d[i][j]); puts(""); } int ans = 0; REP(i,h) REP(j,w) ans = max(ans, d[i][j]); printf("%d\n", ans); return 0; }