結果

問題 No.34 砂漠の行商人
ユーザー 0w10w1
提出日時 2016-12-10 22:45:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 178,392 KB
実行使用メモリ 75,488 KB
最終ジャッジ日時 2023-08-19 10:38:04
合計ジャッジ時間 7,292 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
73,692 KB
testcase_01 AC 21 ms
73,676 KB
testcase_02 AC 22 ms
73,752 KB
testcase_03 AC 21 ms
73,780 KB
testcase_04 AC 28 ms
73,768 KB
testcase_05 AC 29 ms
73,932 KB
testcase_06 AC 21 ms
73,712 KB
testcase_07 AC 33 ms
73,776 KB
testcase_08 AC 38 ms
73,980 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 26 ms
74,024 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 22 ms
73,728 KB
testcase_18 RE -
testcase_19 AC 204 ms
75,332 KB
testcase_20 AC 370 ms
75,488 KB
testcase_21 AC 22 ms
73,800 KB
testcase_22 AC 25 ms
74,156 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 41 ms
73,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, V, Sx, Sy, Gx, Gy;
vvi LV;

void init(){
  cin >> N >> V >> Sx >> Sy >> Gx >> Gy;
  --Sx, --Sy, --Gx, --Gy;
  swap( Sx, Sy ), swap( Gx, Gy );
  LV = vvi( N, vi( N ) );
  for( int i = 0; i < N; ++i )
    for( int j = 0; j < N; ++j )
      cin >> LV[ i ][ j ];
}

int dis[ 1800 ][ 100 ][ 100 ];

void preprocess(){
  memset( dis, INF, sizeof( dis ) );
  typedef tuple< int, int, int, int > t4i;
  queue< t4i > que;
  que.emplace( dis[ V ][ Sx ][ Sy ] = 0, V, Sx, Sy );
  while( not que.empty() ){
    int d, v, x, y; tie( d, v, x, y ) = que.front(); que.pop();
    if( dis[ v ][ x ][ y ] != d ) continue;
    if( x == Gx and y == Gy )
      cout << d << endl, exit( 0 );
    const int dx[] = { 0, 1, 0, -1 };
    const int dy[] = { 1, 0, -1, 0 };
    for( int di = 0; di < 4; ++di ){
      int nx = x + dx[ di ];
      int ny = y + dy[ di ];
      if( not ( 0 <= nx and nx < N and 0 <= ny and ny < N ) ) continue;
      if( v - LV[ nx ][ ny ] <= 0 ) continue;
      if( upmin( dis[ v - LV[ nx ][ ny ] ][ nx ][ ny ], dis[ v ][ x ][ y ] + 1 ) )
        que.emplace( dis[ v - LV[ nx ][ ny ] ][ nx ][ ny ], v - LV[ nx ][ ny ], nx, ny );
    }
  }
  cout << -1 << endl;
}

void solve(){

}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0