結果

問題 No.20 砂漠のオアシス
ユーザー chakkuchakku
提出日時 2016-04-03 03:06:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 2,626 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 73,052 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 07:59:30
合計ジャッジ時間 1,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 28 ms
4,376 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 23 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 2 ms
4,380 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;
};

void show(){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int tt = t[i][j][0];
            if(tt>99) cout << tt << " ";
            else if(tt>9) cout << tt << "  ";
            else cout << tt << "   ";
        }
        cout << endl;
    }
    cout << endl;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int tt = t[i][j][1];
            if(tt>99) cout << tt << " ";
            else if(tt>9) cout << tt << "  ";
            else cout << tt << "   ";
        }
        cout << endl;
    }
}

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 >> Oy >> Ox;
    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;
            //show();
            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