Submission #1243624

#TimeUsernameProblemLanguageResultExecution timeMemory
1243624CrabCNHJOIOJI (JOI14_joioji)C++20
0 / 100
1 ms324 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxN = 2e5 + 5;
const int c[3] = {'J', 'O', 'I'};

int n;
int pfs[maxN][3];

inline bool check (int x) {
    x *= 3;
    for (int i = x; i <= n; i ++) {
        int j = i - x + 1;
        vector <int> t(3, 0);
        for (int k = 0; k < 3; k ++) {
            t[k] += pfs[i][k] - pfs[j - 1][k];
        }
        if (t[0] == t[1] && t[1] == t[2]) {
            return true;
        }
    }
    return false;
}

signed main () {
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        char cc;
        cin >> cc;
        for (int j = 0; j < 3; j ++) {
            if (cc == c[j]) {
                pfs[i][j] = pfs[i - 1][j] + 1;
            }
            else {
                pfs[i][j] = pfs[i - 1][j];
            }
        }
    }
    int l = 0, r = n / 3, res = 0;
    while (true) {
        if (l > r) {
            break;
        }
        int mid = (l + r) >> 1;
        if (check (mid)) {
            res = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    cout << res * 3;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...