結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
👑 ![]() |
提出日時 | 2020-10-06 21:49:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 5,000 ms |
コード長 | 1,242 bytes |
コンパイル時間 | 2,873 ms |
コンパイル使用メモリ | 173,912 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 03:02:27 |
合計ジャッジ時間 | 3,319 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N, V; int G[200][200] = {}; int dp[200][200] = {}; int O[2]; void dijkstra(int sx, int sy) { rep(x, N) rep(y, N) dp[x][y] = -1; priority_queue<pair<int, pair<int, int>>> Q; Q.push({ 0,{sx,sy} }); while (Q.size()) { int d = Q.top().first; int x = Q.top().second.first; int y = Q.top().second.second; Q.pop(); if (dp[x][y] != -1) continue; dp[x][y] = -d; if (x != 0) Q.push({ d - G[x - 1][y],{x - 1,y} }); if (y != 0) Q.push({ d - G[x][y - 1],{x,y - 1} }); if (x != N - 1) Q.push({ d - G[x + 1][y],{x + 1,y} }); if (y != N - 1) Q.push({ d - G[x][y + 1],{x,y + 1} }); } } int main() { cin >> N >> V; cin >> O[0] >> O[1]; O[0]--; O[1]--; rep(y, N) rep(x, N) cin >> G[x][y]; dijkstra(0, 0); if (dp[N - 1][N - 1] < V) { cout << "YES" << endl; return 0; } if (O[0] == -1) { cout << "NO" << endl; return 0; } V = (V - dp[O[0]][O[1]]) * 2; dijkstra(O[0], O[1]); if (dp[N - 1][N - 1] < V) { cout << "YES" << endl; return 0; } cout << "NO" << endl; return 0; }