結果

問題 No.1638 Robot Maze
ユーザー harurunharurun
提出日時 2021-06-23 14:35:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,187 bytes
コンパイル時間 1,375 ms
コンパイル使用メモリ 115,524 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 02:19:07
合計ジャッジ時間 8,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define ll long long
#define Pll pair<ll,ll>



typedef struct edge{
	ll to;
	ll cost;
}Edge;
typedef pair<int,int> P;

long long INF=1000000000000000000;
int V;
vector<Edge> G[10000];
long long d[10000];
vector<ll> defa;

void dijkstra(ll s){
  priority_queue<P,vector<P>,greater<P>> que;
	fill(d,d+V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();que.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(unsigned int i=0;i<G[v].size();i++){
		  Edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
			  d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

ostream& operator<<(ostream& os,vector<Edge> a){
  for(Edge e:a){
    os<<"to:"<<e.to<<",cots:"<<e.cost<<" ";
  }
  return os;
}
ll H,W,U,D,R,L,K,xs,ys,xt,yt,cnt,m,ans,x,y,co;
vector<string>C;
vector<Pll> B;
vector<Pll> u;

int main(){
  cnt=0;
  ans=INF;
  cin>>H>>W>>U>>D>>R>>L>>K;
  V=H*W;//don't forget
  co=(U+1)*(D+1)*(R+1)*(L+1);
  C.resize(H);
  defa.resize(V);
  for(int i=0;i<H;i++){
    cin>>C.at(i);
    for(int j=0;j<W;j++){
      if(C.at(i).at(j)=='@')B.push_back({i,j});
    }
    C.at(i).append("#");
  }
  string s;
  for(int i=0;i<W;i++)s.append("#");
  C.push_back(s);
  cin>>xs>>ys>>xt>>yt;
  xs--;ys--;xt--;yt--;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(C.at(i).at(j)=='#')continue;
      if(C.at(i+1).at(j)=='.'){
        //cerr<<i<<" "<<j<<"push_back tate\n";
        G[W*i+j].push_back({W*(i+1)+j,D});
        G[W*(i+1)+j].push_back({W*i+j,U});
      }
      if(C.at(i).at(j+1)=='.'){
        //cerr<<i<<" "<<j<<"push_back yoko\n";
        G[W*i+j].push_back({W*i+j+1,R});
        G[W*i+j+1].push_back({W*i+j,L});
      }
    }
  }
  for(int i=0;i<V;i++){
    defa.at(i)=G[i].size();
  }
  cnt=B.size();
  m=pow(2,cnt);
  //cerr<<cnt<<" "<<m<<endl;
  for(int i=0;i<m;i++){
    u.clear();
    for(int j=0;j<cnt;j++){
      if((i>>j)&1){
        x=B.at(j).first;
        y=B.at(j).second;
        u.push_back({x,y});
        C.at(x).at(y)='.';
      }
    }
    for(int j=0;j<cnt;j++){
      if((i>>j)&1){
        x=B.at(j).first;
        y=B.at(j).second;
        if(C.at(x+1).at(y)=='.'){
          G[W*x+y].push_back({W*(x+1)+y,D});
          G[W*(x+1)+y].push_back({W*x+y,U});
        }
        if(C.at(x).at(y+1)=='.'){
          G[W*x+y].push_back({W*x+y+1,R});
          G[W*x+y+1].push_back({W*x+y,L});
        }
        if(x>0 && C.at(x-1).at(y)=='.'){
          G[W*x+y].push_back({W*(x-1)+y,U});
          G[W*(x-1)+y].push_back({W*x+y,D});
        }
        if(y>0 && C.at(x).at(y-1)=='.'){
          G[W*x+y].push_back({W*x+y-1,L});
          G[W*x+y-1].push_back({W*x+y,R});
        }
      }
    }
    dijkstra(W*xs+ys);
    ans=min(ans,d[W*xt+yt]+(ll)u.size()*co);
    //cerr<<u.size()<<" "<<d[W*xt+yt]<<endl;
    for(int i=0;i<V;i++){
      while(G[i].size()>defa.at(i)){
        G[i].pop_back();
      }
    }
    for(Pll j:u){
      C.at(j.first).at(j.second)='@';
    }
  }
  if(ans<=K)cout<<"Yes\n";
  else cout<<"No\n";
  cerr<<"ans:"<<ans<<endl;
  return 0;
}
0