Submission #156046

# Submission time Handle Problem Language Result Execution time Memory
156046 2019-10-03T02:28:02 Z souhhcong JOIOJI (JOI14_joioji) C++14
95 / 100
64 ms 7924 KB
#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 (!pref[i].cnt_I && !pref[i].cnt_J && !pref[i].cnt_O)
            ans = max(ans,i+1);
        else 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
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 420 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 508 KB Output is correct
9 Correct 3 ms 508 KB Output is correct
10 Correct 3 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 11 ms 1272 KB Output is correct
3 Correct 17 ms 2040 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 48 ms 5112 KB Output is correct
6 Correct 62 ms 5892 KB Output is correct
7 Correct 64 ms 6280 KB Output is correct
8 Correct 62 ms 5640 KB Output is correct
9 Correct 63 ms 6028 KB Output is correct
10 Correct 61 ms 5736 KB Output is correct
11 Correct 48 ms 7176 KB Output is correct
12 Correct 45 ms 4360 KB Output is correct
13 Correct 37 ms 3772 KB Output is correct
14 Correct 48 ms 7924 KB Output is correct
15 Correct 37 ms 3464 KB Output is correct