結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
char134217728
|
| 提出日時 | 2019-01-19 15:09:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 5,000 ms |
| コード長 | 1,746 bytes |
| コンパイル時間 | 1,849 ms |
| コンパイル使用メモリ | 182,908 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-07-17 22:11:38 |
| 合計ジャッジ時間 | 2,624 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
43 | main(){
| ^~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define mp make_pair
#define pb push_back
typedef long long ll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
const int N = 200;
struct Dijk{
typedef long long ll;
const ll tinf = 1e18;
int n;
vector<ll> d;
vector<int> p;
void solve(const vector<vector<pair<int, ll>>>&E, int S, int G=-1){
n = E.size();
d = vector<ll>(n, tinf);
p = vector<int>(n, -1);
d[S] = 0;
priority_queue<pair<ll, int>,vector<pair<ll, int>>,greater<pair<ll, int>>> Q;
Q.push(pair<ll, int>(0, S));
while(!Q.empty()){
pair<ll, int> t=Q.top(); Q.pop();
if(t.second == G) return;
for(auto itr = E[t.second].begin(); itr != E[t.second].end(); itr++){
ll k = t.first + itr->second;
int m = itr->first;
if(k < d[itr->first]){
d[m] = k;
p[m] = t.second;
Q.push(pair<ll, int>(k, m));
}
}
}
}
};
Dijk dijk;
int n, v, x, y, L[N][N];
VV<pair<int, ll>> E;
main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> v >> y >> x;
E.resize(n*n);
FOR(i, 0, n)FOR(j, 0, n) cin >> L[i][j];
FOR(i, 0, n)FOR(j, 0, n){
if(i < n-1){
E[i*n+j].pb(mp((i+1)*n+j, L[i+1][j]));
E[(i+1)*n+j].pb(mp(i*n+j, L[i][j]));
}
if(j < n-1){
E[i*n+j].pb(mp(i*n+j+1, L[i][j+1]));
E[i*n+j+1].pb(mp(i*n+j, L[i][j]));
}
}
dijk.solve(E, 0);
if(dijk.d[n*n-1] < v){
cout << "YES" << endl;
return 0;
}
if(x){
x--; y--;
int c = dijk.d[x*n+y];
dijk.solve(E, x*n+y);
if(dijk.d[n*n-1] < (v-c)*2){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
char134217728