結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー ygd.
提出日時 2022-09-16 23:09:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,418 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 65,152 KB
最終ジャッジ日時 2024-12-21 22:39:24
合計ジャッジ時間 3,428 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import math
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    n = int(input())
    S = str(input())

    C = [0,0,0]; O = [0,0,0]; N = [0,0,0]

    for i in range(3*n):
        if S[i] == 'c':
            C[i%3] += 1
        if S[i] == 'o':
            O[i%3] += 1
        if S[i] == 'n':
            N[i%3] += 1
    
    first = min(C[0],O[1],N[2])
    second = min(C[1],O[2],N[0])
    third = min(C[2],O[0],N[1])
    # print(C,O,N,first,second,third)

    block = first
    ans = first

    if second > 0:
        block += second + 1
        if block > n:
            ans += second-1
            print(ans);exit()
        else:
            ans += second
    
    if third > 0:
        if second > 0:
            block += third
        else:
            block += third + 1

        if block > n:
            ans += third - 1
        else:
            ans += third
    print(ans)


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