結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー lam6er
提出日時 2025-04-16 01:16:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,119 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 54,540 KB
最終ジャッジ日時 2025-04-16 01:16:43
合計ジャッジ時間 3,025 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

D = int(input())
s = input().strip() + input().strip()

segments = []
if s:
    current_type = s[0]
    current_length = 1
    for c in s[1:]:
        if c == current_type:
            current_length += 1
        else:
            segments.append((current_type, current_length))
            current_type = c
            current_length = 1
    segments.append((current_type, current_length))

max_d = 0
for typ, length in segments:
    if typ == 'o' and length > max_d:
        max_d = length

if D == 0:
    print(max_d)
    exit()

max_a = D
if segments and segments[0][0] == 'o':
    max_a = D + segments[0][1]

max_b = D
if segments and segments[-1][0] == 'o':
    max_b = segments[-1][1] + D

max_c = 0
for i in range(len(segments)):
    typ, length = segments[i]
    if typ == 'x':
        prev_o = segments[i-1][1] if i > 0 and segments[i-1][0] == 'o' else 0
        next_o = segments[i+1][1] if i < len(segments)-1 and segments[i+1][0] == 'o' else 0
        current = prev_o + min(length, D) + next_o
        if current > max_c:
            max_c = current

result = max(max_a, max_b, max_c, max_d)
print(result)
0