結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2022-09-16 22:17:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 112,548 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 15:57:44
合計ジャッジ時間 4,183 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 35 ms
4,376 KB
testcase_06 AC 35 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 23 ms
4,376 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 27 ms
4,384 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 24 ms
4,380 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 15 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 14 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 15 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 13 ms
4,380 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 9 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 9 ms
4,384 KB
testcase_40 AC 8 ms
4,380 KB
testcase_41 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0