結果

問題 No.20 砂漠のオアシス
ユーザー maimai
提出日時 2016-03-18 19:54:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,662 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 75,836 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-04-21 06:51:15
合計ジャッジ時間 6,354 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <cstdio>
#include <cmath>

using namespace std;

int n,hp,ox,oy;
vector<vector<int>> map;

int foot[201][201][2];

int main(){
    int i,j,k;
    cin>>n>>hp>>ox>>oy;
    
    map.push_back(vector<int>());
    for (i=0;i<n;i++){
        map.push_back(vector<int>());
        vector<int> &v=map.back();
        v.push_back(999);
        for(j=0;j<n;j++){
            cin>>k;
            v.push_back(k);
        }
    }
    k=0;
    list<vector<int>> queue;
    queue.push_back(vector<int>{1,1,hp,0});
    for (;!queue.empty();queue.pop_front()){k++;
        vector<int> &v=queue.front();
        if (v[0]==n && v[1]==n){
            cout<<"Yes"<<endl;
            return 0;
        }
        if (foot[v[0]][v[1]][v[3]]>=v[2]) continue;
        foot[v[0]][v[1]][v[3]]=v[2];
        
        v[2]-=map[v[0]][v[1]];
        if (v[2]<=0) continue;
        if (!v[3] && v[0]==ox && v[1]==oy){
            v[3]=1;
            v[2]*=2;
        }
        if (1<v[0]) if (foot[v[0]-1][v[1]][v[3]]<v[2]) 
            queue.push_back(vector<int>{v[0]-1,v[1],v[2],v[3]});
        if (1<v[1]) if (foot[v[0]][v[1]-1][v[3]]<v[2]) 
             queue.push_back(vector<int>{v[0],v[1]-1,v[2],v[3]});
        if (v[0]<n) if (foot[v[0]+1][v[1]][v[3]]<v[2]) 
             queue.push_back(vector<int>{v[0]+1,v[1],v[2],v[3]});
        if (v[1]<n) if (foot[v[0]][v[1]+1][v[3]]<v[2]) 
             queue.push_back(vector<int>{v[0],v[1]+1,v[2],v[3]});
        
        //queue.sort([](vector<int> &le,vector<int> &re){return le[0]+le[1]>re[0]+re[1];});
    }
    
    cout<<"No"<<endl;
    
    return 0;
}
0