結果
問題 |
No.1654 Binary Compression
|
ユーザー |
|
提出日時 | 2021-08-20 23:13:36 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,032 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 81,864 KB |
実行使用メモリ | 604,572 KB |
最終ジャッジ日時 | 2024-10-14 06:45:30 |
合計ジャッジ時間 | 19,953 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 MLE * 4 |
ソースコード
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)