結果

問題 No.2738 CPC To F
ユーザー gew1fw
提出日時 2025-06-12 15:15:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 124,224 KB
最終ジャッジ日時 2025-06-12 15:15:19
合計ジャッジ時間 2,367 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

def max_cpctf():
    import sys
    n = int(sys.stdin.readline())
    s = sys.stdin.readline().strip()
    s_list = list(s)
    possible = []
    
    # 首先找出所有可以替换的 CPC 位置
    for i in range(len(s_list) - 2):
        if s_list[i] == 'C' and s_list[i+1] == 'P' and s_list[i+2] == 'C':
            # 检查替换后是否能在i的位置形成 CPCTF
            # 只需检查i-4的位置是否是 C-P-C-T
            if i -4 >=0:
                if s_list[i-4] == 'C' and s_list[i-3] == 'P' and s_list[i-2] == 'C' and s_list[i-1] == 'T':
                    possible.append(i-4)
    
    # 现在,找出所有原始的 CPCTF 结构
    original = []
    for i in range(len(s_list) -4):
        if s_list[i] == 'C' and s_list[i+1] == 'P' and s_list[i+2] == 'C' and s_list[i+3] == 'T' and s_list[i+4] == 'F':
            original.append(i)
    
    # 合并所有可能的位置,确保不重叠
    all_positions = set(original)
    for pos in possible:
        all_positions.add(pos)
    
    # 将所有位置排序,并用贪心算法选择尽可能多的不重叠结构
    sorted_positions = sorted(all_positions)
    count = 0
    last_end = -1
    for pos in sorted_positions:
        if pos > last_end:
            count +=1
            last_end = pos +4
    print(count)
    
max_cpctf()
0