結果

問題 No.2708 Jewel holder
ユーザー ルクルク
提出日時 2024-03-31 14:33:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,763 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 205,100 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:33:22
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = n; i > 0; --i)
#define bitrep(i, n) for (ll i = 0; i < (1 << n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define yesNo(b) ((b) ? "Yes" : "No")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const double pi = 3.141592653589793;
ll smallMOD = 998244353;
ll bigMOD = 1000000007;
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
ll h, w;
vector<string> mp;
ll ans = 0;

// 0,0からh-1,w-1までをdfs.
ll dfs(ll x, ll y, ll jewel)
{
    ll res = 0;
    rep(i, 2)
    {
        ll nx = x + dx[i];
        ll ny = y + dy[i];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w)
        {
            continue;
        }
        if (mp[nx][ny] == '#')
            continue;
        if (mp[nx][ny] == 'o')
        {
            res += dfs(nx, ny, jewel + 1);
        }
        if (mp[nx][ny] == 'x')
        {
            if (jewel >= 1)
                res += dfs(nx, ny, jewel - 1);
            else
                continue;
        }
    }
    if (x == h - 1 && y == w - 1)
    {
        if (jewel >= 0)
            return 1;
        else
            return 0;
    }
    return res;
}

int main()
{
    cin >> h >> w;
    mp.resize(h);
    rep(i, h) cin >> mp[i];
    // #は通れない、oはjewelが増える、xはjewelが減る
    // #を通らず、jewelが0未満にならないような経路数を求める
    // DFSで探索する
    cout << dfs(0, 0, 1) << endl;
    return 0;
}
0