제출 #909986

#제출 시각아이디문제언어결과실행 시간메모리
909986AlphaMale06스탬프 수집 (JOI16_ho_t2)C++14
0 / 100
1 ms608 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define int long long

const int N = 100002;

int pref[N][3];

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a[n];
	for(int i=0; i< n; i++){
		if(s[i]=='J')a[i]=0;
		else if(s[i]=='O')a[i]=1;
		else a[i]=2;
	}
	for(int i=1; i<=n; i++){
		for(int j=0; j< 3; j++){
			pref[i][j]=pref[i-1][j];
		}
		pref[i][a[i-1]]++;
	}
	int ans=0;
	int mx=0;
	for(int i=1; i<=n; i++){
		if(a[i-1]==1){
			ans+=pref[i][0]*(pref[n][2]-pref[i][2]);
			mx=max(mx, pref[i][0]*(pref[n][2]-pref[i][2]));
		}
	}
	int add1=0;
	int add2=0;
	for(int i=n; i>=1; i--){
		if(a[i-1]==1){
			add1+=pref[n][2]-pref[i][2];
		}
	}
	for(int i=1; i<=n; i++){
		if(a[i-1]==1)add2+=pref[i][0];
	}
	cout << ans+max({mx, add1, add2}) << '\n';
}


signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...