General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
44692084 Virtual:
I1619: Shirone, Kuroni, GreymaneSilverfang#
1070J - 29 C++14 (GCC 6-32) Accepted 218 ms 532 KB 2018-10-22 15:34:34 2018-10-22 15:34:34
→ Source
#include <algorithm>
#include <iostream>
using namespace std;
bool dp[30000] = {true};
int cnt[26];

void solve()
{
	int n, m, k; cin >> n >> m >> k;
	string s; cin >> s;
	for (int i = 0; i < 26; ++i)
		cnt[i] = 0;
	for (char c : s)
		++cnt[c - 'A'];
	int res = m * n;
	for (int i = 0; i < 26; ++i)
	{
		for (int i = 1; i < n; ++i)
			dp[i] = false;
		for (int j = 0; j < 26; ++j)
			if (i != j)
				for (int i = n - 1; i >= cnt[j]; --i)
					dp[i] |= dp[i - cnt[j]];
		for (int j = n - 1; j >= 0; --j)
			if (dp[j] && j + cnt[i] >= n)
			{
				if (j + cnt[i] > k - m)
					res = min(res, (n - j) * (m + j + cnt[i] - k));
				else 
				{
					cout << "0" << endl;
					return;
				}
			}
	}
	cout << res << endl;
}

int main()
{
	int t; cin >> t;
	for (int i = 1; i <= t; ++i)
		solve();
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details