結果
| 問題 |
No.204 ゴールデン・ウィーク(2)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:42:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,516 bytes |
| コンパイル時間 | 363 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 54,396 KB |
| 最終ジャッジ日時 | 2025-03-20 20:42:18 |
| 合計ジャッジ時間 | 3,443 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 24 |
ソースコード
D = int(input())
part1 = input().strip()
part2 = input().strip()
calendar = part1 + part2
days = [c == 'o' for c in calendar]
# Compute left (consecutive o's ending at i) and right (consecutive o's starting at i)
n = len(days)
left = [0] * n
current = 0
for i in range(n):
if days[i]:
current += 1
else:
current = 0
left[i] = current
right = [0] * n
current = 0
for i in range(n-1, -1, -1):
if days[i]:
current += 1
else:
current = 0
right[i] = current
max_original = max(left + right)
# Candidate for front application (D days before the input)
candidate_front = 0
if days[0]:
candidate_front = D + right[0]
# Candidate for back application (D days after the input)
candidate_back = 0
if days[-1]:
candidate_back = left[-1] + D
# Find all x-ranges in the input days
x_ranges = []
i = 0
while i < n:
if not days[i]:
start = i
while i < n and not days[i]:
i += 1
end = i - 1
x_ranges.append((start, end))
else:
i += 1
max_x_candidate = 0
for (start, end) in x_ranges:
L = end - start + 1
A = 0
if start > 0 and days[start - 1]:
A = left[start - 1]
B = 0
if end < n - 1 and days[end + 1]:
B = right[end + 1]
used = min(D, L)
current_candidate = A + used + B
if current_candidate > max_x_candidate:
max_x_candidate = current_candidate
max_total = max(max_original, candidate_front, candidate_back, max_x_candidate)
print(max_total)
lam6er