結果

問題 No.1654 Binary Compression
ユーザー chineristACchineristAC
提出日時 2021-08-20 23:15:31
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,021 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 577,956 KB
最終ジャッジ日時 2024-04-22 07:35:29
合計ジャッジ時間 18,624 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,752 KB
testcase_01 AC 35 ms
54,192 KB
testcase_02 AC 33 ms
53,308 KB
testcase_03 AC 32 ms
52,572 KB
testcase_04 AC 34 ms
52,740 KB
testcase_05 AC 33 ms
52,268 KB
testcase_06 AC 34 ms
51,880 KB
testcase_07 AC 35 ms
52,560 KB
testcase_08 AC 33 ms
52,776 KB
testcase_09 AC 37 ms
53,644 KB
testcase_10 AC 542 ms
313,492 KB
testcase_11 AC 530 ms
315,604 KB
testcase_12 AC 488 ms
309,364 KB
testcase_13 AC 508 ms
320,344 KB
testcase_14 AC 505 ms
315,840 KB
testcase_15 AC 510 ms
319,912 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 510 ms
310,344 KB
testcase_19 AC 525 ms
322,720 KB
testcase_20 AC 528 ms
321,760 KB
testcase_21 AC 509 ms
310,668 KB
testcase_22 AC 509 ms
310,340 KB
testcase_23 AC 82 ms
78,440 KB
testcase_24 AC 79 ms
77,668 KB
testcase_25 AC 75 ms
78,924 KB
testcase_26 AC 79 ms
78,836 KB
testcase_27 AC 731 ms
410,864 KB
testcase_28 AC 761 ms
391,600 KB
testcase_29 AC 75 ms
78,256 KB
testcase_30 AC 76 ms
78,776 KB
testcase_31 AC 77 ms
79,628 KB
testcase_32 AC 75 ms
78,740 KB
testcase_33 AC 796 ms
428,964 KB
testcase_34 AC 791 ms
434,688 KB
testcase_35 AC 87 ms
82,192 KB
testcase_36 AC 96 ms
82,536 KB
testcase_37 AC 96 ms
82,428 KB
testcase_38 AC 85 ms
82,412 KB
testcase_39 AC 78 ms
79,532 KB
testcase_40 AC 82 ms
79,680 KB
testcase_41 AC 69 ms
73,880 KB
testcase_42 AC 97 ms
80,716 KB
testcase_43 AC 69 ms
74,160 KB
testcase_44 AC 63 ms
73,372 KB
testcase_45 AC 65 ms
74,224 KB
testcase_46 AC 81 ms
80,916 KB
testcase_47 AC 37 ms
53,460 KB
testcase_48 AC 35 ms
53,748 KB
testcase_49 MLE -
testcase_50 MLE -
testcase_51 AC 253 ms
184,472 KB
testcase_52 AC 254 ms
183,920 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)
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