Submission #136943

#TimeUsernameProblemLanguageResultExecution timeMemory
136943arnold518스탬프 수집 (JOI16_ho_t2)C++14
100 / 100
6 ms2168 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N;
char S[MAXN+10];

ll pj[MAXN+10], pi[MAXN+10], ans;

int main()
{
    int i, j;

    scanf("%d%s", &N, S+1);
    for(i=1; i<=N; i++) pj[i]=pj[i-1]+(S[i]=='J');
    for(i=N; i>=1; i--) pi[i]=pi[i+1]+(S[i]=='I');

    ll now=0;
    for(i=1; i<N; i++) now=max(now, pj[i]*pi[i+1]);
    for(i=1; i<=N; i++) if(S[i]=='O') now+=pj[i]*pi[i];
    ans=max(ans, now);

    now=0;
    for(i=1; i<=N; i++) if(S[i]=='O') now+=(pj[i]+1)*pi[i];
    ans=max(ans, now);

    now=0;
    for(i=1; i<=N; i++) if(S[i]=='O') now+=pj[i]*(pi[i]+1);
    ans=max(ans, now);

    printf("%lld", ans);
}

Compilation message (stderr)

2016_ho_t2.cpp: In function 'int main()':
2016_ho_t2.cpp:17:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
2016_ho_t2.cpp:19:10: 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...