結果

問題 No.20 砂漠のオアシス
ユーザー Konton7Konton7
提出日時 2020-02-02 23:21:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,567 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 208,760 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:31:41
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 9 ms
4,348 KB
testcase_06 AC 15 ms
4,348 KB
testcase_07 AC 557 ms
4,348 KB
testcase_08 AC 71 ms
4,348 KB
testcase_09 AC 303 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 31 ms
4,348 KB
testcase_15 AC 15 ms
4,348 KB
testcase_16 AC 54 ms
4,348 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 WA -
testcase_19 AC 43 ms
4,348 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


vector<vector<int>> desert, vital;

void dfs(int y, int x, int v, int n)
{
    if (!(0 <= y && y < n && 0 <= x && x < n))
        return;
    if (v - desert[y][x] <= vital[y][x])
        return;
    else
    {
        vital[y][x] = v - desert[y][x];
        dfs(y, x + 1, v - desert[y][x], n);
        dfs(y, x - 1, v - desert[y][x], n);
        dfs(y + 1, x, v - desert[y][x], n);
        dfs(y - 1, x, v - desert[y][x], n);
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, v, ox, oy, di;
    cin >> n >> v >> ox >> oy;
    vector<int> vi;

    rep(i, n)
    {
        vi.clear();
        rep(j, n)
        {
            cin >> di;
            vi.push_back(di);
        }
        desert.push_back(vi);
        vi.clear();
        rep(j, n)
        {
            vi.push_back(0);
        }
        vital.push_back(vi);
    }

    dfs(0, 0, v, n);

    
        

    if (!(ox == 0 && oy == 0))
    {
        oy--, ox--;
        v = 2 * vital[oy][ox] + desert[oy][ox];
        rep(i, n)
            rep(j, n)
                vital[i][j] = 0;
        dfs(oy, ox, v, n);
    }

    if (vital[n - 1][n - 1] == 0)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;

    return 0;
}
0