結果

問題 No.1654 Binary Compression
ユーザー chocoruskchocorusk
提出日時 2021-06-15 01:49:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,402 bytes
コンパイル時間 2,863 ms
コンパイル使用メモリ 158,012 KB
実行使用メモリ 30,876 KB
最終ジャッジ日時 2024-04-22 03:21:28
合計ジャッジ時間 9,203 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
27,008 KB
testcase_01 AC 8 ms
27,088 KB
testcase_02 AC 8 ms
26,880 KB
testcase_03 AC 8 ms
27,088 KB
testcase_04 AC 9 ms
27,088 KB
testcase_05 AC 9 ms
26,964 KB
testcase_06 AC 8 ms
27,084 KB
testcase_07 AC 8 ms
27,008 KB
testcase_08 AC 8 ms
27,084 KB
testcase_09 AC 7 ms
27,008 KB
testcase_10 AC 118 ms
30,620 KB
testcase_11 AC 121 ms
30,792 KB
testcase_12 AC 122 ms
30,744 KB
testcase_13 AC 126 ms
30,876 KB
testcase_14 AC 122 ms
30,744 KB
testcase_15 AC 123 ms
30,872 KB
testcase_16 AC 114 ms
30,876 KB
testcase_17 AC 112 ms
30,872 KB
testcase_18 AC 122 ms
30,740 KB
testcase_19 AC 125 ms
30,744 KB
testcase_20 AC 129 ms
30,876 KB
testcase_21 AC 125 ms
30,876 KB
testcase_22 AC 124 ms
30,868 KB
testcase_23 AC 72 ms
30,748 KB
testcase_24 AC 77 ms
30,868 KB
testcase_25 AC 71 ms
30,872 KB
testcase_26 AC 73 ms
30,620 KB
testcase_27 AC 105 ms
30,616 KB
testcase_28 AC 107 ms
30,744 KB
testcase_29 AC 74 ms
30,744 KB
testcase_30 AC 76 ms
30,740 KB
testcase_31 AC 78 ms
30,744 KB
testcase_32 AC 75 ms
30,616 KB
testcase_33 AC 105 ms
30,688 KB
testcase_34 AC 108 ms
30,868 KB
testcase_35 AC 73 ms
30,616 KB
testcase_36 AC 74 ms
30,616 KB
testcase_37 AC 74 ms
30,876 KB
testcase_38 AC 72 ms
30,784 KB
testcase_39 AC 76 ms
30,616 KB
testcase_40 AC 86 ms
30,744 KB
testcase_41 AC 79 ms
30,616 KB
testcase_42 AC 73 ms
30,616 KB
testcase_43 AC 72 ms
30,740 KB
testcase_44 AC 77 ms
30,872 KB
testcase_45 AC 78 ms
30,876 KB
testcase_46 AC 62 ms
30,748 KB
testcase_47 AC 8 ms
26,880 KB
testcase_48 AC 8 ms
26,960 KB
testcase_49 AC 114 ms
30,616 KB
testcase_50 AC 119 ms
30,748 KB
testcase_51 AC 101 ms
30,612 KB
testcase_52 AC 104 ms
30,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint=static_modint<924844033>;
using P=pair<int, int>;
mint dp[3000010], dps[3000010];
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    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