結果

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

ソースコード

diff #

n = int(input())
s = input().strip()

initial = 0
# Precompute the initial count
for a in range(n - 4):
    if s[a] == 'C' and s[a+1] == 'P' and s[a+2] == 'C' and s[a+3] == 'T' and s[a+4] == 'F':
        initial += 1

intervals = []
# Collect all possible intervals
for x in range(4, n - 2):
    # Check if x is a CPC
    if s[x] == 'C' and s[x+1] == 'P' and s[x+2] == 'C':
        a = x - 4
        if a >= 0 and (a + 3) < n:
            if s[a] == 'C' and s[a+1] == 'P' and s[a+2] == 'C' and s[a+3] == 'T':
                intervals.append((x, x + 2))

# Sort intervals by end
intervals.sort(key=lambda x: x[1])

# Greedy selection of non-overlapping intervals
count = 0
last_end = -1
for start, end in intervals:
    if start > last_end:
        count += 1
        last_end = end

print(initial + count)
0