結果
問題 | No.20 砂漠のオアシス |
ユーザー |
![]() |
提出日時 | 2019-03-28 01:26:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,721 bytes |
コンパイル時間 | 2,274 ms |
コンパイル使用メモリ | 182,924 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 06:17:33 |
合計ジャッジ時間 | 2,743 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 6 |
ソースコード
#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<ll>> graph, dist; void dijkstra(int sy, int sx) { dist[sy][sx] = 0; priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> pq; pq.push({ dist[sy][sx], {sy, sx} }); while (!pq.empty()) { ll nowCost = pq.top().first; ll y = pq.top().second.first; ll x = pq.top().second.second; pq.pop(); if (nowCost > dist[y][x]) { continue; } for (ll i = 0; i < 4; i++) { ll ny = y + dy[i]; ll 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} }); } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> v >> ox >> oy; graph.resize(n, vector<ll>(n)); dist.resize(n, vector<ll>(n, INT_MAX)); for (int y = 0; y < n; y++) { for (int x = 0; x < n; x++) { cin >> graph[y][x]; } } dijkstra(0, 0); if (dist[n - 1][n - 1] < v) { cout << "YES" << endl; return 0; } if (oy == -1 && ox == -1) { cout << "NO" << endl; return 0; } int healHp = (v - dist[oy][ox]) * 2; dijkstra(oy, ox); cout << ((healHp - dist[n - 1][n - 1] > 0) ? "YES" : "NO") << endl; return 0; }