結果

問題 No.34 砂漠の行商人
ユーザー parukiparuki
提出日時 2016-10-07 17:09:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,166 ms / 5,000 ms
コード長 1,383 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 174,672 KB
実行使用メモリ 60,840 KB
最終ジャッジ日時 2023-09-10 19:25:39
合計ジャッジ時間 7,809 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 5 ms
5,320 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 20 ms
12,292 KB
testcase_05 AC 24 ms
15,536 KB
testcase_06 AC 10 ms
10,108 KB
testcase_07 AC 40 ms
24,192 KB
testcase_08 AC 50 ms
28,104 KB
testcase_09 AC 336 ms
32,484 KB
testcase_10 AC 44 ms
23,620 KB
testcase_11 AC 1,166 ms
58,304 KB
testcase_12 AC 14 ms
8,708 KB
testcase_13 AC 1,165 ms
60,840 KB
testcase_14 AC 858 ms
54,960 KB
testcase_15 AC 5 ms
5,020 KB
testcase_16 AC 55 ms
14,408 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 8 ms
5,460 KB
testcase_19 AC 252 ms
38,516 KB
testcase_20 AC 436 ms
46,304 KB
testcase_21 AC 5 ms
5,184 KB
testcase_22 AC 10 ms
7,040 KB
testcase_23 AC 5 ms
4,884 KB
testcase_24 AC 616 ms
49,364 KB
testcase_25 AC 36 ms
12,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define mt make_tuple
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int DY[] = {-1,0,1,0};
const int DX[] = {0,1,0,-1};

int N, V, SX, SY, GX, GY, L[100][100];
bool vis[100][100][10001];

int main(){
    cin >> N >> V >> SX >> SY >> GX >> GY;
    --SX; --SY; --GX; --GY;
    rep(i, N)rep(j, N)scanf("%d", &L[i][j]);

    queue<tuple<int, int, int, int>> q;
    q.push(mt(0, SY, SX, V));
    while(sz(q)){
        int d, y, x, v;
        tie(d, y, x, v) = q.front(); q.pop();
        if(y == GY&&x == GX){
            cout << d << endl;
            return 0;
        }
        if(vis[y][x][v])continue;
        vis[y][x][v] = 1;
        rep(i, 4){
            int ny = DY[i] + y, nx = DX[i] + x;
            if(ny >= 0 && ny < N&&nx >= 0 && nx < N){
                int nv = v - L[ny][nx];
                if(nv > 0 && !vis[ny][nx][nv])q.push(mt(d + 1, ny, nx, nv));
            }
        }
    }
    puts("-1");
}
0