結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー NAMIDAIRO
提出日時 2022-09-16 22:17:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 113,540 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 21:29:21
合計ジャッジ時間 2,446 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T>
using vi = vector<T>;
template<class T>
using vii = vector<vi<T>>;
template<class T>
using viii = vector<vii<T>>;
struct unionfind {
vector<int> d;
vector<int> cnt;
unionfind(int n = 0) : cnt(n) {
d = vector<int>(n, -1);
}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
int rx = find(x);
int ry = find(y);
if (rx == ry) {
cnt[rx]++;
return false;
}
if (d[rx] > d[ry]) swap(rx, ry);
d[rx] += d[ry];
d[ry] = rx;
cnt[rx] = max(cnt[rx], cnt[ry]) + 1;
return true;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return -d[find(x)]; }
};
int main()
{
int n;
string s;
cin >> n >> s;
vi<map<char, int>> d(3);
rep(i, 3 * n) d[i % 3][s[i]]++;
string con = "con";
int ans = 0;
vi<int> p = { 0, 1, 2 };
do {
int pos = 0;
int ta = 0;
rep(i, 3) {
while (pos % 3 != p[i]) pos++;
if (pos >= 3 * n) break;
int temp = n;
rep(j, 3) {
int idx = (p[i] + j) % 3;
temp = min(temp, d[idx][con[j]]);
}
ta += min((3 * n - pos) / 3, temp);
pos += min((3 * n - pos) / 3, temp) * 3;
}
ans = max(ans, ta);
} while (next_permutation(p.begin(), p.end()));
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0