結果

問題 No.20 砂漠のオアシス
ユーザー parukiparuki
提出日時 2016-10-07 23:49:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,276 ms / 5,000 ms
コード長 1,279 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 163,884 KB
実行使用メモリ 82,048 KB
最終ジャッジ日時 2024-04-21 06:56:35
合計ジャッジ時間 5,332 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 8 ms
8,192 KB
testcase_04 AC 14 ms
8,576 KB
testcase_05 AC 58 ms
52,480 KB
testcase_06 AC 28 ms
12,160 KB
testcase_07 AC 1,276 ms
82,048 KB
testcase_08 AC 155 ms
35,712 KB
testcase_09 AC 684 ms
73,472 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 15 ms
7,808 KB
testcase_14 AC 33 ms
11,136 KB
testcase_15 AC 25 ms
9,216 KB
testcase_16 AC 117 ms
20,096 KB
testcase_17 AC 61 ms
14,976 KB
testcase_18 AC 94 ms
17,664 KB
testcase_19 AC 103 ms
20,352 KB
testcase_20 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int DY[] = {-1,0,1,0};
const int DX[] = {0,1,0,-1};

int N, V, OX, OY, L[200][200];
bool visited[200][200][1001][2], ok = false;

void f(int y, int x, int v, int flag){
    if(x == N - 1 && y == N - 1) ok = true;
    if(ok)return;
    visited[y][x][v][flag] = true;
    if(OY == y&&OX == x && !flag){
        flag = 1;
        v *= 2;
    }
    rep(i, 4){
        int ny = y + DY[i], nx = x + DX[i], nv;
        if(ny >= 0 && ny < N&&nx >= 0 && nx < N){
            nv = v - L[ny][nx];
            if(nv > 0 && !visited[ny][nx][nv][flag]){
                f(ny, nx, nv, flag);
            }
        }
    }
}

int main(){
    cin >> N >> V >> OX >> OY;
    --OX; --OY;
    rep(y, N)rep(x, N)scanf("%d", &L[y][x]);
    f(0, 0, V, 0);
    puts(ok ? "YES" : "NO");
}
0