結果

問題 No.20 砂漠のオアシス
ユーザー imgry22imgry22
提出日時 2015-02-06 00:58:15
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,116 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 164,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:21:27
合計ジャッジ時間 2,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 8 ms
6,940 KB
testcase_07 AC 25 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,948 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 5 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 200;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int N, V;
int sx, sy;
int gx, gy;
int ox, oy;
int L[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];
int p, n;

inline bool check(int hx, int hy){ return 0<=hx&&hx<N && 0<=hy&&hy<N; }

int dfs(int sx, int sy, int gx, int gy, int V)
{
  rep(i, N) rep(j, N) dp[i][j] = 0;
  queue<pii> que;
  que.push(mp(sx, sy));
  dp[sx][sy] = V;
  while(!que.empty()){
    pii here = que.front();  que.pop();
    int hx = here.first;
    int hy = here.second;
    if(hx == gx && hy == gy) return dp[gx][gy];
    rep(k, 4){
      int nx = hx + dx[k];
      int ny = hy + dy[k];
      if(!check(nx, ny)) continue;
      if(dp[nx][ny] < dp[hx][hy] - L[nx][ny] && dp[hx][hy] - L[nx][ny] > 0){
        dp[nx][ny] = dp[hx][hy] - L[nx][ny];
        que.push(mp(nx, ny));
      }
    }
  }
  return -1;
}

int main()
{
  cin >> N  >> V;
  cin >> ox >> oy;
  rep(i, N) rep(j, N) cin >> L[i][j];
  //rep(i, N) rep(j, N) dp[i][j] = INF;

  gx = N - 1;  gy = N - 1;
  ox -= 1;     oy -= 1;

  if(dfs(sx, sy, gx, gy, V) > 0){
    cout << "YES" << endl;
    return 0;
  }
  if((p = dfs(sx, sy, ox, oy, V)) > 0){
    if(dfs(ox, oy, gx, gy, p + p) > 0){
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}
0