結果

問題 No.1654 Binary Compression
ユーザー chocoruskchocorusk
提出日時 2021-06-16 00:50:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 10,921 ms
コンパイル使用メモリ 294,072 KB
実行使用メモリ 49,512 KB
最終ジャッジ日時 2024-04-22 03:21:02
合計ジャッジ時間 19,834 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
27,136 KB
testcase_01 AC 10 ms
27,136 KB
testcase_02 AC 10 ms
27,264 KB
testcase_03 AC 10 ms
27,136 KB
testcase_04 AC 10 ms
27,136 KB
testcase_05 AC 10 ms
27,392 KB
testcase_06 AC 10 ms
27,264 KB
testcase_07 AC 11 ms
27,392 KB
testcase_08 AC 22 ms
27,392 KB
testcase_09 AC 20 ms
27,264 KB
testcase_10 AC 190 ms
49,252 KB
testcase_11 AC 160 ms
49,376 KB
testcase_12 AC 165 ms
49,128 KB
testcase_13 AC 162 ms
49,380 KB
testcase_14 AC 161 ms
49,136 KB
testcase_15 AC 162 ms
49,384 KB
testcase_16 AC 150 ms
49,128 KB
testcase_17 AC 150 ms
49,252 KB
testcase_18 AC 166 ms
49,380 KB
testcase_19 AC 162 ms
49,256 KB
testcase_20 AC 162 ms
49,228 KB
testcase_21 AC 163 ms
49,256 KB
testcase_22 AC 164 ms
49,124 KB
testcase_23 AC 102 ms
49,380 KB
testcase_24 AC 102 ms
49,256 KB
testcase_25 AC 101 ms
49,508 KB
testcase_26 AC 101 ms
49,380 KB
testcase_27 AC 137 ms
49,512 KB
testcase_28 AC 134 ms
49,380 KB
testcase_29 AC 103 ms
49,252 KB
testcase_30 AC 100 ms
49,384 KB
testcase_31 AC 103 ms
49,248 KB
testcase_32 AC 101 ms
49,380 KB
testcase_33 AC 136 ms
49,128 KB
testcase_34 AC 135 ms
49,252 KB
testcase_35 AC 100 ms
49,380 KB
testcase_36 AC 101 ms
49,120 KB
testcase_37 AC 101 ms
49,380 KB
testcase_38 AC 104 ms
49,252 KB
testcase_39 AC 107 ms
49,376 KB
testcase_40 AC 107 ms
49,380 KB
testcase_41 AC 107 ms
49,248 KB
testcase_42 AC 100 ms
49,376 KB
testcase_43 AC 99 ms
49,384 KB
testcase_44 AC 107 ms
49,380 KB
testcase_45 AC 106 ms
49,508 KB
testcase_46 AC 90 ms
49,124 KB
testcase_47 AC 8 ms
27,264 KB
testcase_48 AC 9 ms
27,136 KB
testcase_49 AC 145 ms
49,240 KB
testcase_50 AC 143 ms
49,120 KB
testcase_51 AC 131 ms
49,380 KB
testcase_52 AC 133 ms
49,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <atcoder/all>
#include "testlib.h"
using namespace std;
using namespace atcoder;
using mint=static_modint<924844033>;
using P=pair<int, int>;
mint dp[3000010], dps[3000010];
const int MAXN=3000000;
int main(int argc, char* argv[]){
    registerValidation(argc, argv);
    string s=inf.readString();
    int n=s.size();
    ensure(1<=n && n<=MAXN);
    for(int i=0; i<n; i++){
        ensure(s[i]=='0' || s[i]=='1');
    }
    inf.readEof();
    
    bool allzero=1;
    for(int i=0; i<n; i++) if(s[i]=='1') allzero=0;
    if(allzero){
        cout<<n<<endl;
        return 0;
    }
    dp[0]=1, dps[1]=1;
    vector<P> v{P(n+1, -1)};
    int pr1=-1;
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            dp[i+1]+=dp[i];
            if(pr1!=i-1) dp[i+1]+=dp[pr1+1];
            pr1=i;
        }else if(s[i]=='0' && (i==n-1 || s[i+1]=='1')){
            int c=i-pr1;
            int l=0, pr=i+1;
            while(v.back().first<=c){
                dp[i+1]+=(dps[pr]-dps[v.back().second+1])*mint(c-l);
                l=v.back().first;
                pr=v.back().second;
                v.pop_back();
            }
            if(pr1!=-1 && v.back().second==-1) dp[i+1]+=(dps[pr]-dps[1])*mint(c-l);
            else dp[i+1]+=(dps[pr]-dps[v.back().second+1])*mint(c-l);
            v.push_back(P(c, i+1));
        }
        dps[i+2]=dps[i+1]+(s[i]=='1'?dp[i+1]:0);
    }
    mint ans=0;
    for(int i=0; i<n; i++){
        if(s[i]=='1') ans+=dp[i+1];
    }
    if(s[n-1]=='0'){
        ans*=mint(v.back().first+1);
    }
    cout<<ans.val()<<endl;
    return 0;
}
0