結果

問題 No.2279 OR Insertion
ユーザー HaaHaa
提出日時 2023-04-21 23:00:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 688 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 166,308 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:02:08
合計ジャッジ時間 12,073 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 43 ms
5,376 KB
testcase_03 AC 20 ms
5,376 KB
testcase_04 AC 331 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 128 ms
5,376 KB
testcase_07 AC 142 ms
5,376 KB
testcase_08 AC 48 ms
5,376 KB
testcase_09 AC 185 ms
5,376 KB
testcase_10 AC 320 ms
5,376 KB
testcase_11 AC 36 ms
5,376 KB
testcase_12 AC 249 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 159 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 126 ms
5,376 KB
testcase_18 AC 219 ms
5,376 KB
testcase_19 AC 287 ms
5,376 KB
testcase_20 AC 145 ms
5,376 KB
testcase_21 AC 106 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 375 ms
5,376 KB
testcase_33 AC 360 ms
5,376 KB
testcase_34 AC 360 ms
5,376 KB
testcase_35 AC 363 ms
5,376 KB
testcase_36 AC 372 ms
5,376 KB
testcase_37 AC 361 ms
5,376 KB
testcase_38 AC 365 ms
5,376 KB
testcase_39 AC 363 ms
5,376 KB
testcase_40 AC 362 ms
5,376 KB
testcase_41 AC 369 ms
5,376 KB
testcase_42 AC 613 ms
5,376 KB
testcase_43 AC 615 ms
5,376 KB
testcase_44 AC 610 ms
5,376 KB
testcase_45 AC 85 ms
5,376 KB
testcase_46 AC 84 ms
5,376 KB
testcase_47 AC 82 ms
5,376 KB
testcase_48 AC 688 ms
5,376 KB
testcase_49 AC 15 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
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;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

long long power(long long x, long long y){
    x%=MOD;
    long long ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}
long long divid(long long x, long long y){
    x%=MOD;
    return x*power(y,MOD-2)%MOD;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    VI p(n+1,0); p[0]=1;
    REP(i,n) p[i+1]=p[i]*2%MOD;
    ll ans=0;
    for(int i=1;i<=n;i++){
        VI sum(n+1,0);
        REP(j,n-i+1){
            sum[j+1]=sum[j];
            if(s[j]=='1'){
                ll x;
                if(j<n-i)
                    x=(p[n-i-1]-(j-i+1>=0?divid(sum[j-i+1],p[i]):0)+MOD)%MOD;
                else
                    x=(p[n-i]-(j-i+1>=0?divid(sum[j-i+1],p[i-1]):0)+MOD)%MOD;
                sum[j+1]=(sum[j+1]+x)%MOD;
                ans=(ans+x*p[i-1])%MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0