結果

問題 No.20 砂漠のオアシス
ユーザー chakkuchakku
提出日時 2016-04-02 19:01:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,867 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 83,228 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:52:17
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 29 ms
6,940 KB
testcase_08 AC 11 ms
6,944 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 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;


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

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

int N,V,Ox,Oy;
int L[201][201];

int tbl[201][201][2];

bool in_field(int x,int y){
    if(x<0 or y<0 or x>=N or y>=N) return false;
    else return true;
}

int main(){
    cin >> N >> V >> Ox >> Oy;
    Ox--;
    Oy--;
    REP(i,N) REP(j,N) REP(k,2) tbl[i][j][k] = 0;
    REP(i,N) REP(j,N) cin >> L[i][j];
    queue<node> que;
    que.push(node{0,0,V,false});

    while(!que.empty()){
        node p = que.front();
        que.pop();
        if(p.x==N-1 and p.y==N-1){
            cout << "YES" << endl;
            return 0;
        }

        if(tbl[p.x][p.y][p.used]>p.HP) continue;

        for(int i=0;i<4;i++){
            int nx = p.x + dx[i];
            int ny = p.y + dy[i];
            if(!in_field(nx,ny)) continue;
            if(p.HP-L[nx][ny]<0) continue;

            if(nx==Ox && ny==Oy && p.used==false){
                if(tbl[nx][ny][1]<(p.HP-L[nx][ny])*2){
                    tbl[nx][ny][1] = (p.HP-L[nx][ny])*2;
                    que.push(node{nx,ny,tbl[nx][ny][1],true});
                }
            }else{
                if(tbl[nx][ny][p.used]<p.HP-L[nx][ny]){
                    tbl[nx][ny][p.used] = p.HP - L[nx][ny];
                    que.push(node{nx,ny,tbl[nx][ny][p.used],p.used});
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
0