結果

問題 No.34 砂漠の行商人
ユーザー latte0119latte0119
提出日時 2016-02-26 01:16:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,493 bytes
コンパイル時間 3,178 ms
コンパイル使用メモリ 165,076 KB
実行使用メモリ 814,688 KB
最終ジャッジ日時 2023-10-23 20:11:11
合計ジャッジ時間 5,870 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
159,996 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 45 ms
159,996 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 MLE -
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 #

#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--;
    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>=2000||dist[ny][nx]<=dist[d.y][d.x]+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,min(V,2000ll))chmin(mi,dist[gy][gx][i]);
    if(mi==(1<<25))cout<<-1<<endl;
    else cout<<mi<<endl;
    return 0;
}
0