結果

問題 No.20 砂漠のオアシス
ユーザー char134217728char134217728
提出日時 2019-01-19 15:41:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 1,781 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 181,512 KB
実行使用メモリ 8,124 KB
最終ジャッジ日時 2023-09-24 23:15:38
合計ジャッジ時間 3,093 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 21 ms
7,468 KB
testcase_06 AC 28 ms
8,124 KB
testcase_07 AC 27 ms
8,056 KB
testcase_08 AC 27 ms
8,004 KB
testcase_09 AC 26 ms
8,060 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:42:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   42 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define mp make_pair
#define pb push_back
typedef long long ll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
const int N = 200;
struct Dijk{
  typedef long long ll;
  const ll tinf = 1e18;
  int n;
  vector<ll> d;
  vector<int> p;
  void solve(const vector<vector<pair<int, ll>>>&E, int S, int G=-1){
    n = E.size();
    d = vector<ll>(n, tinf);
    p = vector<int>(n, -1);
    d[S] = 0;
    priority_queue<pair<ll, int>,vector<pair<ll, int>>,greater<pair<ll, int>>> Q;
    Q.push(pair<ll, int>(0, S));
    while(!Q.empty()){
      pair<ll, int> t=Q.top(); Q.pop();
      if(t.second == G) return;
      if(t.first > d[t.second]) continue;
      for(auto itr = E[t.second].begin(); itr != E[t.second].end(); itr++){
        ll k = t.first + itr->second;
        int m = itr->first;
        if(k < d[itr->first]){
          d[m] = k;
          p[m] = t.second;
          Q.push(pair<ll, int>(k, m));
        }
      }
    }
  }
} dijk;
int n, v, x, y, L[N][N];
VV<pair<int, ll>> E;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> v >> y >> x;
  E.resize(n*n);
  FOR(i, 0, n)FOR(j, 0, n) cin >> L[i][j];
  FOR(i, 0, n)FOR(j, 0, n){
    if(i < n-1){
      E[i*n+j].pb(mp((i+1)*n+j, L[i+1][j]));
      E[(i+1)*n+j].pb(mp(i*n+j, L[i][j]));
    }
    if(j < n-1){
      E[i*n+j].pb(mp(i*n+j+1, L[i][j+1]));
      E[i*n+j+1].pb(mp(i*n+j, L[i][j]));
    }
  }
  dijk.solve(E, 0);
  if(dijk.d[n*n-1] < v){
    cout << "YES" << endl;
    return 0;
  }
  if(x){
    x--; y--;
    int c = dijk.d[x*n+y];
    dijk.solve(E, x*n+y);
    if(dijk.d[n*n-1] < (v-c)*2){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
0