結果

問題 No.1638 Robot Maze
ユーザー saksak
提出日時 2021-07-01 22:34:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 3,684 bytes
コンパイル時間 3,056 ms
コンパイル使用メモリ 226,528 KB
実行使用メモリ 5,204 KB
最終ジャッジ日時 2023-10-17 02:24:47
合計ジャッジ時間 4,507 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
5,204 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 6 ms
4,924 KB
testcase_15 AC 3 ms
4,432 KB
testcase_16 AC 3 ms
4,432 KB
testcase_17 AC 4 ms
4,432 KB
testcase_18 AC 3 ms
4,428 KB
testcase_19 AC 3 ms
4,432 KB
testcase_20 AC 3 ms
4,432 KB
testcase_21 AC 4 ms
4,728 KB
testcase_22 AC 4 ms
4,728 KB
testcase_23 AC 4 ms
4,728 KB
testcase_24 AC 4 ms
4,728 KB
testcase_25 AC 4 ms
4,728 KB
testcase_26 AC 4 ms
4,728 KB
testcase_27 AC 4 ms
4,728 KB
testcase_28 AC 4 ms
4,728 KB
testcase_29 AC 4 ms
4,728 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 5 ms
5,028 KB
testcase_33 AC 6 ms
5,088 KB
testcase_34 AC 6 ms
5,164 KB
testcase_35 AC 6 ms
5,080 KB
testcase_36 AC 6 ms
5,168 KB
testcase_37 AC 6 ms
5,032 KB
testcase_38 AC 6 ms
5,032 KB
testcase_39 AC 6 ms
5,152 KB
testcase_40 AC 6 ms
5,048 KB
testcase_41 AC 6 ms
5,096 KB
testcase_42 AC 6 ms
5,100 KB
testcase_43 AC 6 ms
5,100 KB
testcase_44 AC 6 ms
5,116 KB
testcase_45 AC 6 ms
5,104 KB
testcase_46 AC 6 ms
5,140 KB
testcase_47 AC 6 ms
5,088 KB
testcase_48 AC 6 ms
5,160 KB
testcase_49 AC 6 ms
5,036 KB
testcase_50 AC 6 ms
5,100 KB
testcase_51 AC 7 ms
5,172 KB
権限があれば一括ダウンロードができます

ソースコード

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, P; cin >> U >> D >> R >> L >> K >> P;
  ll xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
  string C[H]; rep(i,H) cin >> C[i];

  assert(2<=H && H<=100);
  assert(2<=W && W<=100);
  assert(0<=U && U<=100);
  assert(0<=D && D<=100);
  assert(0<=R && R<=100);
  assert(0<=L && L<=100);
  assert(0<=K && K<=pow(10,13));
  assert(0<=P && P<=pow(10,9));
  rep(i,H) rep(j,W) assert(C[i][j]=='.'||C[i][j]=='#'||C[i][j]=='@');
  assert(1<=xs && xs<=H);
  assert(1<=ys && ys<=W);
  assert(1<=xt && xt<=H);
  assert(1<=yt && yt<=W);
  assert(xs!=xt || ys!=yt);
  assert(C[xs-1][ys-1]=='.' && C[xt-1][yt-1]=='.');

  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), P+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), P+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), P+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), P+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