結果

問題 No.2708 Jewel holder
コンテスト
ユーザー ting shuo
提出日時 2026-08-25 02:27:10
言語 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
+ 346µs
コード長 1,355 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,131 ms
コンパイル使用メモリ 212,132 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-25 02:27:18
合計ジャッジ時間 2,505 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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);
    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 {
        if (i == H - 1 && j == W - 1) {
            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 (adj[a][b] == '#') continue;
                if (adj[a][b] == 'x') {
                    if (cur == 0) continue;
                    self(self, a, b, cur - 1);
                } else {
                    self(self, a, b, cur + 1);          
                }
            }
        }
    };

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

    return 0;
}
0