結果

問題 No.2708 Jewel holder
ユーザー ryota2357ryota2357
提出日時 2024-01-24 13:50:43
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,230 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 111,872 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-28 22:37:05
合計ジャッジ時間 1,307 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    assert(2 <= h && h <= 10);
    assert(2 <= w && w <= 10);
    for (int i = 0; i < h; ++i) {
        assert(a[i].length() == (size_t)w);
    }

    auto is_steppable = [&](int x, int y) {
        bool xx = 0 <= x && x < w;
        bool yy = 0 <= y && y < h;
        return xx && yy && (a[y][x] != '#');
    };

    int ans = 0;
    for (int bit = 0; bit < (1 << (h + w - 2)); ++bit) {
        int x = 0, y = 0, jewel = 1;
        for (int i = 0; i < (h + w - 2); ++i) {
            if (bit & (1 << i)) {
                x += 1;
            } else {
                y += 1;
            }
            if (!is_steppable(x, y)) {
                jewel = -1;
                break;
            }
            if (a[y][x] == 'o') {
                jewel += 1;
            } else { // a[y][x] == 'x'
                jewel -= 1;
            }
            if (jewel < 0) {
                break;
            }
        }
        if (jewel >= 0) {
            ans += 1;
        }
    }

    cout << ans << endl;
    return 0;
}
0