結果
| 問題 | No.2708 Jewel holder | 
| コンテスト | |
| ユーザー |  manabeai | 
| 提出日時 | 2024-03-31 14:01:07 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 926 bytes | 
| コンパイル時間 | 1,810 ms | 
| コンパイル使用メモリ | 204,356 KB | 
| 最終ジャッジ日時 | 2025-02-20 16:50:01 | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#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;
}
            
            
            
        