結果

問題 No.1654 Binary Compression
ユーザー chocorusk
提出日時 2021-07-31 05:41:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 131,584 KB
最終ジャッジ日時 2024-10-14 02:19:40
合計ジャッジ時間 10,115 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD=924844033
s=input()
n=len(s)
l=0
while l<n and s[l]=='0':
    l+=1
if l==n:
    print(n)
    exit()
r=n-1
while r>=0 and s[r]=='0':
    r-=1
c=(l+1)*(n-r)
s=s[l:r+1]
n=len(s)
dp=[0]*n
dps=[0]*(n+1)
dp[0]=1
dps[1]=1
pr=0
st=[(n+1, 0)]
for i in range(1, n):
    dps[i+1]=dps[i]
    if s[i]=='1':
        dp[i]+=dp[i-1]
        if pr<i-1:
            dp[i]+=dp[pr]
        dp[i]%=MOD
        pr=i
        dps[i+1]+=dp[i]
        dps[i+1]%=MOD
    elif s[i]=='0' and s[i+1]=='1':
        d=i-pr
        ipr=i
        dpr=0
        while st:
            p=st[-1]
            dp[i]+=(dps[ipr]-dps[p[1]]+MOD)*(d-dpr)
            dp[i]%=MOD
            if p[0]>d:
                break
            ipr=p[1]
            dpr=p[0]
            st.pop()
        st.append((d, i))
print(dps[n]*c%MOD)
0