結果
問題 | No.20 砂漠のオアシス |
ユーザー | commy |
提出日時 | 2018-08-12 22:45:21 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,967 bytes |
コンパイル時間 | 1,153 ms |
コンパイル使用メモリ | 92,436 KB |
実行使用メモリ | 8,636 KB |
最終ジャッジ日時 | 2023-10-24 16:25:00 |
合計ジャッジ時間 | 2,637 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 3 ms
4,348 KB |
testcase_05 | AC | 26 ms
8,108 KB |
testcase_06 | AC | 17 ms
8,636 KB |
testcase_07 | AC | 31 ms
8,636 KB |
testcase_08 | AC | 20 ms
8,636 KB |
testcase_09 | AC | 29 ms
8,636 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 3 ms
4,348 KB |
testcase_13 | AC | 3 ms
4,348 KB |
testcase_14 | AC | 4 ms
4,348 KB |
testcase_15 | AC | 3 ms
4,348 KB |
testcase_16 | AC | 7 ms
4,816 KB |
testcase_17 | AC | 5 ms
4,484 KB |
testcase_18 | AC | 6 ms
4,656 KB |
testcase_19 | AC | 7 ms
4,840 KB |
testcase_20 | AC | 2 ms
4,348 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <queue> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl using namespace std; typedef long long int lli; template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } struct Edge { int x, y, hp, o; Edge(int _x, int _y, int h, int _o) : x(_x), y(_y), hp(h), o(_o) {} Edge() {} bool operator<(const Edge &e) const { return hp < e.hp; } }; int main() { int N, V, Ox, Oy; cin >> N >> V >> Ox >> Oy; auto L = make_v(N + 2, N + 2, -1); REP(i, 1, N + 1) { REP(j, 1, N + 1) { cin >> L[i][j]; } } priority_queue<Edge, vector<Edge>> pq; pq.emplace(1, 1, V, 0); auto used = make_v(N + 2, N + 2, 2, false); auto Cost = make_v(N + 2, N + 2, 2, 0); const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; while (pq.size()) { auto E = pq.top(); pq.pop(); if (used[E.y][E.x][E.o]) continue; used[E.y][E.x][E.o] = true; if (Cost[E.y][E.x][E.o] > E.hp) continue; Cost[E.y][E.x][E.o] = E.hp; REP(k, 0, 4) { int nx = E.x + dx[k]; int ny = E.y + dy[k]; int no = E.o; if (L[ny][nx] == -1) continue; int nc = E.hp - L[ny][nx]; if (ny == Oy && nx == Ox && !no) { nc *= 2; no = 1; } if (nc <= 0) continue; if (Cost[ny][nx][no] < nc) { Cost[ny][nx][no] = nc; pq.emplace(nx, ny, nc, no); } } } cout << (((Cost[N][N][0] > 0) || (Cost[N][N][1] > 0)) ? "YES" : "NO") << endl; return 0; }