結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2019-07-06 19:12:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2,168 ms / 3,000 ms |
コード長 | 1,855 bytes |
コンパイル時間 | 876 ms |
コンパイル使用メモリ | 104,644 KB |
実行使用メモリ | 227,648 KB |
最終ジャッジ日時 | 2024-10-01 06:52:37 |
合計ジャッジ時間 | 12,542 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%s", s[i]+1); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; const int INF=1e8; char s[3010][3010]; int h, w; int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1}; bool check(int i, int j){ if(i<0 || i>=h+w || j<0 || j>=h+w) return false; return true; } int main() { cin>>h>>w; for(int i=1; i<=h; i++){ scanf("%s", s[i]+1); s[i][0]='.'; s[i][w+1]='.'; } for(int i=0; i<w+2; i++) s[0][i]=s[h+1][i]='.'; h+=2, w+=2; int d[6010][6010]; for(int i=0; i<h+w; i++){ for(int j=0; j<h+w; j++){ d[i][j]=INF; } } queue<P> que; for(int i=0; i<h; i++){ for(int j=0; j<w; j++){ if(s[i][j]=='.'){ d[i+j][i-j+w-1]=0; que.push({i+j, i-j+w-1}); } } } while(!que.empty()){ P p=que.front(); que.pop(); int x=p.first, y=p.second; for(int k=0; k<4; k++){ int x1=x+dx[k], y1=y+dy[k]; if(!check(x1, y1)) continue; if(d[x1][y1]>d[x][y]+1){ d[x1][y1]=d[x][y]+1; que.push({x1, y1}); } } } int ans=0; for(int i=0; i<h+w; i++){ for(int j=0; j<h+w; j++){ if((i+j+w-1)&1) continue; int x=(i+j-w+1)/2, y=(i-j+w-1)/2; if(x<=0 || x>=h-1 || y<=0 || y>=w-1) continue; ans=max(ans, d[i][j]/2); } } cout<<ans<<endl; return 0; }