結果

問題 No.34 砂漠の行商人
ユーザー latte0119latte0119
提出日時 2016-02-26 01:21:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,330 ms / 5,000 ms
コード長 1,506 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 148,764 KB
実行使用メモリ 162,388 KB
最終ジャッジ日時 2023-09-10 19:20:44
合計ジャッジ時間 13,462 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
159,556 KB
testcase_01 AC 49 ms
159,616 KB
testcase_02 AC 48 ms
159,640 KB
testcase_03 AC 49 ms
159,752 KB
testcase_04 AC 56 ms
159,808 KB
testcase_05 AC 57 ms
159,816 KB
testcase_06 AC 49 ms
159,892 KB
testcase_07 AC 62 ms
159,752 KB
testcase_08 AC 68 ms
159,872 KB
testcase_09 AC 700 ms
161,228 KB
testcase_10 AC 1,330 ms
159,984 KB
testcase_11 AC 837 ms
161,624 KB
testcase_12 AC 57 ms
159,876 KB
testcase_13 AC 1,300 ms
162,388 KB
testcase_14 AC 1,313 ms
162,260 KB
testcase_15 AC 344 ms
160,676 KB
testcase_16 AC 334 ms
160,448 KB
testcase_17 AC 424 ms
161,228 KB
testcase_18 AC 103 ms
159,708 KB
testcase_19 AC 263 ms
161,992 KB
testcase_20 AC 481 ms
162,188 KB
testcase_21 AC 49 ms
159,772 KB
testcase_22 AC 566 ms
161,636 KB
testcase_23 AC 467 ms
160,728 KB
testcase_24 AC 1,199 ms
162,152 KB
testcase_25 AC 80 ms
160,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ln <<endl
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

struct data{
    int y,x,h;
    data(int y,int x,int h):y(y),x(x),h(h){}
};

int dxy[]={0,-1,0,1,0};

int N,V,sx,sy,gx,gy;
int L[100][100];
int dist[100][100][2000];
signed main(){
    cin>>N>>V>>sx>>sy>>gx>>gy;sx--;sy--;gx--;gy--;
    chmin(V,2000);
    rep(i,N)rep(j,N)cin>>L[i][j];

    queue<data>que;
    que.push(data(sy,sx,0));
    fill_n(**dist,100*100*2000,1<<25);
    dist[sy][sx][0]=0;

    while(que.size()){
        data d=que.front();que.pop();
        rep(i,4){
            int ny=d.y+dxy[i],nx=d.x+dxy[i+1];
            if(ny<0||ny>=N||nx<0||nx>=N)continue;
            int nh=d.h+L[ny][nx];
            if(nh>=V||dist[ny][nx][nh]<=dist[d.y][d.x][d.h]+1)continue;
            dist[ny][nx][nh]=dist[d.y][d.x][d.h]+1;
            que.push(data(ny,nx,nh));
        }
    }

    int mi=1<<25;
    rep(i,V)chmin(mi,dist[gy][gx][i]);
    if(mi==(1<<25))cout<<-1<<endl;
    else cout<<mi<<endl;
    return 0;
}
0