結果

問題 No.3015 右に寄せろ!
コンテスト
ユーザー Kohei
提出日時 2026-07-14 19:30:31
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 388 ms / 2,000 ms
+ 48µs
コード長 826 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 238 ms
コンパイル使用メモリ 96,620 KB
実行使用メモリ 279,624 KB
最終ジャッジ日時 2026-07-14 19:30:47
合計ジャッジ時間 7,043 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.set_int_max_str_digits(0)

S = input()

# 頭の0、お尻の1は捨てる
material = []
flag = True
for s in S:
    if flag:
        if s == '0':
            continue
        else:
            flag = False
            material.append(s)
    else:
        material.append(s)

while material and material[-1] == '1':
    material.pop()

from itertools import groupby
def runLengthEncode(S):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, int(len(list(v)))))
    return res

data = runLengthEncode(material)
L = len(data)

ans = 0
pre1 = 0
for i in range(L//2):
    _, cnt1 = data[2*i]
    _, cnt0 = data[2*i + 1]

    # 引継ぎ分加算
    cnt1 += pre1

    # 今回の寄与
    sub = (cnt1//2) * cnt0
    ans += sub

    # 引継ぎ
    pre1 = (cnt1//2)*2

print(ans)
0