結果

問題 No.34 砂漠の行商人
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-04-08 21:55:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,861 bytes
コンパイル時間 3,404 ms
コンパイル使用メモリ 262,140 KB
実行使用メモリ 454,700 KB
最終ジャッジ日時 2024-04-08 21:56:07
合計ジャッジ時間 16,910 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 60 ms
9,908 KB
testcase_05 AC 60 ms
10,036 KB
testcase_06 AC 5 ms
6,676 KB
testcase_07 AC 100 ms
14,944 KB
testcase_08 AC 170 ms
22,536 KB
testcase_09 AC 2,287 ms
182,744 KB
testcase_10 AC 123 ms
22,576 KB
testcase_11 AC 3,919 ms
394,424 KB
testcase_12 AC 37 ms
8,012 KB
testcase_13 TLE -
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> inline bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> inline 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}};
    unordered_map<int,int> val;
    sx -=1;
    sy -=1;
    gx -=1;
    gy -=1;
    int N2 = N*N;
    val[sx+N*sy+N2*V] = 1;
    queue<int> v;
    v.push(sx+N*sy+N2*V);
    while(!v.empty()){
        auto xym = v.front();
        v.pop();
        auto m = xym/N2;
        auto y = xym%N2/N;
        auto x = xym%N;
        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+N*(y+dy)+(m-L[x+dx][y+dy])*N2]!=0) continue;
            if((x+dx==gx)&&(y+dy==gy)){
                cout << val[xym] << endl;
                return 0;
            }
            val[x+dx+N*(y+dy)+(m-L[x+dx][y+dy])*N2] = val[xym]+1;
            v.push(x+dx+N*(y+dy)+(m-L[x+dx][y+dy])*N2);
        }
    }
    cout << -1 << endl;

    return 0;

}


0