This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
#define MIX(a,b,c,d) make_pair(make_pair(a,b),make_pair(c,d))
int N;
string S;
vector<pair<pair<int,int>,pair<int,int> > > wa;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(9);
cin >> N >> S;
wa.push_back(MIX(0,0,0,0));
for(int i=0; i<N; i++){
wa.push_back(wa.back());
wa.back().second.second++;
if(S[i] == 'J') wa.back().first.first++;
if(S[i] == 'O') wa.back().first.second++;
if(S[i] == 'I') wa.back().second.first++;
int m = min({wa.back().first.first,wa.back().first.second,wa.back().second.first});
wa.back().first.first -= m;
wa.back().first.second -= m;
wa.back().second.first -= m;
}
sort(wa.begin(), wa.end());
int l = 0;
int ans = 0;
for(int i=1; i<=N; i++){
if(wa[l].first == wa[i].first && wa[l].second.first == wa[i].second.first){
ans = max(ans, wa[i].second.second-wa[l].second.second);
}
else{
l = i;
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |