結果

問題 No.20 砂漠のオアシス
ユーザー SSRSSSRS
提出日時 2020-11-08 23:27:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,191 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 177,712 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 21:46:10
合計ジャッジ時間 4,847 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 100000;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  int N, V, Ox, Oy;
  cin >> N >> V >> Ox >> Oy;
  Ox--;
  Oy--;
  vector<vector<int>> L(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> L[i][j];
    }
  }
  vector<vector<int>> S1(N, vector<int>(N, INF));
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq1;
  pq1.push(make_tuple(L[0][0], 0, 0));
  while (!pq1.empty()){
    int c = get<0>(pq1.top());
    int y = get<1>(pq1.top());
    int x = get<2>(pq1.top());
    pq1.pop();
    if (S1[y][x] == INF){
      S1[y][x] = c;
      for (int i = 0; i < 4; i++){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N){
          if (S1[y2][x2] == INF){
            pq1.push(make_tuple(c + L[y2][x2], y2, x2));
          }
        }
      }
    }
  }
  if (Ox == -1 && Oy == -1){
    if (S1[N - 1][N - 1] < V){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  } else {
    assert(false);
    if (S1[N - 1][N - 1] < V){
      cout << "YES" << endl;
    } else if (S1[Oy][Ox] >= V){
      cout << "NO" << endl;
    } else {
      int V2 = (V - S1[Oy][Ox]) * 2;
      vector<vector<int>> S2(N, vector<int>(N, INF));
      priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq2;
      pq2.push(make_tuple(0, Oy, Ox));
      while (!pq2.empty()){
        int c = get<0>(pq2.top());
        int y = get<1>(pq2.top());
        int x = get<2>(pq2.top());
        pq2.pop();
        if (S2[y][x] == INF){
          S2[y][x] = c;
          for (int i = 0; i < 4; i++){
            int y2 = y + dy[i];
            int x2 = x + dx[i];
            if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N){
              if (S2[y2][x2] == INF){
                pq2.push(make_tuple(c + L[y2][x2], y2, x2));
              }
            }
          }
        }
      }
      if (S2[N - 1][N - 1] < V2){
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}
0