Submission #545451

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
5454512022-04-04 14:34:19pokmui9909스탬프 수집 (JOI16_ho_t2)C++17
100 / 100
5 ms3768 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N; string S;
ll J[100005], JO[100005], I[100005], OI[100005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> S;
S = " " + S;
ll A = 0, B = 0;
for(int i = 1; i <= N; i++){
J[i] = J[i - 1], JO[i] = JO[i - 1];
if(S[i] == 'J') J[i]++;
if(S[i] == 'O') JO[i] += J[i];
if(S[i] == 'I') A += JO[i];
}
for(int i = N; i >= 1; i--){
I[i] = I[i + 1], OI[i] = OI[i + 1];
if(S[i] == 'I') I[i]++;
if(S[i] == 'O') OI[i] += I[i];
}
for(int i = 1; i <= N + 1; i++){
B = max({B, OI[i], J[i - 1] * I[i], JO[i - 1]});
}
cout << A + B;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...