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;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
int N;
char S[MAXN+10];
struct tup
{
int a, b, c;
bool operator < (const tup &p) const
{
if(a!=p.a) return a<p.a;
if(b!=p.b) return b<p.b;
return c<p.c;
}
};
map<tup, int> M;
int ans;
int main()
{
int i, j;
scanf("%d%s", &N, S+1);
int J=0, O=0, I=0;
M[{0, 0, 0}]=0;
for(i=1; i<=N; i++)
{
if(S[i]=='J') J++;
else if(S[i]=='O') O++;
else I++;
int p, q, r;
p=J-min({J, O, I});
q=O-min({J, O, I});
r=I-min({J, O, I});
if(M.find({p, q, r})!=M.end()) ans=max(ans, i-M[{p, q, r}]);
else M[{p, q, r}]=i;
}
printf("%d", ans);
}
Compilation message (stderr)
joioji.cpp: In function 'int main()':
joioji.cpp:28:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
joioji.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%s", &N, S+1);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |