結果
| 問題 | No.2738 CPC To F | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 19:55:56 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,681 bytes | 
| コンパイル時間 | 191 ms | 
| コンパイル使用メモリ | 82,576 KB | 
| 実行使用メモリ | 98,976 KB | 
| 最終ジャッジ日時 | 2025-06-12 19:56:50 | 
| 合計ジャッジ時間 | 2,491 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 5 WA * 17 | 
ソースコード
n = int(input())
s = input().strip()
# Step 1: Find all original CPCTF substrings
original = []
for i in range(n - 4):
    if s[i] == 'C' and s[i+1] == 'P' and s[i+2] == 'C' and s[i+3] == 'T' and s[i+4] == 'F':
        original.append((i, i+4))
# Step 2: Mark covered positions by original CPCTF
covered = [False] * n
for start, end in original:
    for i in range(start, end + 1):
        if i < n:
            covered[i] = True
# Step 3: Find all candidate CPC intervals
candidates = []
for i in range(n):
    if s[i] == 'T':
        # Check preceding three characters (C P C)
        if i < 3:
            continue
        if s[i-3] == 'C' and s[i-2] == 'P' and s[i-1] == 'C':
            # Check next three characters (C P C)
            if i + 3 >= n:
                continue
            if s[i+1] == 'C' and s[i+2] == 'P' and s[i+3] == 'C':
                # The CPC is at i+1, i+2, i+3
                s_candidate = i + 1
                e_candidate = i + 3
                if e_candidate < n:
                    candidates.append((s_candidate, e_candidate))
# Step 4: Filter candidates that overlap with original CPCTF
filtered = []
for s_c, e_c in candidates:
    overlap = False
    for pos in range(s_c, e_c + 1):
        if pos >= n or covered[pos]:
            overlap = True
            break
    if not overlap:
        filtered.append((s_c, e_c))
# Step 5: Sort candidates by end and select non-overlapping ones
filtered.sort(key=lambda x: x[1])
count = 0
last_end = -1
for s_c, e_c in filtered:
    if s_c > last_end:
        count += 1
        last_end = e_c
# The answer is the number of original plus the selected candidates
print(len(original) + count)
            
            
            
        