52432023-04-23 17:32:55szilNemzetközi Rántott Hús Fesztiválcpp14Time limit exceeded 27/100586ms30748 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);
	for (int i = 1; i <= n; i++) cin >> v[i];
	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";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Time limit exceeded555ms1280 KiB
subtask27/7
3Accepted3ms2144 KiB
4Accepted3ms2344 KiB
subtask39/9
5Accepted25ms2436 KiB
6Accepted20ms2720 KiB
7Accepted37ms3052 KiB
subtask40/14
8Time limit exceeded564ms4728 KiB
9Time limit exceeded574ms5404 KiB
10Time limit exceeded574ms6452 KiB
11Time limit exceeded577ms7372 KiB
12Time limit exceeded578ms8532 KiB
13Time limit exceeded569ms9812 KiB
14Time limit exceeded564ms10684 KiB
15Time limit exceeded586ms12020 KiB
subtask511/11
16Accepted14ms11980 KiB
17Accepted28ms12000 KiB
18Accepted25ms11956 KiB
subtask60/29
19Time limit exceeded550ms11920 KiB
20Time limit exceeded551ms12204 KiB
21Time limit exceeded555ms11340 KiB
22Time limit exceeded564ms12328 KiB
subtask70/30
23Time limit exceeded541ms13532 KiB
24Time limit exceeded572ms14536 KiB
25Time limit exceeded578ms15432 KiB
26Time limit exceeded573ms16440 KiB
27Time limit exceeded563ms17412 KiB
28Time limit exceeded577ms18408 KiB
29Time limit exceeded572ms19676 KiB
30Time limit exceeded578ms20796 KiB
31Time limit exceeded575ms21796 KiB
32Time limit exceeded573ms22696 KiB
33Time limit exceeded556ms23652 KiB
34Time limit exceeded574ms24696 KiB
35Time limit exceeded566ms25948 KiB
36Time limit exceeded555ms26684 KiB
37Time limit exceeded568ms27700 KiB
38Time limit exceeded570ms28704 KiB
39Time limit exceeded573ms29704 KiB
40Time limit exceeded559ms30748 KiB