結果

問題 No.34 砂漠の行商人
ユーザー maimai
提出日時 2017-03-18 16:56:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 174,960 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-07-04 19:13:45
合計ジャッジ時間 3,730 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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

  priority_queue<ll,vector<ll>,greater<ll> > q;

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

  while(!q.empty()){
    ll d=q.top();q.pop();
    ll x=(d>>8)&0xff;
    ll y=(d)&0xff;
    ll s=(d>>32)&0xffff;
    ll h=(d>>16)&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<<32)|(h<<16));
    }
    if (mat[y+1][x] && h>dp[y+1][x]){
      dp[y+1][x]=h;
      q.push((y+1)|((x)<<8)|(s<<32)|(h<<16));
    }
    if (mat[y][x-1] && h>dp[y][x-1]){
      dp[y][x-1]=h;
      q.push((y)|((x-1)<<8)|(s<<32)|(h<<16));
    }
    if (mat[y][x+1] && h>dp[y][x+1]){
      dp[y][x+1]=h;
      q.push((y)|((x+1)<<8)|(s<<32)|(h<<16));
    }
  }
  
  cout<<"-1"<<endl;
  for (int y=1;y<=n;++y){
    for (int x=1;x<=n;++x){
      cerr<<dp[y][x];
    }
    cerr<<endl;
  }
  
  return 0;
}
0