Submission #70466

#TimeUsernameProblemLanguageResultExecution timeMemory
70466Diuven스탬프 수집 (JOI16_ho_t2)C++14
100 / 100
6 ms3244 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int MX=100010, inf=2e9; int n; char S[MX]; int Jcnt[MX], Icnt[MX]; ll base; ll J(){ ll res=base; for(int i=1; i<=n; i++) if(S[i]=='O') res+=Icnt[i]; return res; } ll I(){ ll res=base; for(int i=n; i>=1; i--) if(S[i]=='O') res+=Jcnt[i]; return res; } ll O(){ ll mx=0; for(int i=1; i<=n; i++){ mx=max(mx, 1LL*Jcnt[i-1]*Icnt[i]); } return base+mx; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>(S+1); for(int i=1; i<=n; i++) Jcnt[i]=Jcnt[i-1]+(S[i]=='J'); for(int i=n; i>=1; i--) Icnt[i]=Icnt[i+1]+(S[i]=='I'); for(int i=1; i<=n; i++) if(S[i]=='O') base+=1LL*Jcnt[i]*Icnt[i]; ll ans=max({J(), I(), O()}); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...