結果

問題 No.2040 010-1 Deletion
ユーザー milkcoffeemilkcoffee
提出日時 2022-05-16 14:32:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 3,000 ms
コード長 2,943 bytes
コンパイル時間 6,683 ms
コンパイル使用メモリ 264,192 KB
実行使用メモリ 109,060 KB
最終ジャッジ日時 2023-10-14 17:50:33
合計ジャッジ時間 8,614 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 1 ms
4,368 KB
testcase_11 AC 115 ms
108,936 KB
testcase_12 AC 116 ms
108,928 KB
testcase_13 AC 115 ms
108,924 KB
testcase_14 AC 116 ms
108,980 KB
testcase_15 AC 117 ms
108,932 KB
testcase_16 AC 122 ms
109,060 KB
testcase_17 AC 102 ms
108,984 KB
testcase_18 AC 120 ms
108,992 KB
testcase_19 AC 14 ms
14,960 KB
testcase_20 AC 7 ms
8,664 KB
testcase_21 AC 45 ms
42,992 KB
testcase_22 AC 57 ms
52,372 KB
testcase_23 AC 97 ms
91,564 KB
testcase_24 AC 110 ms
103,724 KB
testcase_25 AC 82 ms
78,304 KB
testcase_26 AC 72 ms
68,600 KB
testcase_27 AC 89 ms
84,448 KB
testcase_28 AC 71 ms
68,348 KB
testcase_29 AC 89 ms
85,692 KB
testcase_30 AC 53 ms
51,112 KB
testcase_31 AC 106 ms
100,288 KB
testcase_32 AC 110 ms
104,448 KB
testcase_33 AC 107 ms
101,532 KB
testcase_34 AC 108 ms
102,656 KB
testcase_35 AC 109 ms
101,816 KB
testcase_36 AC 103 ms
96,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
#define pb push_back
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define endl "\n"

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvvll vector< vector <vector <vector<ll> > > >
#define vvvll vector< vector< vector<ll> > >
#define vvll vector< vector<ll> >
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template <class T>
using V = vector<T>;

constexpr ll INF = (1ll << 60);
//constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;

constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val)
{
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v)
{
    ll vs = v.size();
    rep(i, vs)
    {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

// O(N^2) 想定解

void solve(){
    ll n, m, k, cnt = 0, sum = 0, ans = 0;
    cin>>n;
    assert(1<=n&&n<=2000);
    string s;
    cin>>s;
    assert(s.size()==n);
    ll flag=1;
    rep(i,n){
        assert(s[i]=='0'||s[i]=='1'||s[i]=='?');
        if(s[i]=='0') flag=0;
    }
    ans+=flag;
    vvvll dp(2,vvll(n+1,vll(2*n+3)));
    // dp[k][i][j]:=i番目まで見て、(0の連続区間数*2 - 0の個数)+n+1=j, 最後の文字がk
    dp[1][0][n+1]=1;
    rep(i,n){
        rep(j,2*n+1){
            if(s[i]!='1'){
                dp[0][i+1][j]+=dp[0][i][j+1];
                dp[0][i+1][j+2]+=dp[1][i][j+1];
                dp[0][i+1][j]%=mod;
                dp[0][i+1][j+2]%=mod;
            }
            if(s[i]!='0'){
                dp[1][i+1][j+1]+=dp[0][i][j+1];
                dp[1][i+1][j+1]+=dp[1][i][j+1];
                dp[1][i+1][j+1]%=mod;
            }
        }
    }
    rep(i,2*n+3){
        if(i>=n+3&&(i+n+1)%2==0){
            ans+=dp[0][n][i];
            ans+=dp[1][n][i];
            ans%=mod;
        }
    }
    ans%=mod;
    pt(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout << fixed << setprecision(16);
    //ll T;
    //cin>>T;
    //rep(ca,T)
    solve();
}   
0