제출 #771403

#제출 시각아이디문제언어결과실행 시간메모리
771403gggkik스탬프 수집 (JOI16_ho_t2)C++14
100 / 100
6 ms5332 KiB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5+5;
long long J[2][MXN], O[2][MXN], I[2][MXN], n;
char A[MXN];
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 1;i<=n;i++) cin >> A[i];
    for(int i = n;i;i--){
        I[1][i] = I[1][i+1];
        O[1][i] = O[1][i+1];
        J[1][i] = J[1][i+1];
        if(A[i]=='I') I[1][i]++;
        if(A[i]=='O') O[1][i]+=I[1][i];
        if(A[i]=='J') J[1][i]+=O[1][i];
    }
    long long ans = 0;
    for(int i = 0;i<=n;i++){
        J[0][i] = J[0][i-1];
        O[0][i] = O[0][i-1];
        I[0][i] = I[0][i-1];
        if(A[i]=='J') J[0][i]++;
        if(A[i]=='O') O[0][i]+=J[0][i];
        if(A[i]=='I') I[0][i]+=O[0][i];
        ans = max(ans,J[1][1]+max({
            O[1][i+1],
            1LL*J[0][i]*I[1][i+1],
            O[0][i],
        }));
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...