結果

問題 No.20 砂漠のオアシス
ユーザー parukiparuki
提出日時 2016-10-07 23:46:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,057 ms / 5,000 ms
コード長 1,310 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 163,104 KB
実行使用メモリ 82,048 KB
最終ジャッジ日時 2024-04-21 06:56:29
合計ジャッジ時間 4,537 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 8 ms
8,320 KB
testcase_04 AC 12 ms
8,704 KB
testcase_05 AC 54 ms
52,480 KB
testcase_06 AC 25 ms
12,160 KB
testcase_07 AC 1,057 ms
82,048 KB
testcase_08 AC 139 ms
35,840 KB
testcase_09 AC 597 ms
73,472 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 12 ms
6,912 KB
testcase_13 AC 13 ms
7,808 KB
testcase_14 AC 29 ms
11,264 KB
testcase_15 AC 20 ms
9,216 KB
testcase_16 AC 101 ms
19,968 KB
testcase_17 AC 53 ms
14,976 KB
testcase_18 AC 80 ms
17,792 KB
testcase_19 AC 90 ms
20,480 KB
testcase_20 AC 7 ms
5,760 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(ok)return;
    visited[y][x][v][flag] = true;
    if(x == N - 1 && y == N - 1){
        ok = true;
        return;
    }
    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