結果

問題 No.2035 Tunnel
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-28 22:48:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 98,740 KB
最終ジャッジ日時 2023-10-14 05:11:29
合計ジャッジ時間 5,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,068 KB
testcase_01 AC 77 ms
71,500 KB
testcase_02 AC 75 ms
71,324 KB
testcase_03 AC 76 ms
71,288 KB
testcase_04 AC 77 ms
71,284 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 95 ms
76,808 KB
testcase_08 AC 108 ms
98,504 KB
testcase_09 AC 105 ms
98,740 KB
testcase_10 AC 107 ms
98,396 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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