# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173449 | ahgus89 | JOIOJI (JOI14_joioji) | C++14 | 2 ms | 504 KiB |
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>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, m, k, ans, mod=1e9+7;
int J[202020], O[202020], I[202020];
bool chk(int x)
{
for(int i=0;i+3*x<=n;i++)
if(J[i+3*x]-J[i]==x&&O[i+3*x]-O[i]==x&&I[i+3*x]-I[i]==x) return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int i, temp=0;
string s;
cin>>n>>s;
for(i=1;i<=n;i++)
{
J[i]=J[i-1];
O[i]=O[i-1];
I[i]=I[i-1];
if(s[i-1]=='J') J[i]++;
if(s[i-1]=='O') O[i]++;
if(s[i-1]=='I') I[i]++;
}
int lo=0, hi=n/3;
while(lo<hi)
{
int mid=lo+hi+1>>1;
if(chk(mid)) lo=mid;
else hi=mid-1;
}
cout<<lo*3;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |