結果

問題 No.2708 Jewel holder
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-04-03 12:07:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 203,448 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-03 12:07:05
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 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 3 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;
using ll = long long;

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

    int H, W, N, K, h=0, w=0, n, ans=0;
    bool f;
    cin >> H >> W;
    N = H+W-2;
    K = 1<<N;

    vector<string> s(H);
    for (int i=0; i<H; i++) cin >> s[i];

    for (int i=0; i<K; i++){
        if (__builtin_popcount(i) == H-1){
            h = 0; w = 0; n = 1; f = 1;
            for (int j=0; j<N; j++){
                if ((i>>j) & 1) h++;
                else w++;
                if (s[h][w] == '#'){
                    f = 0;
                    break;
                }
                else if (s[h][w] == 'o') n++;
                else n--;
                if (n < 0){
                    f = 0;
                    break;
                }
            }
            ans += f;
        }
    }
    cout << ans << endl;

    return 0;
}
0