結果

問題 No.1654 Binary Compression
ユーザー chineristACchineristAC
提出日時 2021-08-20 23:27:48
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 625,588 KB
最終ジャッジ日時 2024-04-22 08:00:33
合計ジャッジ時間 21,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,532 KB
testcase_01 AC 38 ms
53,364 KB
testcase_02 AC 39 ms
54,028 KB
testcase_03 AC 39 ms
53,080 KB
testcase_04 AC 40 ms
53,228 KB
testcase_05 AC 39 ms
53,820 KB
testcase_06 AC 39 ms
52,740 KB
testcase_07 AC 38 ms
53,536 KB
testcase_08 AC 40 ms
52,692 KB
testcase_09 AC 39 ms
53,200 KB
testcase_10 AC 557 ms
291,004 KB
testcase_11 AC 564 ms
293,296 KB
testcase_12 AC 530 ms
286,036 KB
testcase_13 AC 559 ms
297,056 KB
testcase_14 AC 547 ms
293,564 KB
testcase_15 AC 576 ms
297,048 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 569 ms
287,320 KB
testcase_19 AC 587 ms
298,672 KB
testcase_20 AC 610 ms
298,908 KB
testcase_21 AC 580 ms
287,576 KB
testcase_22 AC 558 ms
286,984 KB
testcase_23 AC 83 ms
79,260 KB
testcase_24 AC 84 ms
78,532 KB
testcase_25 AC 83 ms
78,648 KB
testcase_26 AC 84 ms
78,564 KB
testcase_27 AC 841 ms
368,508 KB
testcase_28 AC 853 ms
365,424 KB
testcase_29 AC 83 ms
78,752 KB
testcase_30 AC 83 ms
77,652 KB
testcase_31 AC 86 ms
79,440 KB
testcase_32 AC 83 ms
78,256 KB
testcase_33 AC 870 ms
374,788 KB
testcase_34 AC 879 ms
386,824 KB
testcase_35 AC 95 ms
82,380 KB
testcase_36 AC 103 ms
82,592 KB
testcase_37 AC 101 ms
82,412 KB
testcase_38 AC 90 ms
80,084 KB
testcase_39 AC 86 ms
79,416 KB
testcase_40 AC 89 ms
79,864 KB
testcase_41 AC 75 ms
75,084 KB
testcase_42 AC 107 ms
81,204 KB
testcase_43 AC 74 ms
73,200 KB
testcase_44 AC 71 ms
73,720 KB
testcase_45 AC 72 ms
74,536 KB
testcase_46 AC 89 ms
80,636 KB
testcase_47 AC 39 ms
53,360 KB
testcase_48 AC 39 ms
53,712 KB
testcase_49 MLE -
testcase_50 MLE -
testcase_51 AC 276 ms
178,436 KB
testcase_52 AC 279 ms
178,340 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 = data[0][1]
pre = 0

for i in range(2,n,2):
    j = -1
    while stack and data[stack[-1][0]][1]<data[i-1][1]:
        stack.pop()
    if stack:
        j,dpj,pj = stack[-1]
        pi = ((data[i-1][1]*dp % mod)+pj-(data[i-1][1]*dpj % mod))%mod
        stack.append((i-1,dp,pi))
        dpi = ((data[i][1]*pi % mod)+dp+data[i][1])%mod
        dp = dpi
    else:
        pi = data[i-1][1] * dp % mod
        stack.append((i-1,dp,pi))
        dpi = ((data[i][1]*pi % mod)+dp+data[i][1])%mod
        dp = dpi
        

print((dp*Start*End)%mod)
0