結果
問題 | No.2073 Concon Substrings (Swap Version) |
ユーザー |
![]() |
提出日時 | 2025-05-14 13:20:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,391 bytes |
コンパイル時間 | 301 ms |
コンパイル使用メモリ | 82,952 KB |
実行使用メモリ | 77,044 KB |
最終ジャッジ日時 | 2025-05-14 13:21:04 |
合計ジャッジ時間 | 4,136 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 17 WA * 20 |
ソースコード
import sys def solve(): N = int(sys.stdin.readline()) S = sys.stdin.readline().strip() # counts[group_idx][char_idx] # char_idx: 0 for 'c', 1 for 'o', 2 for 'n' counts = [[0, 0, 0] for _ in range(3)] char_to_idx = {'c': 0, 'o': 1, 'n': 2} for i in range(3 * N): char = S[i] group = i % 3 if char in char_to_idx: counts[group][char_to_idx[char]] += 1 # U0: Max number of Type 0 "con"s. # A Type 0 "con" (S[j]='c', S[j+1]='o', S[j+2]='n' where j % 3 == 0) # requires 'c' from Group 0, 'o' from Group 1, 'n' from Group 2. U0 = min(counts[0][0], counts[1][1], counts[2][2]) # U1: Max number of Type 1 "con"s. # A Type 1 "con" (S[j]='c', S[j+1]='o', S[j+2]='n' where j % 3 == 1) # requires 'c' from Group 1, 'o' from Group 2, 'n' from Group 0. U1 = min(counts[1][0], counts[2][1], counts[0][2]) # U2: Max number of Type 2 "con"s. # A Type 2 "con" (S[j]='c', S[j+1]='o', S[j+2]='n' where j % 3 == 2) # requires 'c' from Group 2, 'o' from Group 0, 'n' from Group 1. U2 = min(counts[2][0], counts[0][1], counts[1][2]) # The total number of "con"s, K = x0 + x1 + x2, is limited by N (K <= N). # Also, K <= U0 + U1 + U2 because x0 <= U0, x1 <= U1, x2 <= U2. # Thus, the maximum K is min(N, U0 + U1 + U2). ans = min(N, U0 + U1 + U2) print(ans) solve()