Submission #896398

# Submission time Handle Problem Language Result Execution time Memory
896398 2024-01-01T11:19:19 Z MongHwa None (JOI16_ho_t2) C++17
100 / 100
5 ms 3160 KB
#include <iostream>
using namespace std;

#define ll long long

ll J[100005], O[100005], I[100005];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n; string s;
	cin >> n >> s;

	ll org = 0;
	for(int i = 0; i < n; i++)
	{
		J[i+1] = J[i];
		if(s[i] == 'J')
			J[i+1]++;
	}
	for(int i = 0; i < n; i++)
	{
		O[i+1] = O[i];
		if(s[i] == 'O')
			O[i+1] += J[i+1];
	}
	for(int i = 0; i < n; i++)
	{
		I[i+1] = I[i];
		if(s[i] == 'I')
			I[i+1] += O[i+1];
	}
	org = I[n];

	ll ans = org;
	for(int i = 1; i <= n; i++)
		ans = max(ans, org + O[i]);

	fill(O, O+n+1, 0);
	fill(I, I+n+1, 0);

	for(int i = n-1; i >= 0; i--)
	{
		I[i] = I[i+1];
		if(s[i] == 'I')
			I[i]++;
	}
	for(int i = n-1; i >= 0; i--)
	{
		O[i] = O[i+1];
		if(s[i] == 'O')
			O[i] += I[i];
	}

	for(int i = 0; i < n; i++)
		ans = max(ans, org + O[i]);

	fill(J, J+n+1, 0);
	fill(I, I+n+1, 0);

	for(int i = 0; i < n; i++)
	{
		J[i+1] = J[i], I[i+1] = I[i];
		if(s[i] == 'J')
			J[i+1]++;
		else if(s[i] == 'I')
			I[i+1]++;
	}

	for(int i = 1; i < n; i++)
		ans = max(ans, org + J[i]*(I[n]-I[i]));

	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 3 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 3 ms 2908 KB Output is correct
34 Correct 3 ms 2904 KB Output is correct
35 Correct 3 ms 2908 KB Output is correct
36 Correct 5 ms 3036 KB Output is correct
37 Correct 4 ms 2904 KB Output is correct
38 Correct 4 ms 3160 KB Output is correct
39 Correct 4 ms 3124 KB Output is correct
40 Correct 4 ms 2904 KB Output is correct
41 Correct 4 ms 2908 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 3 ms 2892 KB Output is correct