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<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
map<pair<int, pair<int, int> >, int> mp;
int n;
string s;
int v[5];
int ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s;
mp[{0, {0, 0}}] = -1;
for(int i = 0; i < n; ++i)
{
if(s[i] == 'J')
++v[1];
if(s[i] == 'O')
++v[2];
if(s[i] == 'I')
++v[3];
int mn = min(v[1], min(v[2], v[3]));
if(mp.find({v[1] - mn, {v[2] - mn, v[3] - mn}}) != mp.end())
ans = max(ans, i - mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}]);
else
mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}] = i;
}
cout << ans;
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... |