結果

問題 No.2708 Jewel holder
コンテスト
ユーザー vjudge1
提出日時 2026-08-25 02:30:55
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 347µs
コード長 1,447 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,311 ms
コンパイル使用メモリ 215,464 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-25 02:30:59
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

using u128 = unsigned __int128;
using i128 = __int128;

const int dx[] = {1, 0};
const int dy[] = {0, 1};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> adj(H);
    std::vector<std::vector<int>> vis(H, std::vector<int>(W));
    for (int i = 0; i < H; i++) {
        std::cin >> adj[i];
    }

    int ans = 0;
    auto dfs = [&](auto&& self, int i, int j, int cur) -> void {
        vis[i][j] = 1;
        if (i == H - 1 && j == W - 1) {
            if (cur >= 0) ans++;  //! ??????????????????ans++
        }
        //! ????????
        //! 1.????????????????return???????????????
        //! 2.????x???????x???cur==0??????
        for (int d = 0; d < 2; d++) {
            int a = i + dx[d];
            int b = j + dy[d];
            if (a >= 0 && a < H && b >= 0 && b < W) {
                if (vis[a][b]) continue;
                if (adj[a][b] == '#') continue;
                if (adj[a][b] == 'x') {
                    if (cur > 0) {
                        self(self, a, b, cur - 1);
                    }
                } else {
                    self(self, a, b, cur + 1);          
                }
            }
        }
        vis[i][j] = 0;
    };

    dfs(dfs, 0, 0, 1);
    std::cout << ans << '\n';

    return 0;
}
0