結果

問題 No.2708 Jewel holder
ユーザー manabeaimanabeai
提出日時 2024-03-31 14:01:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 212,368 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:01:11
合計ジャッジ時間 3,100 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 2 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 2 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 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;
typedef long long ll;
vector<ll> dx = {0,1};
vector<ll> dy = {1,0};
ll ans = 0;
void dfs(vector<vector<char>> &S, ll x, ll y, ll houseki,ll h,ll w) {
    if (S[x][y]=='o') houseki++;
    if (S[x][y]=='x') houseki--;

    if (houseki==-1) return;

    if (x==h-1&&y==w-1) {
        ++ans;
        return;
    }

    for (ll i = 0; i < 2; ++i) {
        ll nx = dx[i]+x;
        ll ny = dy[i]+y;

        if (nx >= 0 && nx < h && ny >= 0 && ny < w && S[nx][ny]!='#') {
            dfs(S,nx,ny,houseki,h,w);
        }
    }
}

void solve() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    vector<vector<bool>> seen(h, vector<bool>(w));
    
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) cin >> s[i][j];

    ll hou = 0;

    dfs(s,0,0,hou,h,w);
    cout << ans << endl;




    
}

int main() {
    solve();
    return 0;
}
0