結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー kichirb3kichirb3
提出日時 2018-03-27 17:26:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 1,000 ms
コード長 2,161 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-09-07 19:02:06
合計ジャッジ時間 2,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,216 KB
testcase_01 AC 17 ms
8,388 KB
testcase_02 AC 18 ms
8,228 KB
testcase_03 AC 17 ms
8,348 KB
testcase_04 AC 16 ms
8,196 KB
testcase_05 AC 16 ms
8,272 KB
testcase_06 AC 16 ms
8,180 KB
testcase_07 AC 17 ms
8,320 KB
testcase_08 AC 16 ms
8,196 KB
testcase_09 AC 16 ms
8,208 KB
testcase_10 AC 17 ms
8,376 KB
testcase_11 AC 16 ms
8,192 KB
testcase_12 AC 17 ms
8,376 KB
testcase_13 AC 17 ms
8,208 KB
testcase_14 AC 16 ms
8,332 KB
testcase_15 AC 17 ms
8,268 KB
testcase_16 AC 17 ms
8,316 KB
testcase_17 AC 17 ms
8,400 KB
testcase_18 AC 17 ms
8,392 KB
testcase_19 AC 17 ms
8,388 KB
testcase_20 AC 16 ms
8,372 KB
testcase_21 AC 17 ms
8,368 KB
testcase_22 AC 17 ms
8,196 KB
testcase_23 AC 16 ms
8,276 KB
testcase_24 AC 17 ms
8,248 KB
testcase_25 AC 17 ms
8,388 KB
testcase_26 AC 17 ms
8,380 KB
testcase_27 AC 16 ms
8,340 KB
testcase_28 AC 17 ms
8,272 KB
testcase_29 AC 16 ms
8,216 KB
testcase_30 AC 16 ms
8,380 KB
testcase_31 AC 17 ms
8,220 KB
testcase_32 AC 16 ms
8,196 KB
testcase_33 AC 17 ms
8,260 KB
testcase_34 AC 17 ms
8,236 KB
testcase_35 AC 18 ms
8,332 KB
testcase_36 AC 17 ms
8,368 KB
testcase_37 AC 17 ms
8,212 KB
testcase_38 AC 17 ms
8,380 KB
testcase_39 AC 17 ms
8,332 KB
testcase_40 AC 17 ms
8,252 KB
testcase_41 AC 17 ms
8,372 KB
testcase_42 AC 16 ms
8,268 KB
testcase_43 AC 17 ms
8,332 KB
testcase_44 AC 18 ms
8,272 KB
testcase_45 AC 17 ms
8,368 KB
testcase_46 AC 17 ms
8,344 KB
testcase_47 AC 16 ms
8,232 KB
testcase_48 AC 17 ms
8,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.204 ゴールデン・ウィーク(2)
https://yukicoder.me/problems/no/204

問題文にある
「有給休暇として、連続した最大D日間の平日を休日とする権利が与えられます。(分割してはいけません)」とは、
単純に有給休暇を細切れに取得してはならないという意味だけではなく
- 連続して取得したD日の有給休暇が平日の島2つにまたがってはならない
という意味も含んでいるっぽい。
xoxooooooooxxo というカレンダーに対して4日の有給休暇を取得する場合、xoxooooooooDDoD もしくは DDoDooooooooxxo のようにしてはならない。

"""
import sys
from sys import stdin
input = stdin.readline


def take_days_off(D, s, cal):
    # カレンダーのs日目からD日連続の有給を取得した場合のカレンダー情報を返す
    # 有給休暇が複数の平日島にまたがってしまう場合、有給休暇を取得できないのでNoneを返す
    if D == 0:
        return cal

    t = cal[s:s+D]
    res = []
    if t[0] == 'x':
        res.append(0)
    for i in range(1, len(t)):
        if t[i-1] == 'o' and t[i] == 'x':
            res.append(i)
    if len(res) >= 2:
        return None

    gw = list(cal)
    for i in range(s, s+D):
        gw[i] = 'o'
    return ''.join(gw)


def check_longest(cal):
    # カレンダーをチェックして、一番長い連休日数を返す
    res = cal.split('x')
    ans = 0
    for r in res:
        ans = max(ans, len(r))
    return ans


def solve(D, cal):
    ans = D
    for i in range(len(cal)-D+1):
        gw = take_days_off(D, i, cal)
        if not gw is None:
            ans = max(ans, check_longest(gw))
    return ans


def main(args):
    D = int(input())
    # 素のカレンダー情報を文字列として記憶、2週間の前後で有給休暇を取得しても良いので前後D日分の平日も追加しておく
    cal = 'x' * D
    cal += input().strip()
    cal += input().strip()
    cal += 'x' * D
    ans = solve(D, cal)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0