結果
問題 | No.20 砂漠のオアシス |
ユーザー |
![]() |
提出日時 | 2019-03-28 01:40:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,837 bytes |
コンパイル時間 | 2,112 ms |
コンパイル使用メモリ | 181,828 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 06:17:39 |
合計ジャッジ時間 | 3,185 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 WA * 1 RE * 1 |
ソースコード
#include "bits/stdc++.h"using namespace std;using ll = long long;using ld = long double;const double PI = 3.1415926535897932384626433832795;const int dx[] = { 0, 1, 0, -1 };const int dy[] = { -1, 0, 1, 0 };int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }int lcm(int x, int y) { return x / gcd(x, y) * y; }ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }int n, v, ox, oy;vector<vector<int>> graph;vector<vector<int>> dijkstra(int sy, int sx) {vector<vector<int>> dist(n, vector<int>(n, INT_MAX));dist[sy][sx] = 0;priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;pq.push({ dist[sy][sx], {sy, sx} });while (!pq.empty()) {int nowCost = pq.top().first;int y = pq.top().second.first;int x = pq.top().second.second;pq.pop();if (nowCost > dist[y][x]) {continue;}for (int i = 0; i < 4; i++) {int ny = y + dy[i];int nx = x + dx[i];if (ny < 0 || ny >= n || nx < 0 || nx >= n) {continue;}if (dist[ny][nx] > nowCost + graph[ny][nx]) {dist[ny][nx] = nowCost + graph[ny][nx];pq.push({ dist[ny][nx] , {ny, nx} });}}}return dist;}int main() {ios::sync_with_stdio(false);cin.tie(0);cin >> n >> v >> ox >> oy;ox--; oy--;graph.resize(n, vector<int>(n));for (int y = 0; y < n; y++) {for (int x = 0; x < n; x++) {cin >> graph[y][x];}}vector<vector<int>> dist = dijkstra(0, 0);if (dist[n - 1][n - 1] < v) {cout << "YES" << endl;return 0;}if (oy == 0 || ox == 0) {cout << "NO" << endl;return 0;}int healHp = (v - dist[oy][ox]) * 2;vector<vector<int>> dist2 = dijkstra(oy, ox);cout << ((dist2[n - 1][n - 1] < healHp) ? "YES" : "NO") << endl;return 0;}