結果

問題 No.20 砂漠のオアシス
ユーザー togatogatogatoga
提出日時 2015-09-12 14:26:36
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,867 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 167,132 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-10-13 05:26:09
合計ジャッジ時間 2,255 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
struct Edge{
int node,cost;
Edge(int node, int cost):node(node),cost(cost){
}
};
struct State{
int hp,node;
bool use;
State(int node, int hp, bool use):hp(hp),node(node),use(use){}
bool operator < (const State& right) const {
return hp < right.hp;
}
};
int N,V,gx,gy;
int board[220][220];
int cost[44000][2];
vector<Edge> Edges[44000];
int main(){
cin >> N >> V >> gx >> gy;
gx--;
gy--;
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
cin >> board[i][j];
}
}
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
int ny,nx;
int node = i * N + j;
for (int k = 0; k < 4; k++){
ny = i + dy[k];
nx = j + dx[k];
if (ny < 0 or nx < 0 or ny >= N or nx >= N)continue;
int next_node = ny * N + nx;
int cost = board[ny][nx];
Edges[node].push_back(Edge(next_node, cost));
}
}
}
priority_queue<State> que;
que.push(State(0, V, false));
for (int i = 0; i < 44000; i++){
for (int j = 0; j < 2; j++){
cost[i][j] = -100;
}
}
cost[0][0] = V;
while (!que.empty()){
State pos = que.top();
que.pop();
if (cost[pos.node][pos.use] > pos.hp){
continue;
}
//cout << pos.node << " " << pos.hp << endl;
if (!pos.use and pos.node == gy * N + gx){
pos.use = true;
pos.hp *= 2;
}
if (pos.node == N * (N - 1) + (N - 1)){
cout << "YES" << endl;
return 0;
}
for (int i = 0; i < Edges[pos.node].size(); i++){
Edge np = Edges[pos.node][i];
if (pos.hp - np.cost > 0){
if (cost[np.node][pos.use] < pos.hp - np.cost){
cost[np.node][pos.use] = pos.hp - np.cost;
que.push(State(np.node, cost[np.node][pos.use], pos.use));
}
}
}
}
cout << "NO" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0