結果

問題 No.3500 01 String
コンテスト
ユーザー 蒸した柿ピー
提出日時 2026-04-18 11:27:57
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 521 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 1,310,204 KB
最終ジャッジ日時 2026-04-18 11:28:29
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 2 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import re

N = int(input())
a = input()
result = 0

blocks = re.findall('0+|1+', a)
if "1" in blocks[0]:
    ##n = n - len(blocks[0])
    blocks = blocks[1:]
if "0" in blocks[-1]:
    ##n = n - len(blocks[-1])
    blocks = blocks[:-1]


blocks = [len(x) for x in blocks]


def merge(arr, i):
    if i == 0:
        return arr[2:]
    if i == len(arr) - 1:
        return arr[:-2]
    arr[i - 1] += arr.pop(i) + arr.pop(i)
    return arr

def calc(arr):
    global result
    n = sum(arr)
    k = len(arr)
    if k == 2:
        result += n
        result = result%998244353
        return 
    result += n
    result = result%998244353
    for i in range(k):
        calc(merge(arr, i))
    return


calc(blocks)
print(result%998244353)
0