結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-24 21:15:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 1,487 bytes |
| コンパイル時間 | 584 ms |
| コンパイル使用メモリ | 53,376 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 05:06:40 |
| 合計ジャッジ時間 | 1,552 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
int dp[200][200][2];
const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
int main(){
const int n = getInt();
const int v = getInt();
const int ox = getInt() - 1;
const int oy = getInt() - 1;
vector<vector<int> > g(n, vector<int>(n));
REP(i,n) REP(j,n)
g[i][j] = getInt();
typedef pair<int, pair<pair<int, int>, int> > data;
priority_queue<data> pq;
auto cd = [](int hp, int x, int y, int o){
return data(hp, make_pair(make_pair(x, y), o));
};
pq.push(cd(v, 0, 0, 0));
while(pq.size()){
const data d = pq.top(); pq.pop();
const int h = d.first;
const int x = d.second.first.first;
const int y = d.second.first.second;
const int o = d.second.second;
if(dp[y][x][o]) continue;
dp[y][x][o] = h;
if(x == n - 1 && y == n - 1){
puts("YES");
return 0;
}
REP(i,4){
const int xx = x + _dx[i];
const int yy = y + _dy[i];
if(ISIN(xx, yy, n, n)){
const int hh = h * (ox == x && oy == y && o == 0 ? 2 : 1) - g[yy][xx];
const int oo = ox == x && oy == y ? 1 : o;
if(dp[yy][xx][oo] != 0) continue;
if(hh <= 0) continue;
pq.push(cd(hh, xx, yy, oo));
}
}
}
puts("NO");
return 0;
}
y_mazun