Submission #533232

# Submission time Handle Problem Language Result Execution time Memory
533232 2022-03-05T07:13:01 Z rk42745417 None (JOI16_ho_t2) C++17
100 / 100
4 ms 1360 KB
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const ll LINF = ll(4e18) + ll(2e15);
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
static int LamyIsCute = []() {
	EmiliaMyWife
	return 48763;
}();

signed main() {
	int n;
	string s;
	cin >> n >> s;
	ll res = 0;
	vector<int> pre_cnt(n), suf_cnt(n);
	for(int i = 0; i < n; i++) {
		pre_cnt[i] = (s[i] == 'J');
		if(i)
			pre_cnt[i] += pre_cnt[i - 1];
	}
	for(int i = n - 1; ~i; i-- ){
		suf_cnt[i] = s[i] == 'I';
		if(i + 1 < n)
			suf_cnt[i] += suf_cnt[i + 1];
	}
	for(int i = 0; i < n; i++)
		if(s[i] == 'O')
			res += 1LL * pre_cnt[i] * suf_cnt[i];
	ll ans = res;
	for(int i = 0; i + 1 < n; i++)
		ans = max(ans, res + ll(pre_cnt[i]) * suf_cnt[i + 1]);

	ll cur = 0;
	for(int i = 0; i < n; i++)
		if(s[i] == 'O')
			cur += pre_cnt[i];
	ans = max(ans, res + cur);
	cur = 0;
	for(int i = n - 1; ~i; i--)
		if(s[i] == 'O')
			cur += suf_cnt[i];
	ans = max(ans, res + cur);

	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 272 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 272 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 1360 KB Output is correct
32 Correct 2 ms 1348 KB Output is correct
33 Correct 2 ms 1360 KB Output is correct
34 Correct 2 ms 1360 KB Output is correct
35 Correct 2 ms 1352 KB Output is correct
36 Correct 3 ms 1360 KB Output is correct
37 Correct 3 ms 1360 KB Output is correct
38 Correct 3 ms 1360 KB Output is correct
39 Correct 3 ms 1360 KB Output is correct
40 Correct 3 ms 1360 KB Output is correct
41 Correct 3 ms 1360 KB Output is correct
42 Correct 3 ms 1360 KB Output is correct
43 Correct 4 ms 1360 KB Output is correct
44 Correct 3 ms 1348 KB Output is correct
45 Correct 2 ms 1344 KB Output is correct