結果

問題 No.1654 Binary Compression
ユーザー chineristACchineristAC
提出日時 2021-08-20 23:13:36
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 604,520 KB
最終ジャッジ日時 2024-04-22 07:31:11
合計ジャッジ時間 20,252 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,840 KB
testcase_01 AC 38 ms
51,968 KB
testcase_02 AC 37 ms
52,592 KB
testcase_03 AC 38 ms
52,608 KB
testcase_04 AC 38 ms
51,840 KB
testcase_05 AC 37 ms
52,352 KB
testcase_06 AC 37 ms
52,352 KB
testcase_07 AC 38 ms
52,736 KB
testcase_08 AC 37 ms
52,224 KB
testcase_09 AC 36 ms
52,352 KB
testcase_10 AC 545 ms
324,784 KB
testcase_11 AC 547 ms
327,596 KB
testcase_12 AC 523 ms
321,104 KB
testcase_13 AC 547 ms
332,060 KB
testcase_14 AC 536 ms
327,248 KB
testcase_15 AC 615 ms
331,720 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 547 ms
322,124 KB
testcase_19 AC 575 ms
334,292 KB
testcase_20 AC 570 ms
333,728 KB
testcase_21 AC 558 ms
322,204 KB
testcase_22 AC 551 ms
322,300 KB
testcase_23 AC 81 ms
78,208 KB
testcase_24 AC 81 ms
77,952 KB
testcase_25 AC 81 ms
77,988 KB
testcase_26 AC 83 ms
78,464 KB
testcase_27 AC 794 ms
425,792 KB
testcase_28 AC 829 ms
434,708 KB
testcase_29 AC 81 ms
78,208 KB
testcase_30 AC 82 ms
77,952 KB
testcase_31 AC 85 ms
79,872 KB
testcase_32 AC 86 ms
78,336 KB
testcase_33 AC 844 ms
472,364 KB
testcase_34 AC 841 ms
477,692 KB
testcase_35 AC 93 ms
82,728 KB
testcase_36 AC 103 ms
82,688 KB
testcase_37 AC 101 ms
82,560 KB
testcase_38 AC 95 ms
82,636 KB
testcase_39 AC 85 ms
79,360 KB
testcase_40 AC 88 ms
80,000 KB
testcase_41 AC 72 ms
72,832 KB
testcase_42 AC 105 ms
80,512 KB
testcase_43 AC 72 ms
73,728 KB
testcase_44 AC 68 ms
73,344 KB
testcase_45 AC 68 ms
73,600 KB
testcase_46 AC 88 ms
80,640 KB
testcase_47 AC 39 ms
51,840 KB
testcase_48 AC 37 ms
52,224 KB
testcase_49 MLE -
testcase_50 MLE -
testcase_51 AC 291 ms
190,212 KB
testcase_52 AC 279 ms
189,892 KB
権限があれば一括ダウンロードができます

ソースコード

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)
comp = [data[i][1] for i in range(n)]
if n==1:
    print(comp[0]*Start*End)
    exit()

stack=[]
dp = [0]*n
dp[0] = comp[0]
pre = [0]*n

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

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

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