結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-29 20:59:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,480 bytes |
| コンパイル時間 | 1,551 ms |
| コンパイル使用メモリ | 174,192 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 13:59:26 |
| 合計ジャッジ時間 | 3,173 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
48 | auto [x,y,v]=q.top(); q.pop();
| ^
main.cpp:51:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
51 | for(auto [nx,ny,w]:ve[x][y]){
| ^
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
struct P{
int x,y,v;
bool operator>(const P&a)const {
return v>a.v;
}
};
vector<P>ve[N][N];
int n,m;
int k,p;
int sx,sy,tx,ty;
int dx[]={-1,1,0,0},dy[]={0,0,1,-1};
int value[4];
char s[N][N];
bool vis[N][N];
int dist[N][N];
signed main(){
cin>>n>>m;
for(int i=0;i<4;i++) cin>>value[i];
cin>>k>>p;
cin>>sx>>sy>>tx>>ty;
sx--,sy--,tx--,ty--;
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s[i][j]=='#') continue;
for(int z=0;z<4;z++){
int x=i+dx[z],y=j+dy[z];
if(x<0||y<0||x>=n||y>=m||s[x][y]=='#') continue;
if(s[x][y]=='@'){
ve[i][j].push_back({x,y,value[z]+p});
}
else{
ve[i][j].push_back({x,y,value[z]});
}
}
}
}
memset(dist,0x3f,sizeof dist);
priority_queue<P,vector<P>,greater<P>>q;
q.push({sx,sy,0});
dist[sx][sy]=0;
while(q.size()){
auto [x,y,v]=q.top(); q.pop();
if(vis[x][y]) continue;
vis[x][y]=1;
for(auto [nx,ny,w]:ve[x][y]){
if(dist[nx][ny]>dist[x][y]+w){
dist[nx][ny]=dist[x][y]+w;
q.push({nx,ny,dist[nx][ny]});
}
}
}
if(dist[tx][ty]<=k) cout<<"Yes";
else cout<<"No";
return 0;
}