# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221936 | mhy908 | 스탬프 수집 (JOI16_ho_t2) | C++14 | 9 ms | 3712 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;
int n;
char str[100010];
LL J[100010], JO[100010], OI[100010], I[100010], ans, ans2;
int main(){
scanf("%d %s", &n, str+1);
for(int i=1; i<=n; i++){
J[i]=J[i-1], JO[i]=JO[i-1];
if(str[i]=='J')J[i]++;
if(str[i]=='O')JO[i]+=J[i];
if(str[i]=='I')ans+=JO[i];
}
for(int i=n; i>=1; i--){
I[i]=I[i+1], OI[i]=OI[i+1];
if(str[i]=='I')I[i]++;
if(str[i]=='O')OI[i]+=I[i];
}
for(int i=1; i<=n+1; i++){
LL tmp=max(max(OI[i], JO[i-1]), J[i-1]*I[i]);
ans2=max(ans2, tmp);
}
printf("%lld", ans+ans2);
}
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... |