結果

問題 No.2541 Divide 01 String
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-24 21:27:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 207,144 KB
実行使用メモリ 14,312 KB
最終ジャッジ日時 2023-11-24 21:27:03
合計ジャッジ時間 3,426 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 5 ms
6,676 KB
testcase_04 AC 13 ms
8,832 KB
testcase_05 AC 21 ms
13,452 KB
testcase_06 AC 11 ms
7,936 KB
testcase_07 AC 20 ms
13,364 KB
testcase_08 AC 22 ms
14,312 KB
testcase_09 AC 21 ms
14,312 KB
testcase_10 AC 20 ms
14,312 KB
testcase_11 AC 20 ms
14,312 KB
testcase_12 AC 20 ms
14,312 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 15 ms
10,368 KB
testcase_19 AC 15 ms
10,368 KB
testcase_20 AC 15 ms
10,240 KB
testcase_21 AC 12 ms
8,576 KB
testcase_22 AC 11 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    int N; cin >> N;
    string s; cin >> s;
    vector dp(N+1,vector<long long>(2));
    dp.at(0).at(0) = 1;
    long long mod = 998244353;
    for(int i=0; i<N; i++) for(int k=0; k<2; k++){
        if(k == 1) dp.at(i+1).at(1) = (dp.at(i+1).at(1)+dp.at(i).at(k))%mod;

        if(s.at(i) == '1') dp.at(i+1).at(1) = (dp.at(i+1).at(1)+dp.at(i).at(k))%mod;
        else dp.at(i+1).at(0) = (dp.at(i+1).at(0)+dp.at(i).at(k))%mod;
    }    
    cout << dp.at(N).at(1) << endl;
}
0