結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
uenoku
|
| 提出日時 | 2017-01-07 11:55:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,894 bytes |
| コンパイル時間 | 613 ms |
| コンパイル使用メモリ | 73,376 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-10-13 05:45:56 |
| 合計ジャッジ時間 | 7,367 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 15 |
ソースコード
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
int f[205][205];
int n;
int v, ox, oy;
bool inrange(int x, int y)
{
return 0 <= x && x < n && 0 <= y && y < n;
}
struct node {
lli d, x, y;
};
int vx[] = {1, 0, -1, 0};
int vy[] = {0, 1, 0, -1};
int main()
{
cin >> n >> v >> ox >> oy;
ox--, oy--;
lli dis[205][205] = {};
auto comp = [](const node l, const node r) -> bool { return l.d < r.d; };
rep(i, n) rep(j, n) cin >> f[i][j];
{
priority_queue<node, vector<node>, decltype(comp)> que(comp);
que.push({f[0][0], 0, 0});
rep(i, 205) rep(j, 205) dis[i][j] = MOD;
while (!que.empty()) {
node cur = que.top();
que.pop();
if (dis[cur.x][cur.y] < cur.d)
continue;
//cout << cur.x << ' ' << cur.y << endl;
dis[cur.x][cur.y] = cur.d;
rep(i, 4)
{
int nx = cur.x + vx[i];
int ny = cur.y + vy[i];
if (inrange(nx, ny)) {
if (dis[nx][ny] > cur.d + f[nx][ny]) {
que.push({cur.d + f[nx][ny], nx, ny});
dis[nx][ny] = cur.d + f[nx][ny];
}
}
}
}
}
if (ox == -1) {
cout << (dis[n - 1][n - 1] < v ? "YES" : "NO") << endl;
} else {
if (dis[n - 1][n - 1] < v) {
cout << "YES" << endl;
return 0;
}
if (dis[ox][oy] < v) {
v = 2 * (v - f[ox][oy]);
priority_queue<node, vector<node>, decltype(comp)> que(comp);
que.push({0, ox, oy});
rep(i, 205) rep(j, 205) dis[i][j] = MOD;
while (!que.empty()) {
node cur = que.top();
que.pop();
if (dis[cur.x][cur.y] < cur.d)
continue;
//cout << cur.x << ' ' << cur.y << endl;
dis[cur.x][cur.y] = cur.d;
rep(i, 4)
{
int nx = cur.x + vx[i];
int ny = cur.y + vy[i];
if (inrange(nx, ny)) {
if (dis[nx][ny] > cur.d + f[nx][ny]) {
que.push({cur.d + f[nx][ny], nx, ny});
dis[nx][ny] = cur.d + f[nx][ny];
}
}
}
}
if (dis[n - 1][n - 1] < v) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
}
}
uenoku