結果

問題 No.20 砂漠のオアシス
ユーザー どららどらら
提出日時 2015-06-04 00:35:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,726 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 86,180 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:32:15
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 1000000000

int N;
int L[205][205];

int vx[4] = {0,0,1,-1};
int vy[4] = {1,-1,0,0};

struct ST {
  int x, y, v;
};
bool operator>(const ST& a, const ST& b){
  return a.v > b.v;
}

int dijkstra(int sx, int sy, int gx, int gy){
  bool visited[205][205];
  int cost[205][205];
 
  REP(i,1,N+1){
    REP(j,1,N+1){
      cost[i][j] = INF;
      visited[i][j] = false;
    }
  }
  cost[sy][sx] = 0;

  priority_queue<ST, vector<ST>, greater<ST> > q;
  q.push((ST){sx,sy,0});
  while(!q.empty()){
    ST st = q.top(); q.pop();

    if(visited[st.y][st.x]) continue;
    visited[st.y][st.x] = true;
    
    if(st.x == gx && st.y == gy) return st.v;
 
    rep(k,4){
      int nx = st.x + vx[k], ny = st.y + vy[k];
      if(1<=nx&&nx<=N && 1<=ny&&ny<=N){
        q.push((ST){nx,ny,cost[st.y][st.x]+L[ny][nx]});
      }
    }
  }
  return INF;
}


int main(){
  int V, Ox, Oy;
  cin >> N >> V >> Ox >> Oy;
  REP(i,1,N+1){
    REP(j,1,N+1){
      cin >> L[i][j];
    }
  }

  int ret1 = V - dijkstra(1,1,N,N);
  int ret2 = 0;
  if(Ox>=1){
    int a = V-dijkstra(1,1,Ox,Oy);
    if(a>=0){
      ret2 = 2*a - dijkstra(Ox,Oy,N,N);
    }
  }
  if(max(ret1, ret2) > 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
0