結果

問題 No.20 砂漠のオアシス
ユーザー chakkuchakku
提出日時 2016-04-03 02:23:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,064 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 71,956 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:52:41
合計ジャッジ時間 1,429 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define ALL(v) (v).begin(),(v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

int N,V,Ox,Oy;
int L[256][256];
int t[256][256][2];     //t[i][j][k] : (i,j)に体力t[i][j][k]でたどり着ける(kが0の時泉未使用)

struct node{
    int x,y,hp;
    bool used;
};

bool ok(int x,int y){
    if(0<=x and x<N and 0<=y and y<N) return true;
    else return false;
}

int main(){
    cin >> N >> V >> Ox >> Oy;
    Ox--;Oy--;
    REP(i,N) REP(j,N) cin >> L[i][j];
    REP(i,N) REP(j,N) REP(k,2) t[i][j][k] = 0;

    queue<node> que;
    que.push(node{0,0,V,false});
    t[0][0][0] = V;

    while(!que.empty()){
        node p = que.front();
        que.pop();
        const int x = p.x;
        const int y = p.y;
        const int hp = p.hp;
        const bool used = p.used;

        assert(hp>0);

        if(x==N-1 and y==N-1){
            cout << "YES" << endl;
            return 0;
        }

        if(t[x][y][used]>hp) continue;

        REP(idx,4){
            const int nx = x + dx[idx], ny = y + dy[idx];
            if(!ok(nx,ny)) continue;

            if(hp-L[nx][ny]<0) continue;

            if(nx==Ox and ny==Oy and used==false){
                //泉使用
                if(t[nx][ny][1]<(hp-L[nx][ny])*2){
                    t[nx][ny][1] = (hp-L[nx][ny])*2;
                    que.push(node{nx,ny,t[nx][ny][1],true});
                }
            }
            else{
                if(t[nx][ny][used]<hp-L[nx][ny]){
                    t[nx][ny][used] = hp - L[nx][ny];
                    que.push(node{nx,ny,t[nx][ny][used],used});
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
0