結果

問題 No.2541 Divide 01 String
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-12-10 17:15:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 88,604 KB
最終ジャッジ日時 2023-12-10 17:15:31
合計ジャッジ時間 2,572 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 56 ms
73,656 KB
testcase_04 AC 85 ms
83,528 KB
testcase_05 AC 108 ms
88,604 KB
testcase_06 AC 71 ms
79,904 KB
testcase_07 AC 102 ms
88,288 KB
testcase_08 AC 107 ms
88,356 KB
testcase_09 AC 103 ms
88,360 KB
testcase_10 AC 50 ms
75,024 KB
testcase_11 AC 50 ms
75,152 KB
testcase_12 AC 52 ms
75,024 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 35 ms
53,460 KB
testcase_15 AC 35 ms
53,460 KB
testcase_16 AC 39 ms
53,460 KB
testcase_17 AC 35 ms
53,460 KB
testcase_18 AC 47 ms
71,588 KB
testcase_19 AC 48 ms
71,584 KB
testcase_20 AC 46 ms
71,588 KB
testcase_21 AC 46 ms
69,616 KB
testcase_22 AC 46 ms
69,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def RLE(S: list) -> list:
    """
    入力をランレングス圧縮したリストを返す.
    [(value1,length1),(value2,length2),...]

    Parameters
    ----------
    S:list

    Examples
    --------
    >>> RLE('aaabbc')
    [('a', 3), ('b', 2), ('c', 1)]
    """
    from itertools import groupby

    res = [(k, len(list(g))) for k, g in groupby(S)]
    return res


N = int(input())
S = input()
R = RLE(S)
ans = 1
MOD = 998244353
if '1' not in S:
    exit(print(0))
for i in range(len(R)):
    mid = R[i][0]
    if mid == "1":
        ans *= pow(2, R[i][1] - 1, MOD)
    if 0 <= i - 1 and i + 1 <= len(R) - 1:
        l = R[i - 1][0]
        r = R[i + 1][0]
        if l == r == "1" and mid == "0":
            ans *= R[i][1] + 2
    ans %= MOD
print(ans)
0