結果
| 問題 |
No.2738 CPC To F
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:45:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 806 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 82,296 KB |
| 実行使用メモリ | 93,216 KB |
| 最終ジャッジ日時 | 2025-06-12 14:46:58 |
| 合計ジャッジ時間 | 2,394 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 17 |
ソースコード
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)
gew1fw