結果

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

ソースコード

diff #

D = int(input())
cal = list(input().strip() + input().strip())
n = 14

# Precompute left and right contiguous 'o's
left_contiguous = [0] * n
left_contiguous[0] = 1 if cal[0] == 'o' else 0
for i in range(1, n):
    if cal[i] == 'o':
        left_contiguous[i] = left_contiguous[i-1] + 1
    else:
        left_contiguous[i] = 0

right_contiguous = [0] * n
right_contiguous[-1] = 1 if cal[-1] == 'o' else 0
for i in range(n-2, -1, -1):
    if cal[i] == 'o':
        right_contiguous[i] = right_contiguous[i+1] + 1
    else:
        right_contiguous[i] = 0

# Calculate original maximum consecutive 'o's
max_original = 0
current = 0
for c in cal:
    if c == 'o':
        current += 1
        if current > max_original:
            max_original = current
    else:
        current = 0

# Extract all intervals of consecutive 'x's
x_intervals = []
s = None
for i in range(n):
    if cal[i] == 'x':
        if s is None:
            s = i
    else:
        if s is not None:
            x_intervals.append((s, i-1))
            s = None
if s is not None:
    x_intervals.append((s, n-1))

max_result = max_original

for s, e in x_intervals:
    L = e - s + 1
    # Calculate m (previous 'o's)
    m = 0
    if s > 0 and cal[s-1] == 'o':
        m = left_contiguous[s-1]
    # Calculate n (next 'o's)
    n_val = 0
    if e < n-1 and cal[e+1] == 'o':
        n_val = right_contiguous[e+1]
    
    if D == 0:
        continue  # No change possible
    
    # Case 1: Convert entire interval (if possible)
    if D >= L:
        case1 = m + L + n_val
        if case1 > max_result:
            max_result = case1
    else:
        # Case 2: Leftmost D days
        case2 = m + D
        # Case 3: Rightmost D days
        case3 = D + n_val
        # Case 4: Any D days (middle)
        case4 = D
        current_max = max(case2, case3, case4)
        if current_max > max_result:
            max_result = current_max

print(max_result)
0