結果
| 問題 | 
                            No.20 砂漠のオアシス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             imgry22
                         | 
                    
| 提出日時 | 2015-02-05 21:38:02 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,427 bytes | 
| コンパイル時間 | 1,370 ms | 
| コンパイル使用メモリ | 166,752 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:00:28 | 
| 合計ジャッジ時間 | 2,158 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 5 | 
ソースコード
#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];
bool used[MAX_N][MAX_N];
inline bool check(int hx, int hy){ return 0<=hx&&hx<N && 0<=hy&&hy<N; }
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;
  queue<pair<pii, pair<int, bool> > > que;
  que.push(mp(mp(sx, sy), mp(V, false)));
  dp[sx][sy] = V;
  while(!que.empty()){
    //cout << que.size() << endl;
    pair<pii, pair<int, bool> > top = que.front();  que.pop();
    pii here = top.first;
    int v = top.second.first;
    bool flag = top.second.second;
    int hx = here.first;
    int hy = here.second;
    if(hx == gx && hy == gy){
      cout << "YES" << endl;
      return 0;
    }
    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];
        if(nx == ox && ny == oy && !flag){
          que.push(mp(mp(nx, ny), mp(v * 2, true)));
          dp[nx][ny] *= 2;
          used[nx][ny] = true;
        }
        else{
          que.push(mp(mp(nx, ny), mp(v, flag)));
        }
      }
      else if(dp[nx][ny] == dp[hx][hy] - L[nx][ny]){
        if(used[nx][ny]){
          que.push(mp(mp(nx, ny), mp(v, false)));
          used[nx][ny] = false;
        }
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
            
            
            
        
            
imgry22