結果

問題 No.20 砂漠のオアシス
ユーザー どららどらら
提出日時 2015-06-04 00:26:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,973 ms / 5,000 ms
コード長 1,783 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 75,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 07:36:09
合計ジャッジ時間 18,165 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 19 ms
4,384 KB
testcase_05 AC 3,973 ms
4,380 KB
testcase_06 AC 3,077 ms
4,384 KB
testcase_07 AC 3,088 ms
4,380 KB
testcase_08 AC 2,457 ms
4,384 KB
testcase_09 AC 3,165 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 14 ms
4,384 KB
testcase_14 AC 38 ms
4,380 KB
testcase_15 AC 21 ms
4,384 KB
testcase_16 AC 170 ms
4,380 KB
testcase_17 AC 87 ms
4,384 KB
testcase_18 AC 129 ms
4,384 KB
testcase_19 AC 180 ms
4,380 KB
testcase_20 AC 4 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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

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;
 
  while(true){
    int minx, miny, minVal = INF;

    REP(i,1,N+1){
      REP(j,1,N+1){
        if(minVal>cost[i][j] && !visited[i][j]){
          minVal = cost[i][j];
          miny = i;
          minx = j;
        }
      }
    }
 
    if(minVal == INF) return INF;
    if(minx == gx && miny == gy) return minVal;
    
    visited[miny][minx] = true;
 
    rep(k,4){
      int nx = minx + vx[k], ny = miny + vy[k];
      if(1<=nx&&nx<=N && 1<=ny&&ny<=N){
        if(cost[ny][nx]>cost[miny][minx]+L[ny][nx]){
          cost[ny][nx] = cost[miny][minx]+L[ny][nx];
        }
      }
    }
  }
}


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