結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー gew1fw
提出日時 2025-06-12 21:44:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,515 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 81,732 KB
実行使用メモリ 53,984 KB
最終ジャッジ日時 2025-06-12 21:48:26
合計ジャッジ時間 3,181 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    D = int(sys.stdin.readline())
    line1 = sys.stdin.readline().strip()
    line2 = sys.stdin.readline().strip()
    S = line1 + line2  # S is 14 characters

    # Find all runs of 'o's
    runs = []
    n = len(S)
    i = 0
    while i < n:
        if S[i] == 'o':
            start = i
            while i < n and S[i] == 'o':
                i += 1
            end = i - 1
            runs.append((start, end))
        else:
            i += 1

    # Compute max_run
    max_run = max((end - start + 1) for (start, end) in runs) if runs else 0

    # Compute possible candidates
    candidates = [max_run, D]

    # Check runs before and after
    if runs:
        first_start, first_end = runs[0]
        if first_start == 0:
            candidates.append(D + (first_end - first_start + 1))

        last_start, last_end = runs[-1]
        if last_end == len(S) - 1:
            candidates.append((last_end - last_start + 1) + D)

    # Check all pairs of runs
    for i in range(len(runs)):
        for j in range(i + 1, len(runs)):
            run_i = runs[i]
            run_j = runs[j]
            # Distance between run_i's end and run_j's start
            distance = run_j[0] - run_i[1] - 1
            if distance <= D:
                merged = (run_i[1] - run_i[0] + 1) + (run_j[1] - run_j[0] + 1) + distance
                candidates.append(merged)

    # The maximum possible
    max_length = max(candidates)
    print(max_length)

if __name__ == '__main__':
    main()
0