結果

問題 No.20 砂漠のオアシス
ユーザー goodbatongoodbaton
提出日時 2015-07-29 19:22:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 2,197 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 80,156 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:38:50
合計ジャッジ時間 1,484 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 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 4 ms
6,944 KB
testcase_05 AC 23 ms
6,944 KB
testcase_06 AC 8 ms
6,940 KB
testcase_07 AC 45 ms
6,940 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 38 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 9 ms
6,940 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 9 ms
6,944 KB
testcase_19 AC 10 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%d%d%d%d",&n,&v,&ox,&oy);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:37:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |             scanf("%d",&l[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int mo[5] = {0,1,0,-1,0};

int main(){
    int n,v,ox,oy,nowv,a,b;
    int l[210][210];
    bool visit_bf[210][210]={0},visit_oa[210][210]={0};
    
    scanf("%d%d%d%d",&n,&v,&ox,&oy);
    
    ox--;
    oy--;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&l[i][j]);
        }
    }
    
    priority_queue<pair<int,pair<int,int> > > pq,pq_oa;
    pq.push({v,{0,0}});
    
    while(pq.size()){
        
        pair<int,pair<int,int> > p = pq.top();
        pq.pop();
        
        nowv = p.first;
        a = p.second.first;
        b = p.second.second;
        
        if(visit_bf[a][b]) continue;
        visit_bf[a][b] = true;
        
        if(nowv<=0) continue;
        
        if(b==ox && a==oy){
            pq_oa.push({nowv*2,{a,b}});
        }
        
        if(a==n-1 && b==n-1){
            puts("YES");
            return 0;
        }
        
        for(int i=0;i<4;i++){
            
            if(a+mo[i]<0 || b+mo[i+1]<0 || n<=a+mo[i] || n<=b+mo[i+1]) continue;
            
            pq.push({nowv-l[a+mo[i]][b+mo[i+1]],{a+mo[i],b+mo[i+1]}});
        }
        
    }
    
    while(pq_oa.size()){
        
        pair<int,pair<int,int> > p = pq_oa.top();
        pq_oa.pop();
        
        nowv = p.first;
        a = p.second.first;
        b = p.second.second;
        
        if(visit_oa[a][b]) continue;
        visit_oa[a][b] = true;
        
        if(nowv<=0) continue;
        
        if(a==n-1 && b==n-1){
            puts("YES");
            return 0;
        }
        
        for(int i=0;i<4;i++){
            
            if(a+mo[i]<0 || b+mo[i+1]<0 || n<=a+mo[i] || n<=b+mo[i+1]) continue;
            
            pq_oa.push({nowv-l[a+mo[i]][b+mo[i+1]],{a+mo[i],b+mo[i+1]}});
        }
        
    }
    
    puts("NO");
    
    return 0;
}
0