답안 #909988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909988 2024-01-17T17:32:54 Z AlphaMale06 스탬프 수집 (JOI16_ho_t2) C++14
100 / 100
5 ms 3932 KB
#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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 432 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 432 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 3676 KB Output is correct
32 Correct 3 ms 3668 KB Output is correct
33 Correct 2 ms 3676 KB Output is correct
34 Correct 2 ms 3676 KB Output is correct
35 Correct 2 ms 3656 KB Output is correct
36 Correct 4 ms 3932 KB Output is correct
37 Correct 3 ms 3932 KB Output is correct
38 Correct 3 ms 3676 KB Output is correct
39 Correct 3 ms 3684 KB Output is correct
40 Correct 3 ms 3676 KB Output is correct
41 Correct 3 ms 3676 KB Output is correct
42 Correct 3 ms 3680 KB Output is correct
43 Correct 3 ms 3676 KB Output is correct
44 Correct 5 ms 3872 KB Output is correct
45 Correct 2 ms 3676 KB Output is correct