52442023-04-23 18:03:13szilNemzetközi Rántott Hús Fesztiválcpp14Time limit exceeded 41/100600ms22560 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<char> v(n+1);
	bool mind = false;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		if (v[i] == 'M') mind = true;
	}
	if (mind) {
		for (int i = 1; i <= n; i++) {
			int x = 0;
			for (int j = i; j <= n; j++) x += v[j] == 'M';
			int ans = 0;
			for (int j = 0; j <= x; j++){
				int left = j, res = 0, koret = 0;
				for(int k = i; k <= n; k++){
					if (v[k] == 'K') koret++;
					else if(v[k] == 'H') {
						if(koret == 0) break;
						res++; koret--;
					} else {
						if(left > 0){
							left--; koret++;
						} else {
							if(koret == 0) break;
							res++; koret--;
						}
					}
				}

				ans = max(ans, res);
			}
			cout << ans << " ";
		}
		cout << "\n";
	} else {
		vector<int> ans(n+2), next(n+2);
		ans[n+1] = 0;
		next[n+1] = n+1;
		for (int i = n; i >= 1; i--) {
			if (v[i] == 'H') {
				ans[i] = 0;
				next[i] = i;
				continue;
			}
			ans[i] = ans[i+1];
			if(next[i+1] == n+1){
				next[i] = n+1;
				continue;
			}
			ans[i]++;
			ans[i] += ans[next[i+1]+1];
			next[i] = next[next[i+1]+1];
		}
		for(int i = 1; i <= n; i++)cout<<ans[i]<<" ";
		cout<<endl;
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Time limit exceeded600ms1184 KiB
subtask27/7
3Accepted3ms2088 KiB
4Accepted3ms2308 KiB
subtask39/9
5Accepted3ms2712 KiB
6Accepted3ms2892 KiB
7Accepted3ms3188 KiB
subtask414/14
8Accepted118ms20676 KiB
9Accepted119ms20816 KiB
10Accepted116ms20952 KiB
11Accepted118ms21188 KiB
12Accepted109ms21128 KiB
13Accepted111ms21360 KiB
14Accepted107ms21272 KiB
15Accepted107ms21524 KiB
subtask511/11
16Accepted13ms3992 KiB
17Accepted23ms4060 KiB
18Accepted20ms4060 KiB
subtask60/29
19Time limit exceeded565ms4040 KiB
20Time limit exceeded566ms4144 KiB
21Time limit exceeded568ms4264 KiB
22Time limit exceeded549ms4496 KiB
subtask70/30
23Time limit exceeded580ms4880 KiB
24Time limit exceeded570ms4840 KiB
25Time limit exceeded563ms5012 KiB
26Time limit exceeded527ms4908 KiB
27Time limit exceeded560ms4780 KiB
28Time limit exceeded554ms5016 KiB
29Time limit exceeded547ms4900 KiB
30Time limit exceeded549ms5016 KiB
31Time limit exceeded564ms4924 KiB
32Time limit exceeded570ms4952 KiB
33Time limit exceeded537ms5060 KiB
34Time limit exceeded566ms4984 KiB
35Time limit exceeded566ms5076 KiB
36Accepted107ms22468 KiB
37Accepted111ms22560 KiB
38Accepted108ms22520 KiB
39Accepted108ms22516 KiB
40Time limit exceeded552ms5032 KiB