結果

問題 No.145 yukiover
ユーザー maspy
提出日時 2020-03-03 23:25:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 900 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 14,116 KB
最終ジャッジ日時 2024-10-13 23:22:37
合計ジャッジ時間 2,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

# %%
N = int(readline())
S = read().rstrip().decode()


# %%
def test(n, alphabets, word):
    """alphabetsを使ってwordより真に大きいものをn個つくれる"""
    if n <= 0:
        return True
    if not word:
        return len(alphabets) >= n
    w = word[0]
    while alphabets and alphabets[-1] > w:
        alphabets.pop()
        n -= 1
    if n <= 0:
        return True
    if len(alphabets) < n:
        return False
    if alphabets[-n] < w:
        return False
    return test(n, alphabets[:-n], word[1:])


# %%
A = sorted(S)
left = 0
right = N + 1
while left + 1 < right:
    x = (left + right) // 2
    if test(x, A[:], 'yuki'):
        left = x
    else:
        right = x


# %%
print(left)
0