結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
![]() |
提出日時 | 2018-06-23 18:20:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,100 bytes |
コンパイル時間 | 1,805 ms |
コンパイル使用メモリ | 179,068 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 18:30:13 |
合計ジャッジ時間 | 3,104 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 7 RE * 2 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 }; int N, V, Ox, Oy, L[202][202]; //--------------------------------------------------------------------------------------------------- int vis[202][202]; void dji(int sx, int sy, vector<vector<int>> &d) { rep(y, 0, N) rep(x, 0, N) d[y][x] = inf; rep(y, 0, N) rep(x, 0, N) vis[y][x] = 0; min_priority_queue<pair<int, int>> que; que.push({ 0, sy * N + sx }); d[sy][sx] = 0; while (!que.empty()) { auto q = que.top(); que.pop(); int c = q.first; int x = q.second % N; int y = q.second / N; if (vis[y][x]) continue; vis[y][x] = 1; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (0 <= xx and xx < N and 0 <= yy and yy < N) if(!vis[yy][xx]) { if (d[y][x] + L[yy][xx] < d[yy][xx]) { d[yy][xx] = d[y][x] + L[yy][xx]; que.push({ d[yy][xx], yy * N + xx }); } } } } } //--------------------------------------------------------------------------------------------------- #define yes "YES" #define no "NO" string solve() { vector<vector<int>> d1(N, vector<int>(N)); dji(0, 0, d1); vector<vector<int>> d2(N, vector<int>(N)); dji(Ox, Oy, d2); // start -> goal if (d1[N - 1][N - 1] <= V) return yes; // start -> oasis -> goal if (d1[Oy][Ox] <= V and d1[Oy][Ox] + d2[N-1][N-1] <= (V - d1[Oy][Ox]) * 2) return yes; return no; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> V >> Ox >> Oy; Ox--; Oy--; rep(y, 0, N) rep(x, 0, N) cin >> L[y][x]; cout << solve() << endl; }