結果
問題 | No.1638 Robot Maze |
ユーザー |
|
提出日時 | 2021-08-06 23:31:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 2,314 bytes |
コンパイル時間 | 2,608 ms |
コンパイル使用メモリ | 208,160 KB |
最終ジャッジ日時 | 2025-01-23 16:15:41 |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h>using namespace std;#include <math.h>#include <iomanip>#include <cstdint>#include <string>#include <sstream>template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }#define rep(i,n) for (int i = 0; i < (n); ++i)typedef long long ll;typedef unsigned long long ull;using P=pair<ll,ll>;const ll INF=1e18;const int mod=998244353;struct edge{int to;ll w;edge(int to,ll w):to(to),w(w){}};using Graph=vector<vector<edge>>;int n;ll h,w,k,p,xs,ys,xt,yt;int toid(int i,int j){return i*w+j;}ll dijkstra(int s,Graph G){vector<ll> dist(n,INF);dist[s]=0;priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q;q.push({dist[s],s});while(!q.empty()){int v=q.top().second;ll d=q.top().first;q.pop();if(d>dist[v]){continue;}for(auto e:G[v]){if(chmin(dist[e.to],dist[v]+e.w)){q.push({dist[e.to],e.to});}}}return dist[toid(yt,xt)];}char c[105][105];int dx[4]={0,0,1,-1},dy[4]={-1,1,0,0};void solve(){cin>>h>>w;vector<ll>s(4);rep(i,4){cin>>s[i];}cin>>k>>p>>ys>>xs>>yt>>xt;xs--;ys--;xt--;yt--;n=h*w;Graph G(n);rep(i,h){rep(j,w){cin>>c[i][j];}}rep(i,h){rep(j,w){if(c[i][j]=='#'){continue;}rep(k,4){int ni=i+dy[k],nj=j+dx[k];if(ni>=0&&ni<h&&nj>=0&&nj<w&&c[ni][nj]!='#'){ll cost=s[k]+(c[ni][nj]=='@'?p:0);G[toid(i,j)].push_back(edge(toid(ni,nj),cost));}}}}ll dist=dijkstra(toid(ys,xs),G);if(dist<=k){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}int main(){ios_base::sync_with_stdio(false);cin.tie(NULL);solve();return 0;}