結果

問題 No.2035 Tunnel
ユーザー あかしあみどり
提出日時 2023-02-28 22:48:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 93,268 KB
最終ジャッジ日時 2024-09-16 00:35:19
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

def oi(): return int(input())
def os(): return input()
def mi(): return list(map(int, input().split()))

# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0

from itertools import groupby

# RUN LENGTH ENCODING str -> list(tuple())
# example) "aabbbbaaca" -> [('a', 2), ('b', 4), ('a', 2), ('c', 1), ('a', 1)] 
def runLengthEncode(S: str) -> "List[tuple(str, int)]":
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, int(len(list(v)))))
    return res

input_count = 0
oi()
S = os()
def solve(S):
    dist = len(S)-S.index("#")-1
    run = runLengthEncode(S)
    if run[0][0] == "#":
        dist += run[0][1]
        ind = 1
    else:
        dist += run[1][1]
        ind = 2

    if run[-1][0] == ".":
        run = run[:-1]

    mins = 0
    if ind < len(run):
        for i in range(ind, len(run),2):
            mins = min(run[i+1][1] - run[i][1], mins)

            if (run[i+1][1] - run[i][1]) + mins > 0:
                dist += run[i+1][1] - run[i][1]

    return dist


print(solve(S))
0