結果

問題 No.20 砂漠のオアシス
ユーザー koprickykopricky
提出日時 2017-09-13 04:01:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 2,211 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 162,952 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:29:31
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 27 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 21 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 205;
const int dx[] = {1,0,0,-1};
const int dy[] = {0,1,-1,0};

int cost[MAX_N][MAX_N];
int hp[MAX_N][MAX_N][2];

struct state
{
    int a,b,c;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,h,u,v;
    cin >> n >> h >> v >> u;
    u--,v--;
    rep(i,n){
        rep(j,n){
            cin >> cost[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            rep(k,2){
                hp[i][j][k] = 0;
            }
        }
    }
    hp[0][0][0] = h;
    queue<state> que;
    que.push((state){0,0,0});
    while(!que.empty()){
        state s = que.front();
        que.pop();
        rep(i,4){
            int nx = s.a + dx[i],ny = s.b + dy[i];
            if(0 <= nx && nx < n && 0 <= ny && ny < n){
                if(nx == u && ny == v && s.c == 0){
                    if(2*(hp[s.a][s.b][s.c] - cost[nx][ny]) > hp[nx][ny][1]){
                        hp[nx][ny][1] = 2*(hp[s.a][s.b][s.c] - cost[nx][ny]);
                        que.push((state){nx,ny,1});
                    }
                }else{
                    if(hp[s.a][s.b][s.c] - cost[nx][ny] > hp[nx][ny][s.c]){
                        hp[nx][ny][s.c] = hp[s.a][s.b][s.c] - cost[nx][ny];
                        que.push((state){nx,ny,s.c});
                    }
                }
            }
        }
    }
    if(max(hp[n-1][n-1][0],hp[n-1][n-1][1]) > 0){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}
0