結果

問題 No.34 砂漠の行商人
ユーザー goodbatongoodbaton
提出日時 2015-07-30 23:35:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 308 ms / 5,000 ms
コード長 1,754 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 19:10:27
合計ジャッジ時間 2,081 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 308 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 149 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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];
int dp[10000][102][102]={0};
priority_queue<pair<pair<int,int>,pair<int,int> > > pq;


int main(){
    int af_x,af_y;
    bool f;
    
    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;
    }
    
    dp[0][sx][sy] = v;
    
    for(int i=1;i<10000;i++){
        f = false;
        memset(dp[1],0,sizeof(dp[1]));
        
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                
                if(dp[0][i][j]==0) continue;
                
                f = true;
                
                for(int k=0;k<4;k++){
                    af_x = i + mo[k];
                    af_y = j + mo[k+1];
                    dp[1][af_x][af_y]=max(dp[1][af_x][af_y],dp[0][i][j]-l[af_x][af_y]);
                }
                
            }
        }
        
        if(dp[1][gx][gy]>0){
            printf("%d\n",i);
            return 0;
        }
        
        if(!f) break;
        
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dp[0][i][j]=dp[1][i][j];
            }
        }
        
    }
    
    puts("-1");
    
    return 0;
}
0