結果

問題 No.20 砂漠のオアシス
ユーザー EmKjpEmKjp
提出日時 2015-02-21 19:42:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,351 ms / 5,000 ms
コード長 1,792 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 86,112 KB
実行使用メモリ 91,080 KB
最終ジャッジ日時 2024-04-21 06:24:00
合計ジャッジ時間 5,370 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
83,392 KB
testcase_01 AC 33 ms
83,276 KB
testcase_02 AC 33 ms
83,344 KB
testcase_03 AC 34 ms
83,444 KB
testcase_04 AC 51 ms
83,812 KB
testcase_05 AC 38 ms
83,528 KB
testcase_06 AC 54 ms
83,840 KB
testcase_07 AC 1,351 ms
91,080 KB
testcase_08 AC 181 ms
85,068 KB
testcase_09 AC 710 ms
88,164 KB
testcase_10 AC 35 ms
83,276 KB
testcase_11 AC 34 ms
83,288 KB
testcase_12 AC 44 ms
83,664 KB
testcase_13 AC 45 ms
83,756 KB
testcase_14 AC 104 ms
84,388 KB
testcase_15 AC 71 ms
84,300 KB
testcase_16 AC 189 ms
84,932 KB
testcase_17 AC 124 ms
84,408 KB
testcase_18 AC 169 ms
84,700 KB
testcase_19 AC 172 ms
84,916 KB
testcase_20 AC 38 ms
83,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:68: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
   53 |         if(visited[now.row][now.col][now.vitality][now.visitedOasis]++) continue;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
main.cpp:44:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     FOR(i,N) FOR(j,N) scanf("%d", &L[i][j]);
      |                       ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

int L[222][222];

struct data{
    int row, col;
    int vitality;
    bool visitedOasis;
};

bool visited[202][202][1002][2];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int main()
{
    int N,V,ox,oy;
    cin>>N>>V>>ox>>oy;
    ox--; oy--;
    FOR(i,N) FOR(j,N) scanf("%d", &L[i][j]);
    queue<data> qu;
    qu.push((data){ 0, 0, V, false});
    memset(visited , 0 , sizeof(visited));
    while(!qu.empty()){
        data now = qu.front(); qu.pop();
        if(now.row == oy && now.col == ox && !now.visitedOasis){
            qu.push((data){now.row,now.col,2*now.vitality,true});
        }
        if(visited[now.row][now.col][now.vitality][now.visitedOasis]++) continue;
        if(now.row == N - 1 && now.col == N - 1){
            puts("YES");
            return 0;
        }
        FOR(i,4){
            int nr = now.row + dy[i];
            int nc = now.col + dx[i];
            if(BET(0,nr,N) && BET(0,nc,N)){
                int nv = now.vitality;
                nv -= L[nr][nc];
                if(nv > 0){
                    qu.push((data){nr, nc, nv, now.visitedOasis});
                }
            }
        }
    }
    puts("NO");
    
    return 0;
}
0