結果

問題 No.2040 010-1 Deletion
ユーザー ぷらぷら
提出日時 2022-08-12 22:44:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 3,000 ms
コード長 2,352 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 196,408 KB
実行使用メモリ 39,296 KB
最終ジャッジ日時 2024-04-26 19:11:04
合計ジャッジ時間 4,737 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 72 ms
39,040 KB
testcase_12 AC 73 ms
39,168 KB
testcase_13 AC 72 ms
39,296 KB
testcase_14 AC 70 ms
39,040 KB
testcase_15 AC 70 ms
39,168 KB
testcase_16 AC 81 ms
39,168 KB
testcase_17 AC 64 ms
38,912 KB
testcase_18 AC 80 ms
39,040 KB
testcase_19 AC 11 ms
9,344 KB
testcase_20 AC 7 ms
6,784 KB
testcase_21 AC 32 ms
20,480 KB
testcase_22 AC 39 ms
23,936 KB
testcase_23 AC 64 ms
36,224 KB
testcase_24 AC 69 ms
38,016 KB
testcase_25 AC 54 ms
33,664 KB
testcase_26 AC 48 ms
29,952 KB
testcase_27 AC 59 ms
34,688 KB
testcase_28 AC 48 ms
29,952 KB
testcase_29 AC 59 ms
34,816 KB
testcase_30 AC 37 ms
23,552 KB
testcase_31 AC 66 ms
37,504 KB
testcase_32 AC 68 ms
38,400 KB
testcase_33 AC 66 ms
37,888 KB
testcase_34 AC 67 ms
38,016 KB
testcase_35 AC 67 ms
37,888 KB
testcase_36 AC 64 ms
36,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;

int dp[1515][1515][2][2];

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    dp[0][0][0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < 2; k++) {
                for(int l = 0; l < 2; l++) {
                    if(S[i] != '?' && S[i]-'0' != l) {
                        continue;
                    }
                    for(int f = 0; f < 2; f++) {
                        if(l == 1) {
                            mpl(dp[i+1][j][l][f],dp[i][j][k][f]);
                        }
                        else {
                            if(f == 0 && k == 0) {
                                mpl(dp[i+1][j+1][l][f],dp[i][j][k][f]);
                            }
                            if(f == 1 && k == 1) {
                                mpl(dp[i+1][j+1][l][f],dp[i][j][k][f]);
                            }
                            if(f == 0 && k == 1) {
                                if(j == 0) {
                                    mpl(dp[i+1][j+1][l][0],dp[i][j][k][f]);
                                }
                                else if(j == 1) {
                                    mpl(dp[i+1][j+1][l][1],dp[i][j][k][f]);
                                }
                                else {
                                    mpl(dp[i+1][j-1][l][0],dp[i][j][k][f]);
                                }
                            }
                            if(f == 1 && k == 0) {
                                if(j == 2) {
                                    mpl(dp[i+1][j-1][l][0],dp[i][j][k][f]);
                                }
                                else {
                                    mpl(dp[i+1][j-1][l][1],dp[i][j][k][f]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= N; i += 2) {
        if(i == 0) {
            mpl(ans,dp[N][i][0][0]);
            mpl(ans,dp[N][i][1][0]);
        }
        else {
            mpl(ans,dp[N][i][0][1]);
            mpl(ans,dp[N][i][1][1]);
        }
    }
    cout << ans << endl;
}
0