結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
rapurasu
|
| 提出日時 | 2016-07-25 00:55:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,173 ms / 3,000 ms |
| コード長 | 2,641 bytes |
| コンパイル時間 | 1,792 ms |
| コンパイル使用メモリ | 174,316 KB |
| 実行使用メモリ | 169,940 KB |
| 最終ジャッジ日時 | 2024-11-06 16:05:00 |
| 合計ジャッジ時間 | 11,343 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int dp[3002][3002];
#define INF 10000
#define MAX_V 10000000
struct edge{int to ,cost;};
typedef pair<int,int> P; //firstは最短距離,secondは頂点の番号
int V;
int d[MAX_V];
priority_queue<P,vector<P>,greater<P> > que;
int H,W;
void dijkstra(int s){
//greater<P>を指定することでfirstが小さい順に取り出せる
fill(d,d+V,INF);
//d[s]=0;
//queue.push(P(0,s));
while(!que.empty()){
P p=que.top();que.pop();
int v=p.second;
if(d[v] < p.first)continue;
for(int i=-1;i<=1;i++){
for(int j=-1;j<=1;j++){
if(i==0&&j==0)continue;
int a=0;
a=v+(i*1)+j*(W+2);
if(a<0||(a>=(H+2)*(W+2)))continue;
if((v%(W+2)==0&&i==-1)||(v%(W+2)==W+1&&i==1))continue;
/*
switch(i){
case 0:
if(v-1<0)continue;
a=v-1;
break;
case 1:
if(v-W-2<0)continue;
a=v-W-2;
break;
case 2:
if(v%(W+2)==W+1)continue;
a=v+1;
break;
case 3:
if(v+W+2>(H+2)*(W+2))continue;
a=v+H+2;
break;
case 4:
if(v)
}
*/
if(d[a]>d[v]+1){
d[a]=d[v]+1;
que.push(P(d[a],a));
}
}
}
/*
cout<<v<<endl;
REP(i,H+2){
REP(j,W+2){
cout<<d[i*(W+1)+j]<<" ";
}
cout<<endl;
}
cout<<endl;
*/
}
}
int main(){
cin>>H>>W;
REP(i,H+2){
REP(j,W+2){
if(i==0||i==H+1||j==0||j==W+1){
d[i*(W+2)+j]=0;
que.push(P(0,i*(W+2)+j));
}else{
d[i*(W+2)+j]=INF;
}
}
}
REP(i,H){
string S;
cin>>S;
REP(j,W){
if(S[j]=='.'){
d[(i+1)*(W+2)+(j+1)]=0;
que.push(P(0,(i+1)*(W+2)+j+1));
}else{
d[(i+1)*(W+2)+j+1]=INF;
}
}
}
dijkstra(0);
int m=-1;
/*
REP(i,H+2){
REP(j,W+2){
cout<<d[i*(W+2)+j]<<" ";
}
cout<<endl;
}
*/
REP(i,MAX_V){
m=max(m,d[i]);
}
cout<<m<<endl;
return(0);
}
rapurasu