結果

問題 No.34 砂漠の行商人
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-04-08 21:34:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,888 bytes
コンパイル時間 10,063 ms
コンパイル使用メモリ 351,400 KB
実行使用メモリ 123,796 KB
最終ジャッジ日時 2024-04-08 21:35:06
合計ジャッジ時間 18,372 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 9 ms
6,676 KB
testcase_03 AC 31 ms
6,676 KB
testcase_04 AC 214 ms
14,720 KB
testcase_05 AC 208 ms
14,464 KB
testcase_06 AC 12 ms
6,676 KB
testcase_07 AC 381 ms
21,376 KB
testcase_08 AC 588 ms
27,776 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <atcoder/all>


using namespace std;
using namespace atcoder;
#define rep(i,m,n,k) for (int i = (int)(m); i < (int)(n); i += (int)(k))
#define rrep(i,m,n,k) for (int i = (int)(m); i > (int)(n); i += (int)(k))
#define all(x) x.begin(),x.end()
#define ll long long
#define list(T,A,N) vector<T> A(N);for(int i=0;i<(int)(N);i++){cin >> A[i];}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
// #define int long long


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N,V,sx,sy,gx,gy;
    cin >> N >> V >> sx >> sy >> gx >> gy;
    vector<vector<int>> L(N,vector<int> (N));
    rep(i,0,N,1){
        rep(j,0,N,1){
            cin >> L[j][i];
        }
    }
    vector<pair<int,int>> dxy = {{-1,0},{1,0},{0,1},{0,-1}};
    map<pair<pair<int,int>,int>,int> val;
    sx -=1;
    sy -=1;
    gx -=1;
    gy -=1;
    val[{{sx,sy},V}] = 1;
    queue<pair<pair<int,int>,int>> v;
    v.push({{sx,sy},V});
    while(!v.empty()){
        auto [xy,m] = v.front();
        v.pop();
        auto [x,y] = xy;
        for(auto [dx,dy]:dxy){
            if((x+dx>=N)||(y+dy>=N)||(x+dx<0)||(y+dy<0)) continue;
            if(m-L[x+dx][y+dy]<=0) continue;
            if(val[{{x+dx,y+dy},m-L[x+dx][y+dy]}]!=0) continue;
            val[{{x+dx,y+dy},m-L[x+dx][y+dy]}] = val[{{x,y},m}]+1;
            v.push({{x+dx,y+dy},m-L[x+dx][y+dy]});
        }
    }
    int ans = N*N + 1;
    rep(i,1,V+1,1){
        if(val[{{gx,gy},i}]!=0){
            chmin(ans,val[{{gx,gy},i}]-1);
        }
    }
    if(ans==N*N+1){
        cout << -1 << endl; 
        return 0;
        }
    cout << ans << endl;
    return 0;

    return 0;
}

0