結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー gew1fw
提出日時 2025-06-12 18:47:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 54,164 KB
最終ジャッジ日時 2025-06-12 18:47:50
合計ジャッジ時間 3,078 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

D = int(input())
cal = []
cal.append(input().strip())
cal.append(input().strip())
cal = ''.join(cal)

# Create an extended array with 14 days before and after
extended = ['x'] * 14 + list(cal) + ['x'] * 14
n = len(extended)

# Find all consecutive x intervals
intervals = []
current_start = None
for i in range(n):
    if extended[i] == 'x':
        if current_start is None:
            current_start = i
    else:
        if current_start is not None:
            intervals.append((current_start, i - 1))
            current_start = None
if current_start is not None:
    intervals.append((current_start, n - 1))

max_len = 0

for s, e in intervals:
    L = e - s + 1
    k = min(L, D)
    if k == 0:
        continue
    
    # Try leftmost k days
    temp = extended.copy()
    for i in range(s, s + k):
        temp[i] = 'o'
    current = 0
    max_current = 0
    for c in temp:
        if c == 'o':
            current += 1
            max_current = max(max_current, current)
        else:
            current = 0
    max_len = max(max_len, max_current)
    
    # Try rightmost k days
    temp = extended.copy()
    for i in range(e - k + 1, e + 1):
        temp[i] = 'o'
    current = 0
    max_current = 0
    for c in temp:
        if c == 'o':
            current += 1
            max_current = max(max_current, current)
        else:
            current = 0
    max_len = max(max_len, max_current)

print(max_len)
0