結果

問題 No.2708 Jewel holder
ユーザー うえこうえこ
提出日時 2024-03-31 13:39:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 178,532 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-31 13:39:15
合計ジャッジ時間 2,378 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
const long long INF=1LL<<60;
ll h,w;
int main(){
    std::cin >> h >> w;
    std::vector<std::vector<char>>A(h,std::vector<char>(w));
    for(auto&row:A){
        for(auto&a:row)std::cin >> a;
    }
    std::vector<std::vector<std::vector<ll>>>dp(h,std::vector<std::vector<ll>>(w,std::vector<ll>(120)));
    dp[0][0][1]=1;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(i==0&&j==0)continue;
            if(A[i][j]=='#')continue;
            for(int v=0;v<120;++v){
                int nv=v;
                if(A[i][j]=='o')++nv;
                else --nv;
                if(nv<0)continue;
                if(i!=0){
                    dp[i][j][nv]+=dp[i-1][j][v];
                }
                if(j!=0){
                    dp[i][j][nv]+=dp[i][j-1][v];
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<120;++i)ans+=dp.back().back()[i];
    std::cout << ans << '\n';
}
0