結果

問題 No.1638 Robot Maze
ユーザー saksak
提出日時 2021-06-26 15:45:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,247 bytes
コンパイル時間 2,681 ms
コンパイル使用メモリ 225,480 KB
実行使用メモリ 4,904 KB
最終ジャッジ日時 2023-10-17 02:23:57
合計ジャッジ時間 11,244 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 WA -
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 <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct dijkstra2d {

  ll N, M;
  struct edge { p_ll to; ll d; };
  vector<vector<vector<edge>>> adj;
  vector<vector<ll>> minlen;

  dijkstra2d(ll n, ll m) { 
    N = n; M = m; 
    adj.resize(N); rep(i,N) adj[i].resize(M);
    minlen.resize(N); rep(i,N) minlen[i].assign(M,LLINF);
  }

  void add_edge(p_ll from, p_ll to, ll d) {
    adj[from.first][from.second].push_back({to,d});
  }
  vector<vector<ll>> calc(ll n=0, ll m=0) {
    auto c = [](const pair<p_ll, ll> &x, const pair<p_ll, ll> &y){return x.second>y.second;};
    priority_queue<pair<p_ll, ll>, vector<pair<p_ll, ll>>, decltype(c)> q(c);
    minlen[n][m] = 0; q.push(make_pair(make_pair(n,m),0));
    while(q.size()) {
      pair<p_ll, ll> now = q.top(); q.pop();
      p_ll np = now.first;
      ll np1 = np.first, np2 = np.second;
      ll nd = now.second;
      if (nd>minlen[np1][np2]) continue;
      for (auto x: adj[np1][np2]) {
        ll xt1 = x.to.first, xt2 = x.to.second;
        if (minlen[xt1][xt2]<=minlen[np1][np2]+x.d) continue;
        q.push(make_pair(make_pair(xt1, xt2), minlen[np1][np2]+x.d));
        minlen[xt1][xt2] = minlen[np1][np2]+x.d;
      }
    }
    return minlen;
  }

};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  ll H, W; cin >> H >> W;
  ll U, D, R, L, K; cin >> U >> D >> R >> L >> K;
  ll cost = (D+1)*(R+1)*(U+1)*(L+1);
  string C[H]; rep(i,H) cin >> C[i];
  ll xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt; xs--; ys--; xt--; yt--;

  dijkstra2d dk(H,W);
  rep(i,H) rep(j,W) {
    if (i!=H-1) {
      if (C[i+1][j]=='.')      dk.add_edge(make_pair(i,j), make_pair(i+1,j), D);
      else if (C[i+1][j]=='@') dk.add_edge(make_pair(i,j), make_pair(i+1,j), cost+D);

      if (C[i][j]=='.')      dk.add_edge(make_pair(i+1,j), make_pair(i,j), U);
      else if (C[i][j]=='@') dk.add_edge(make_pair(i+1,j), make_pair(i,j), cost+U);
    }

    if (j!=W-1) {
      if (C[i][j+1]=='.')      dk.add_edge(make_pair(i,j), make_pair(i,j+1), R);
      else if (C[i][j+1]=='@') dk.add_edge(make_pair(i,j), make_pair(i,j+1), cost+R);

      if (C[i][j]=='.')      dk.add_edge(make_pair(i,j+1), make_pair(i,j), L);
      else if (C[i][j]=='@') dk.add_edge(make_pair(i,j+1), make_pair(i,j), cost+L);
    }
  }

  vector<vector<ll>> d = dk.calc(xs,ys);
  // for (auto x: d) debug(all(x));
  string result = d[xt][yt]<=K ? "Yes" : "No";
  cout << result << endl;
  return 0;
}
0