結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2015-06-04 00:26:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3,987 ms / 5,000 ms |
| コード長 | 1,783 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 05:12:21 |
| 合計ジャッジ時間 | 18,061 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
#define INF 1000000000
int N;
int L[205][205];
int vx[4] = {0,0,1,-1};
int vy[4] = {1,-1,0,0};
int dijkstra(int sx, int sy, int gx, int gy){
bool visited[205][205];
int cost[205][205];
REP(i,1,N+1){
REP(j,1,N+1){
cost[i][j] = INF;
visited[i][j] = false;
}
}
cost[sy][sx] = 0;
while(true){
int minx, miny, minVal = INF;
REP(i,1,N+1){
REP(j,1,N+1){
if(minVal>cost[i][j] && !visited[i][j]){
minVal = cost[i][j];
miny = i;
minx = j;
}
}
}
if(minVal == INF) return INF;
if(minx == gx && miny == gy) return minVal;
visited[miny][minx] = true;
rep(k,4){
int nx = minx + vx[k], ny = miny + vy[k];
if(1<=nx&&nx<=N && 1<=ny&&ny<=N){
if(cost[ny][nx]>cost[miny][minx]+L[ny][nx]){
cost[ny][nx] = cost[miny][minx]+L[ny][nx];
}
}
}
}
}
int main(){
int V, Ox, Oy;
cin >> N >> V >> Ox >> Oy;
REP(i,1,N+1){
REP(j,1,N+1){
cin >> L[i][j];
}
}
int ret1 = V - dijkstra(1,1,N,N);
int ret2 = 0;
if(Ox>=1){
int a = V-dijkstra(1,1,Ox,Oy);
if(a>=0){
ret2 = 2*a - dijkstra(Ox,Oy,N,N);
}
}
if(max(ret1, ret2) > 0) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
どらら