結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
tkmst201
|
| 提出日時 | 2017-05-18 20:03:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 5,000 ms |
| コード長 | 1,543 bytes |
| コンパイル時間 | 1,439 ms |
| コンパイル使用メモリ | 165,132 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 05:51:23 |
| 合計ジャッジ時間 | 2,137 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | REP(i, n) REP(j, n) scanf("%d", &l[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
int n, v, ox, oy;
int l[200][200];
int dp[200][200][2];
int main() {
cin >> n >> v >> ox >> oy;
REP(i, n) REP(j, n) scanf("%d", &l[i][j]);
ox--; oy--;
memset(dp, -1, sizeof(dp));
priority_queue<P> pq;
pq.push(P(pii(v, 1), pii(0, 0)));
if (ox == 0 && oy == 0) pq.push(P(pii(v * 2, 0), pii(0, 0)));
while (!pq.empty()) {
P now = pq.top(); pq.pop();
int h = now.first.first;
int f = now.first.second;
int x = now.second.first;
int y = now.second.second;
if (!chmax(dp[y][x][f], h)) continue;
static int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
REP(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!(nx >= 0 && nx < n && ny >= 0 && ny < n)) continue;
pq.push(P(pii(h - l[ny][nx], f), pii(nx, ny)));
if (f && nx == ox && ny == oy) pq.push(P(pii((h - l[ny][nx]) * 2, 0), pii(nx, ny)));
}
}
if (dp[n - 1][n - 1][0] > 0 || dp[n - 1][n - 1][1] > 0) puts("YES");
else puts("NO");
return 0;
}
tkmst201