結果

問題 No.2040 010-1 Deletion
ユーザー sapphire__15sapphire__15
提出日時 2022-08-12 22:23:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 3,000 ms
コード長 5,295 bytes
コンパイル時間 3,228 ms
コンパイル使用メモリ 207,552 KB
実行使用メモリ 109,176 KB
最終ジャッジ日時 2023-10-24 10:35:41
合計ジャッジ時間 5,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 109 ms
109,176 KB
testcase_12 AC 109 ms
109,176 KB
testcase_13 AC 109 ms
109,176 KB
testcase_14 AC 109 ms
109,176 KB
testcase_15 AC 109 ms
109,176 KB
testcase_16 AC 117 ms
109,176 KB
testcase_17 AC 98 ms
109,176 KB
testcase_18 AC 114 ms
109,176 KB
testcase_19 AC 14 ms
15,192 KB
testcase_20 AC 8 ms
8,856 KB
testcase_21 AC 42 ms
43,176 KB
testcase_22 AC 52 ms
52,416 KB
testcase_23 AC 90 ms
91,752 KB
testcase_24 AC 103 ms
103,896 KB
testcase_25 AC 79 ms
78,552 KB
testcase_26 AC 68 ms
68,784 KB
testcase_27 AC 84 ms
84,624 KB
testcase_28 AC 67 ms
68,520 KB
testcase_29 AC 85 ms
85,944 KB
testcase_30 AC 50 ms
51,360 KB
testcase_31 AC 100 ms
100,464 KB
testcase_32 AC 105 ms
104,688 KB
testcase_33 AC 101 ms
101,520 KB
testcase_34 AC 103 ms
102,576 KB
testcase_35 AC 106 ms
102,048 KB
testcase_36 AC 97 ms
96,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i = 0; i < int(n); i++)
#define per(i,n) for(int i = (n) - 1; 0 <= i; i--)
#define rep2(i,l,r) for(int i = (l); i < int(r); i++)
#define per2(i,l,r) for(int i = (r) - 1; int(l) <= i; i--)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()

template <typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty()) cout << '\n';
}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

// const ll MOD = 1'000'000'007;
const ll MOD = 998'244'353;

///////////////////////////////////////////////////////////////

template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using maxheap = priority_queue<T>;

template <typename T>
int lb(const vector<T> &v, T x) {
    return lower_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
int ub(const vector<T> &v, T x) {
    return upper_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
void rearrange(vector<T> &v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

struct modint {
    long long num;
    const static long long p = 998244353;
    constexpr static long long pow(long long n, long long k) {//n^k(mod p)
        n %= p;
        long long ret = 1;
        while(k) {
            if(k&1) ret = ret * n % p;
            n = n * n % p;
            k >>= 1;
        }
        return ret;
    }
    // a*A + b*B = 1
    constexpr static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1
        if (a == 1) {
            a = 1;
        }
        else {
            long long A = b, B = a % b;
            euclid(A, B);
            b = (A - (p + a / b) % p * B % p + p) % p;
            a = B;
        }
    }
    constexpr static long long rev(const long long n) {// n*x-p*y=1
        //long long q = p;
        //euclid(p, n, p);
        //return n % q;
        return pow(n,p-2);
    }
    constexpr modint() : num(0) {}
    constexpr modint(long long x) : num(x%p < 0 ? x%p+p : x%p) {}
    constexpr modint inv() const {return rev(num);}
    modint operator-() const {return modint(p-num);}
    modint& operator+=(const modint &other){
        num = (num + other.num) % p;
        return *this;
    }
    modint& operator-=(const modint &other){
        num = (num - other.num + p) % p;
        return *this;
    }
    modint& operator*=(const modint &other){
        num = (num * other.num) % p;
        if(num < 0) num += p;
        return *this;
    }
    modint& operator/=(const modint &other){
        (*this) *= other.inv();
        return *this;
    }
    modint& operator+=(const long long &other){
        num = (num + other) % p;
        return *this;
    }
    modint& operator-=(const long long &other){
        num = (num - other + p) % p;
        return *this;
    }
    modint& operator*=(const long long &other){
        num = (num * (other % p)) % p;
        return *this;
    }
    modint& operator/=(const long long &other){
        (*this) *= rev(other);
        return *this;
    }
    modint& operator++(){return *this += 1;}
    modint& operator--(){return *this -= 1;}
    modint& operator=(const long long &other){return (*this) = modint(other);}
    modint operator+(const modint &other) const{return modint(*this) += other;}
    modint operator-(const modint &other) const{return modint(*this) -= other;}
    modint operator*(const modint &other) const{return modint(*this) *= other;}
    modint operator/(const modint &other) const{return modint(*this) /= other;}
    modint operator+(const long long &other) const{return modint(*this) += other;}
    modint operator-(const long long &other) const{return modint(*this) -= other;}
    modint operator*(const long long &other) const{return modint(*this) *= other;}
    modint operator/(const long long &other) const{return modint(*this) /= other;}
    bool operator==(const modint &other) const{return num == other.num;}
};
std::istream& operator>>(std::istream &is, modint x) {
    is >> x.num;
    return is;
}
std::ostream& operator<<(std::ostream &os, const modint &x){
    os << x.num;
    return os;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<modint>> dp1(n+1, vector<modint>(n*3+3));
    vector<vector<modint>> dp2(n+1, vector<modint>(n*3+3));
    dp2[0][n*2+2] += 1;
    rep(i,n) {
        if(s[i] != '0') {
            rep(j,n*3+3) {
                dp2[i+1][j] += dp2[i][j];
                if(j > 1) dp2[i+1][j-2] += dp1[i][j];
            }
        }
        if(s[i] != '1') {
            rep(j,n*3+2) {
                dp1[i+1][j+1] += dp1[i][j] + dp2[i][j];
            }
        }
    }
    modint ans = dp1.back()[n*2+2];
    for(int i = 0; i <= n*2; i+=2) {
        ans += dp1.back()[i] + dp2.back()[i];
    }
    if(s.find('0') == string::npos) ans += 1;
    cout << ans << endl;
}
0