이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <map>
#include <stdio.h>
#include <string.h>
using namespace std;
#define cnt_I first
#define cnt_O second.first
#define cnt_J second.second
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int N = 2e5+5;
int n, ans = 0;
string s;
iii pref[N];
map<iii,int> check;
int main()
{
    cin >> n >> s;
    if (s[0] == 'I') pref[0].cnt_I++;
    else if (s[0] == 'O') pref[0].cnt_O++;
    else pref[0].cnt_J++;
    check[pref[0]] = 1;
    for (int i = 1; i < n; i++)
    {
        pref[i] = pref[i-1];
        if (s[i] == 'I') pref[i].cnt_I++;
        else if (s[i] == 'O') pref[i].cnt_J++;
        else pref[i].cnt_O++;
        int tmp = min(pref[i].cnt_I,min(pref[i].cnt_O,pref[i].cnt_J));
        pref[i].cnt_I -= tmp;
        pref[i].cnt_O -= tmp;
        pref[i].cnt_J -= tmp;
        if (check[pref[i]])
        {
            ans = max(ans,i+1-check[pref[i]]);
        }
        else
            check[pref[i]] = i+1;
    }
    cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |