結果

問題 No.20 砂漠のオアシス
ユーザー A8pfA8pf
提出日時 2019-07-01 13:04:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 2,545 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 180,348 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-07-08 13:07:40
合計ジャッジ時間 2,648 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;
class Edge
{
public:
int to,cost;
Edge(int t,int c)
{
to=t;cost=c;
}
};
vector<Edge> g[40000]; //(i,j)=i*200+j
int d[40000]; //
int m[200][200]; //
//nst01BFS
int bfs(int s,int t,int n)
{
deque<P> q;
fill(d,d+n,1e8-1); //ll1e17-1
//01BFS
d[s]=0;
q.push_back(P(d[s],s));
while(!q.empty())
{
P p=q[0]; //
q.pop_front();
for(int i=0;i<g[p.second].size();i++)
{
Edge e=g[p.second][i];
if(d[e.to]==1e8-1)//
{
d[e.to]=p.first+1;
q.push_back(P(d[e.to],e.to));
}
}
}
//(h,w
/*
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
cerr<<(d[i*50+j]==1e8-1 ? -1 : d[i*50+j])<<" ";
cerr<<endl;
}*/
return d[t];
}
//n
int dijk(int s,int t,int n)
{
priority_queue<P,vector<P>,greater<P>> q;
fill(d,d+n,1e8-1);
d[s]=0;
q.push(P(d[s],s));
while(!q.empty())
{
P p=q.top();q.pop();
if(p.first>d[p.second])
continue;
for(int i=0;i<g[p.second].size();i++)
{
Edge e=g[p.second][i];
if(d[e.to]>p.first+e.cost)
{
d[e.to]=p.first+e.cost;
q.push(P(d[e.to],e.to));
}
}
}
return d[t];
}
int main()
{
int n,v,ox,oy;
cin>>n>>v>>ox>>oy;
ox--;oy--;
int s=0; //(0,0)
int t=200*(n-1)+(n-1); //(n-1,n-1)
int o=200*ox+oy;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};//
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cin>>m[j][i]; //ij
}
/* 0indexed */
//
//x
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
//4調
for(int k=0;k<4;k++)
{
int nx=i+dx[k];
int ny=j+dy[k];
if(nx>-1 && nx<n && ny>-1 && ny<n)
{
//調
g[i*200+j].push_back(Edge(nx*200+ny,m[nx][ny]));
}
}
}
}
int st=dijk(s,t,40000); //st
int so=1e8-1;
int ot=1e8-1;
//
if(o>0)
{
so=d[o];
ot=dijk(o,t,40000);
}
cerr<<st<<" "<<so<<" "<<ot<<endl;
if(st<v || ot<(v-so)*2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0