結果
問題 |
No.2738 CPC To F
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:58:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,536 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 81,960 KB |
実行使用メモリ | 89,528 KB |
最終ジャッジ日時 | 2025-04-16 00:00:22 |
合計ジャッジ時間 | 2,080 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 WA * 17 |
ソースコード
n = int(input()) s = input() # Step 1: Count existing CPCTF substrings existing_list = [] 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': existing_list.append(i) # Step 2: Find all CPC that are preceded by CPCT and do not overlap with existing CPCTF's first 3 characters candidates = [] for i in range(n - 6): # Check if the current position starts with CPCT if s[i] == 'C' and s[i+1] == 'P' and s[i+2] == 'C' and s[i+3] == 'T': # Check if followed by CPC cpc_start = i + 4 if cpc_start + 2 < n and s[cpc_start] == 'C' and s[cpc_start+1] == 'P' and s[cpc_start+2] == 'C': # Check overlap with existing CPCTF's first 3 characters overlap = False for j in existing_list: existing_start = j existing_end = j + 2 # CPC spans from cpc_start to cpc_start + 2 if not (cpc_start + 2 < existing_start or cpc_start > existing_end): overlap = True break if not overlap: candidates.append((cpc_start + 2, cpc_start)) # (end, start) # Step 3: Greedily select non-overlapping CPC conversions candidates.sort() selected = [] last_end = -1 for end, start in candidates: if start > last_end: selected.append((start, end)) last_end = end # The answer is the existing count plus the number of selected conversions print(len(existing_list) + len(selected))