結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー sapphire__15
提出日時 2022-08-26 06:00:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 43,696 KB
最終ジャッジ日時 2024-12-21 17:56:12
合計ジャッジ時間 29,013 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from functools import reduce
from numpy import roll


def main():
    N = int(input())
    S = input()
    CON = "con"

    buff = [defaultdict(lambda: 0) for _ in range(3)]

    for i, j in enumerate(S):
        buff[i%3][j] += 1
    
    cnt = [reduce(min,
                  map(lambda x, y: x[y],
                      roll(buff, i), CON))
           for i in range(3)]

    if cnt[0] == N:
        print(N)
    else:
        print(min(sum(cnt), N-1))

if __name__ == '__main__':
    main()
0