結果

問題 No.2279 OR Insertion
ユーザー otoshigo
提出日時 2023-04-21 23:23:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,295 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 77,500 KB
最終ジャッジ日時 2025-02-12 12:34:31
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll MOD=998244353;

template <class T>
struct FenwickTree{
    int n;
    vector<T> bit;
    FenwickTree(int N){
        bit.resize(N+1);
        n = N;
    }
    T sum(int i){
        i++;
        T s = 0;
        while (i > 0){
            s += bit[i];
            s %= MOD;
            i -= i & -i;
        }
        return s;
    }
    T sum(int l, int r){
        if (l >= r) return 0;
        return (sum(r-1) - sum(l-1)) % MOD;
    }
    void add(int i, T x){
        i++;
        while (i <= n){
            bit[i] += x;
            bit[i] %= MOD;
            i += i & -i;
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0,p=1,q=1;
    rep(i,n-1)q=2*q%MOD;
    rep(i,n){
        FenwickTree<ll>fw(n+2);
        fw.add(n,1);
        fw.add(n+1,-1);
        rrep(j,n){
            ll c=fw.sum(0,j+2);
            fw.add(max(0,j-i+1),c);
            fw.add(j+1,-c);
            if(j-i>=0&&s[j-i]=='0'){
                fw.add(0,c);
                fw.add(j-i+1,-c);
            }
        }
        ans+=p*(q-fw.sum(0,1))%MOD;
        ans%=MOD;
        p=2*p%MOD;
    }
    if(ans<0)ans+=MOD;
    cout<<ans<<"\n";
}
0