結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
newlife171128
|
| 提出日時 | 2018-02-08 16:49:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 5,000 ms |
| コード長 | 2,155 bytes |
| コンパイル時間 | 1,381 ms |
| コンパイル使用メモリ | 166,952 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 20:51:32 |
| 合計ジャッジ時間 | 2,338 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#include "bits/stdc++.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <unordered_map>
#include <string.h>
#include <utility>
typedef long long ll;
const int INF = 1e8;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> cost_now;
int n, v, o1, o2;
int x_direction[4] = { 1, -1, 0, 0 };
int y_direction[4] = { 0, 0, 1, -1 };
int desert[201][201];
bool visited[201][201];
int desert_cost[201][201];
void inite() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
desert_cost[i][j] = INF;
}
}
}
void solve(int y, int x) {
inite();
desert_cost[y][x] = 0;
priority_queue<cost_now, vector<cost_now>, greater<cost_now>> que;
que.push(cost_now(0, P(y, x)));
while (!que.empty()) {
cost_now xyc = que.top();
int cost = xyc.first;
P p = xyc.second;
que.pop();
for (int i = 0; i < 4; i++) {
int nx = p.second + x_direction[i];
int ny = p.first + y_direction[i];
if (0 <= nx && nx < n && 0 <= ny && ny < n) {
if (desert_cost[ny][nx] > cost + desert[ny][nx]) {
desert_cost[ny][nx] = cost + desert[ny][nx];
que.push(cost_now(desert_cost[ny][nx], P(ny, nx)));
}
}
}
}
}
int main() {
cin >> n >> v >> o1 >> o2;
int tmp = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> tmp;
desert[i][j] = tmp;
}
}
solve(0, 0);
/* for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << desert_cost[i][j];
}
cout << endl;
}*/
if (v - desert_cost[n - 1][n - 1] > 0) {
cout << "YES" << endl;
return 0;
}else if (o1 ==0 && o2 ==0) {
cout<<"NO"<<endl;
return 0;
}
int h = desert_cost[o2-1][o1-1];
solve(o2-1,o1-1);
if(2*(v-h) > desert_cost[n-1][n-1]){
cout << "YES" << endl;
}else {
cout<<"NO"<<endl;
}
/*
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << desert_cost[i][j]<<" ";
}
cout << endl;
}
*/
return 0;
}
newlife171128