結果

問題 No.34 砂漠の行商人
ユーザー goodbatongoodbaton
提出日時 2015-07-30 23:09:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 79,408 KB
実行使用メモリ 52,936 KB
最終ジャッジ日時 2023-09-24 22:23:09
合計ジャッジ時間 13,809 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 9 ms
5,584 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 154 ms
12,368 KB
testcase_05 AC 154 ms
15,444 KB
testcase_06 AC 15 ms
10,324 KB
testcase_07 AC 257 ms
23,940 KB
testcase_08 AC 351 ms
28,228 KB
testcase_09 AC 4,926 ms
33,516 KB
testcase_10 AC 334 ms
23,972 KB
testcase_11 TLE -
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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 10000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int mo[5] = {0,1,0,-1,0};

int n,v,sx,sy,gx,gy;
int l[102][102];
bool visit[102][102][10001]={0};
priority_queue<pair<pair<int,int>,pair<int,int> > > pq;


int main(){
    
    scanf("%d%d%d%d%d%d",&n,&v,&sx,&sy,&gx,&gy);
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            scanf("%d",&l[j][i]);
        }
    }
    
    for(int i=0;i<=n;i++){
        l[i][0]=INF;
        l[i][n+1]=INF;
        l[0][i]=INF;
        l[n+1][i]=INF;
    }
    
    pq.push({{0,v},{sx,sy}});
    
    while(pq.size()){
        pair<pair<int,int>,pair<int,int> > p = pq.top();
        pq.pop();
        
        int now_v = p.first.second;
        int now_c = p.first.first;
        int now_x = p.second.first;
        int now_y = p.second.second;
        int af_x,af_y;
        
        
        if(now_v<=0) continue;
        if(visit[now_x][now_y][now_v]) continue;
        
        visit[now_x][now_y][now_v] = true;
        
        if(now_x==gx && now_y==gy){
            printf("%d\n",-now_c);
            return 0;
        }
        
        for(int i=0;i<4;i++){
            
            af_x = now_x + mo[i];
            af_y = now_y + mo[i+1];
            
            pq.push({{now_c-1,now_v-l[af_x][af_y]},{af_x,af_y}});
        }
        
    }
    
    puts("-1");
    
    return 0;
}
0