結果

問題 No.1638 Robot Maze
ユーザー outlineoutline
提出日時 2021-08-06 21:44:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 496 ms / 2,000 ms
コード長 2,810 bytes
コンパイル時間 3,067 ms
コンパイル使用メモリ 149,360 KB
実行使用メモリ 29,404 KB
最終ジャッジ日時 2023-10-17 03:02:38
合計ジャッジ時間 11,731 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 228 ms
28,892 KB
testcase_04 AC 3 ms
5,772 KB
testcase_05 AC 3 ms
5,704 KB
testcase_06 AC 3 ms
5,772 KB
testcase_07 AC 3 ms
5,772 KB
testcase_08 AC 3 ms
5,772 KB
testcase_09 AC 3 ms
5,772 KB
testcase_10 AC 3 ms
5,772 KB
testcase_11 AC 3 ms
5,772 KB
testcase_12 AC 3 ms
5,772 KB
testcase_13 AC 3 ms
5,772 KB
testcase_14 AC 164 ms
28,896 KB
testcase_15 AC 74 ms
28,892 KB
testcase_16 AC 75 ms
28,824 KB
testcase_17 AC 75 ms
28,896 KB
testcase_18 AC 9 ms
28,820 KB
testcase_19 AC 38 ms
28,948 KB
testcase_20 AC 39 ms
28,948 KB
testcase_21 AC 11 ms
28,832 KB
testcase_22 AC 10 ms
28,820 KB
testcase_23 AC 69 ms
28,888 KB
testcase_24 AC 11 ms
28,832 KB
testcase_25 AC 11 ms
28,832 KB
testcase_26 AC 79 ms
28,888 KB
testcase_27 AC 79 ms
28,820 KB
testcase_28 AC 75 ms
28,820 KB
testcase_29 AC 74 ms
28,888 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 232 ms
28,908 KB
testcase_33 AC 320 ms
29,016 KB
testcase_34 AC 348 ms
29,012 KB
testcase_35 AC 302 ms
28,968 KB
testcase_36 AC 372 ms
28,948 KB
testcase_37 AC 229 ms
28,908 KB
testcase_38 AC 337 ms
29,016 KB
testcase_39 AC 496 ms
29,044 KB
testcase_40 AC 309 ms
28,964 KB
testcase_41 AC 384 ms
29,016 KB
testcase_42 AC 399 ms
28,948 KB
testcase_43 AC 495 ms
29,044 KB
testcase_44 AC 464 ms
29,404 KB
testcase_45 AC 436 ms
29,044 KB
testcase_46 AC 422 ms
29,044 KB
testcase_47 AC 393 ms
29,044 KB
testcase_48 AC 375 ms
28,948 KB
testcase_49 AC 305 ms
28,868 KB
testcase_50 AC 374 ms
28,948 KB
testcase_51 AC 403 ms
29,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

constexpr int dx[4] = {-1, 1, 0, 0};
constexpr int dy[4] = {0, 0, 1, -1};

constexpr ll inf = 1e+17;
ll dp[105][105][305];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int H, W, P, sx, sy, tx, ty;
    ll K;
    vector<int> cost(4);
    cin >> H >> W;
    for(int i = 0; i < 4; ++i)  cin >> cost[i];
    cin >> K >> P >> sx >> sy >> tx >> ty;
    --sx, --sy, --tx, --ty;
    vector<string> s(H);
    for(int i = 0; i < H; ++i)  cin >> s[i];

    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            for(int k = 0; k <= 205; ++k){
                dp[i][j][k] = inf;
            }
        }
    }

    dp[sx][sy][0] = 0;
    using node = tuple<ll, int, int, int>;
    priority_queue<node, vector<node>, greater<node>> que;
    que.emplace(0, sx, sy, 0);
    while(!que.empty()){
        auto [d, x, y, cnt] = que.top();
        que.pop();
        if(d > dp[x][y][cnt])   continue;
        for(int i = 0; i < 4; ++i){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W)  continue;
            if(s[nx][ny] == '#')    continue;
            if(s[nx][ny] == '.'){
                if(chmin(dp[nx][ny][cnt], dp[x][y][cnt] + cost[i])){
                    que.emplace(dp[nx][ny][cnt], nx, ny, cnt);
                }
            }
            else{
                if(cnt < 205 && chmin(dp[nx][ny][cnt + 1], dp[x][y][cnt] + cost[i] + P)){
                    que.emplace(dp[nx][ny][cnt + 1], nx, ny, cnt + 1);
                }
            }
        }
    }

    for(int i = 0; i <= 205; ++i){
        if(dp[tx][ty][i] <= K)  return puts("Yes") & 0;
    }
    cout << "No\n";

    return 0;
}
0