結果

問題 No.2279 OR Insertion
ユーザー otoshigootoshigo
提出日時 2023-04-21 23:23:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,275 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 80,900 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:22:59
合計ジャッジ時間 30,856 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 125 ms
5,376 KB
testcase_03 AC 51 ms
5,376 KB
testcase_04 AC 1,056 ms
5,376 KB
testcase_05 AC 13 ms
5,376 KB
testcase_06 AC 418 ms
5,376 KB
testcase_07 AC 456 ms
5,376 KB
testcase_08 AC 131 ms
5,376 KB
testcase_09 AC 608 ms
5,376 KB
testcase_10 AC 1,020 ms
5,376 KB
testcase_11 AC 104 ms
5,376 KB
testcase_12 AC 805 ms
5,376 KB
testcase_13 AC 37 ms
5,376 KB
testcase_14 AC 48 ms
5,376 KB
testcase_15 AC 502 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 415 ms
5,376 KB
testcase_18 AC 699 ms
5,376 KB
testcase_19 AC 919 ms
5,376 KB
testcase_20 AC 465 ms
5,376 KB
testcase_21 AC 337 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1,153 ms
5,376 KB
testcase_33 AC 1,162 ms
5,376 KB
testcase_34 AC 1,162 ms
5,376 KB
testcase_35 AC 1,165 ms
5,376 KB
testcase_36 AC 1,161 ms
5,376 KB
testcase_37 AC 1,166 ms
5,376 KB
testcase_38 AC 1,168 ms
5,376 KB
testcase_39 AC 1,167 ms
5,376 KB
testcase_40 AC 1,162 ms
5,376 KB
testcase_41 AC 1,159 ms
5,376 KB
testcase_42 AC 982 ms
5,376 KB
testcase_43 AC 982 ms
5,376 KB
testcase_44 AC 988 ms
5,376 KB
testcase_45 AC 1,258 ms
5,376 KB
testcase_46 AC 1,257 ms
5,376 KB
testcase_47 AC 1,261 ms
5,376 KB
testcase_48 AC 920 ms
5,376 KB
testcase_49 AC 1,275 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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