結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー amylase_pepsin
提出日時 2015-06-13 01:53:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 1,000 ms
コード長 922 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-12-24 11:47:33
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

__author__ = 'amylase'

def solve(d, s):
    """
    solution for yukicoder No.204

    >>> solve(2, 'oxxoxxoooooxxo')
    8

    >>> solve(5, 'ooxxxxxooooooo')
    14

    >>> solve(1, 'oxxxxxoxoxxxxo')
    3

    >>> solve(14, 'x' * 14)
    14

    >>> solve(0, 'o' * 14)
    14

    >>> solve(2, 'x' + ('o' * 13))
    15

    :param d: maximum continuous PTO
    :param s: calendar string
    :return: longest continuous holiday
    """
    s = ('x' * 14) + s + ('x' * 14)
    n = len(s)

    answer = 0
    for i in range(n):
        j = i
        while j < n and s[j] == 'o' :
            j += 1

        used = 0
        while j < n and s[j] == 'x' and used < d:
            j += 1
            used += 1

        while j < n and s[j] == 'o' :
            j += 1

        answer = max(j - i, answer)

    return answer


if __name__ == '__main__':
    d = int(input())
    s = input() + input()
    print(solve(d, s))
0