結果
問題 | No.2073 Concon Substrings (Swap Version) |
ユーザー | t98slider |
提出日時 | 2022-09-16 21:55:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 1,726 ms |
コンパイル使用メモリ | 171,372 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-21 19:40:59 |
合計ジャッジ時間 | 3,382 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int n; string s; cin >> n >> s; vector<vector<int>> cnt(3, vector<int>(26)); for(int i = 0; i < s.size(); i++){ cnt[i % 3][s[i] - 'a']++; } int C = 'c' - 'a', O = 'o' - 'a', N = 'n' - 'a'; int i0 = 0, i1 = 1, i2 = 2; int ans = 0; while(cnt[0][C] >= 1 && cnt[1][O] >= 1 && cnt[2][N] >= 1 && i2 < 3 * n){ cnt[0][C]--, cnt[1][O]--, cnt[2][N]--; ans++; i0 += 3, i1 += 3, i2 += 3; } i0 += 3; while(cnt[1][C] >= 1 && cnt[2][O] >= 1 && cnt[0][N] >= 1 && i0 < 3 * n){ cnt[1][C]--, cnt[2][O]--, cnt[0][N]--; ans++; i0 += 3, i1 += 3, i2 += 3; } i1 += 3; while(cnt[2][C] >= 1 && cnt[0][O] >= 1 && cnt[1][N] >= 1 && i1 < 3 * n){ cnt[2][C]--, cnt[0][O]--, cnt[1][N]--; ans++; i0 += 3, i1 += 3, i2 += 3; } cout << ans << '\n'; }