結果

問題 No.34 砂漠の行商人
ユーザー maimai
提出日時 2017-03-18 08:00:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 171,136 KB
実行使用メモリ 814,676 KB
最終ジャッジ日時 2023-09-17 21:53:11
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

typedef long long int ll;

using namespace std;

int mat[111][111];
int dp[111][111];
ll n,hp,ssx,ssy,ggx,ggy;


int main(){
  cin>>n>>hp>>ssx>>ssy>>ggx>>ggy;
  
  for(int y=1;y<=n;++y){
    for(int x=1;x<=n;++x){
      scanf("%d",&(mat[y][x]));
      ++mat[y][x];
    }}
  //fill(&dp[0][0],&dp[110][110]+1,101010);

  queue<ll> q;

  q.push((ssx<<8)|(ssy)|(hp<<32));

  while(!q.empty()){
    ll d=q.front();q.pop();
    ll x=(d>>8)&0xff;
    ll y=(d)&0xff;
    ll s=(d>>16)&0xffff;
    ll h=(d>>32)&0xffff;
    
    if ((h-=mat[y][x]-1)<=0) continue;
    if (x==ggx && y==ggy){
      cout << s << endl;
      exit(0);
    }
    ++s;
    if (mat[y-1][x] && h>=dp[y-1][x]){
      dp[y-1][x]=h;
      q.push((y-1)|((x)<<8)|(s<<16)|(h<<32));
    }
    if (mat[y+1][x] && h>=dp[y+1][x]){
      dp[y+1][x]=h;
      q.push((y+1)|((x)<<8)|(s<<16)|(h<<32));
    }
    if (mat[y][x-1] && h>=dp[y][x-1]){
      dp[y][x-1]=h;
      q.push((y)|((x-1)<<8)|(s<<16)|(h<<32));
    }
    if (mat[y][x+1] && h>=dp[y][x+1]){
      dp[y][x+1]=h;
      q.push((y)|((x+1)<<8)|(s<<16)|(h<<32));
    }
  }
  
  cout<<"-1"<<endl;
  
  return 0;
}
0