結果

問題 No.2040 010-1 Deletion
ユーザー ぷらぷら
提出日時 2022-08-12 22:44:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 3,000 ms
コード長 2,352 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 201,372 KB
実行使用メモリ 39,168 KB
最終ジャッジ日時 2023-08-09 03:50:00
合計ジャッジ時間 6,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 71 ms
38,948 KB
testcase_12 AC 73 ms
39,052 KB
testcase_13 AC 71 ms
38,992 KB
testcase_14 AC 71 ms
39,168 KB
testcase_15 AC 72 ms
38,924 KB
testcase_16 AC 84 ms
38,928 KB
testcase_17 AC 65 ms
38,932 KB
testcase_18 AC 80 ms
38,872 KB
testcase_19 AC 11 ms
9,372 KB
testcase_20 AC 7 ms
6,584 KB
testcase_21 AC 31 ms
20,272 KB
testcase_22 AC 39 ms
23,812 KB
testcase_23 AC 63 ms
35,888 KB
testcase_24 AC 68 ms
38,012 KB
testcase_25 AC 56 ms
33,284 KB
testcase_26 AC 50 ms
29,908 KB
testcase_27 AC 60 ms
34,548 KB
testcase_28 AC 50 ms
29,784 KB
testcase_29 AC 60 ms
35,036 KB
testcase_30 AC 38 ms
23,460 KB
testcase_31 AC 67 ms
37,400 KB
testcase_32 AC 67 ms
38,312 KB
testcase_33 AC 67 ms
37,708 KB
testcase_34 AC 65 ms
37,888 KB
testcase_35 AC 66 ms
37,668 KB
testcase_36 AC 65 ms
36,768 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