結果

問題 No.1654 Binary Compression
ユーザー chineristAC
提出日時 2021-08-20 23:15:31
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,021 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 578,120 KB
最終ジャッジ日時 2024-10-14 06:49:26
合計ジャッジ時間 19,146 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 MLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import groupby

mod = 924844033
 
s = input()
n = len(s)

if all(s[i]=="0" for i in range(n)):
    exit(print(n))

data = []
val = s[0]
cnt = 1
for i in range(1,n):
    if s[i]==val:
        cnt += 1
    else:
        data.append((val,cnt))
        val = s[i]
        cnt = 1
data.append((val,cnt))
Start = 1
End = 1
if data[0][0]=="0":
    Start+=data[0][1]
    data=data[1:]
if data[-1][0]=="0":
    End+=data[-1][1]
    data.pop()
 
n = len(data)
if n==1:
    print(data[0][1]*Start*End)
    exit()

stack=[]
dp = [0]*n
dp[0] = data[0][1]
pre = [0]*n

for i in range(2,n,2):
    j = -1
    while stack and data[stack[-1]][1]<data[i-1][1]:
        stack.pop()
    if stack:
        j = stack[-1]
    stack.append(i-1)

    if j==-1:
        res = (data[i-1][1]*dp[i-2] % mod)
        pre[i-1] = res
    else:
        res=((data[i-1][1]*dp[i-2] % mod)+pre[j]-(data[i-1][1]*dp[j-1] % mod))%mod
        pre[i-1] = res
    dp[i]=((data[i][1]*res % mod)+dp[i-2]+data[i][1])%mod

print((dp[-1]*Start*End)%mod)
0