結果

問題 No.34 砂漠の行商人
ユーザー maimai
提出日時 2017-03-23 08:41:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,279 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 166,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 08:35:47
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

ll que[100000];
ll qb=0,qe=0;

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);

  
  hp+=mat[ssy][ssx]-1;
  dp[ssy][ssx]=hp;

  que[qb++]=((ssx<<8)|(ssy)|(hp<<32));

  ll d,x,y,s,h;
  while(qb!=qe){
    d=que[qb++];qb=qb%100000;
    x=(d>>8)&0xff;
    y=(d)&0xff;
    s=(d>>16)&0xffff;
    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;
      que[qb++]=((y-1)|((x)<<8)|(s<<16)|(h<<32));qb=qb%100000;
    }
    if (mat[y+1][x] && h>dp[y+1][x]){
      dp[y+1][x]=h;
      que[qb++]=((y+1)|((x)<<8)|(s<<16)|(h<<32));qb=qb%100000;
    }
    if (mat[y][x-1] && h>dp[y][x-1]){
      dp[y][x-1]=h;
      que[qb++]=((y)|((x-1)<<8)|(s<<16)|(h<<32));qb=qb%100000;
    }
    if (mat[y][x+1] && h>dp[y][x+1]){
      dp[y][x+1]=h;
      que[qb++]=((y)|((x+1)<<8)|(s<<16)|(h<<32));qb=qb%100000;
    }
  }
  
  cout<<"-1"<<endl;
  
  return 0;
}
0