結果

問題 No.2040 010-1 Deletion
ユーザー milanis48663220milanis48663220
提出日時 2022-08-13 00:44:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 3,000 ms
コード長 2,778 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 120,304 KB
実行使用メモリ 74,212 KB
最終ジャッジ日時 2023-10-24 12:48:44
合計ジャッジ時間 3,451 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
74,204 KB
testcase_01 AC 22 ms
74,204 KB
testcase_02 AC 21 ms
74,144 KB
testcase_03 AC 22 ms
74,204 KB
testcase_04 AC 21 ms
74,204 KB
testcase_05 AC 22 ms
74,204 KB
testcase_06 AC 21 ms
74,204 KB
testcase_07 AC 22 ms
74,204 KB
testcase_08 AC 22 ms
74,204 KB
testcase_09 AC 21 ms
74,144 KB
testcase_10 AC 22 ms
74,204 KB
testcase_11 AC 47 ms
74,212 KB
testcase_12 AC 48 ms
74,212 KB
testcase_13 AC 47 ms
74,212 KB
testcase_14 AC 47 ms
74,212 KB
testcase_15 AC 47 ms
74,212 KB
testcase_16 AC 52 ms
74,212 KB
testcase_17 AC 41 ms
74,212 KB
testcase_18 AC 51 ms
74,212 KB
testcase_19 AC 25 ms
74,212 KB
testcase_20 AC 23 ms
74,212 KB
testcase_21 AC 32 ms
74,212 KB
testcase_22 AC 35 ms
74,212 KB
testcase_23 AC 43 ms
74,212 KB
testcase_24 AC 46 ms
74,212 KB
testcase_25 AC 41 ms
74,212 KB
testcase_26 AC 38 ms
74,212 KB
testcase_27 AC 42 ms
74,212 KB
testcase_28 AC 38 ms
74,212 KB
testcase_29 AC 42 ms
74,212 KB
testcase_30 AC 34 ms
74,212 KB
testcase_31 AC 46 ms
74,212 KB
testcase_32 AC 47 ms
74,212 KB
testcase_33 AC 46 ms
74,212 KB
testcase_34 AC 46 ms
74,212 KB
testcase_35 AC 47 ms
74,212 KB
testcase_36 AC 45 ms
74,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


template<typename T>
class Cumsum{
    public:
    Cumsum(vector<T> v): v(v){
        n = v.size();
        v_cumsum = vector<T>(n+1, T(0));
        for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i];
    }
    /**
     * v[l] + ... + v[r-1]
     */ 
    T sum(int l, int r){
        if(r <= l) return T(0);
        if(r > n) r = n;
        if(l < 0) l = 0;
        return v_cumsum[r]-v_cumsum[l];
    }
    private:
    int n;
    vector<T> v;
    vector<T> v_cumsum;
};

using mint = atcoder::modint998244353;


ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

void test(int n){
    
}

mint dp[1505][6005][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    string s; cin >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == '1') continue;
        dp[i][n-1][0] = 1;
        if(s[i] == '0') break;
    }
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 4*n; j++){
            if(s[i] != '0'){
                dp[i][j][1] += dp[i-1][j][0]+dp[i-1][j][1];
            }
            if(s[i] != '1'){
                // 一つ前が1
                dp[i][j+1][0] += dp[i-1][j][1];
                // 一つ前が0
                dp[i][j-1][0] += dp[i-1][j][0];
            }
        }
    }
    mint ans = 0;
    for(int j = n; j < 4*n; j+=2){
        ans += dp[n-1][j][0]+dp[n-1][j][1];
    }
    bool ok = true;
    for(int i = 0; i < n; i++){
        if(s[i] == '0') ok = false;
    }
    if(ok) ans += 1;
    cout << ans << endl;
}
0