結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
81,804 KB
testcase_01 AC 24 ms
81,808 KB
testcase_02 AC 45 ms
81,932 KB
testcase_03 AC 39 ms
81,912 KB
testcase_04 AC 151 ms
82,564 KB
testcase_05 AC 216 ms
82,444 KB
testcase_06 AC 139 ms
81,904 KB
testcase_07 AC 308 ms
82,504 KB
testcase_08 AC 394 ms
83,068 KB
testcase_09 AC 298 ms
83,424 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 160 ms
82,536 KB
testcase_13 WA -
testcase_14 AC 453 ms
84,332 KB
testcase_15 AC 166 ms
82,620 KB
testcase_16 AC 163 ms
82,584 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 510 ms
84,208 KB
testcase_20 AC 474 ms
84,164 KB
testcase_21 AC 482 ms
84,384 KB
testcase_22 AC 472 ms
84,056 KB
testcase_23 WA -
testcase_24 AC 472 ms
84,268 KB
testcase_25 AC 290 ms
83,192 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][1000];
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*1000,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],nh=d.h+L[ny][nx];
            if(ny<0||ny>=N||nx<0||nx>=N||nh>=1000||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