結果
問題 | No.402 最も海から遠い場所 |
ユーザー | snrnsidy |
提出日時 | 2021-09-12 21:31:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 620 ms / 3,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 2,202 ms |
コンパイル使用メモリ | 203,084 KB |
実行使用メモリ | 120,748 KB |
最終ジャッジ日時 | 2023-09-06 22:32:38 |
合計ジャッジ時間 | 6,695 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
40,164 KB |
testcase_01 | AC | 12 ms
40,300 KB |
testcase_02 | AC | 11 ms
40,212 KB |
testcase_03 | AC | 11 ms
40,184 KB |
testcase_04 | AC | 11 ms
40,180 KB |
testcase_05 | AC | 12 ms
40,148 KB |
testcase_06 | AC | 11 ms
40,224 KB |
testcase_07 | AC | 11 ms
40,188 KB |
testcase_08 | AC | 12 ms
40,212 KB |
testcase_09 | AC | 12 ms
40,324 KB |
testcase_10 | AC | 12 ms
40,252 KB |
testcase_11 | AC | 11 ms
40,428 KB |
testcase_12 | AC | 12 ms
40,180 KB |
testcase_13 | AC | 14 ms
40,428 KB |
testcase_14 | AC | 12 ms
40,256 KB |
testcase_15 | AC | 25 ms
41,132 KB |
testcase_16 | AC | 30 ms
43,472 KB |
testcase_17 | AC | 259 ms
62,064 KB |
testcase_18 | AC | 620 ms
51,332 KB |
testcase_19 | AC | 452 ms
120,748 KB |
testcase_20 | AC | 397 ms
47,532 KB |
testcase_21 | AC | 415 ms
84,204 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int h,w; char board[3005][3005]; int visited[3005][3005]; int dy[8] = {-1,-1,0,1,1,1,0,-1}; int dx[8] = {0,1,1,1,0,-1,-1,-1}; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for(int i=0;i<=h+1;i++) { for(int j=0;j<=w+1;j++) { board[i][j] = '.'; } } for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) { cin >> board[i][j]; } } h += 1; w += 1; memset(visited,-1,sizeof(visited)); queue <pair<int,int>> que; for(int i=0;i<=h;i++) { for(int j=0;j<=w;j++) { if(board[i][j]=='.') { visited[i][j] = 0; que.push(make_pair(i,j)); } } } while(!que.empty()) { int y = que.front().first; int x = que.front().second; que.pop(); for(int k=0;k<8;k++) { int ny = y + dy[k]; int nx = x + dx[k]; if(ny<0 || ny>h || nx<0 || nx>w) continue; if(visited[ny][nx]==-1) { visited[ny][nx] = visited[y][x] + 1; que.push(make_pair(ny,nx)); } } } int res = 0; for(int i=0;i<=h;i++) { for(int j=0;j<=w;j++) { res = max(res,visited[i][j]); } } cout << res <<'\n'; return 0; }