General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
44617380 Practice:
dcordb
1070J - 29 GNU C++11 Accepted 78 ms 988 KB 2018-10-21 06:11:59 2018-10-21 06:11:59
→ Source
#include <bits/stdc++.h>
using namespace std;

const int MAX = 2e5 + 5;
int t, n, m, k, f[26], dp[MAX];
char a[MAX];

int main() {
	scanf("%d", &t);

	while(t--) {
		scanf("%d%d%d%s", &n, &m, &k, a + 1);

		for(int i = 0; i < 26; i++)
			f[i] = 0;

		for(int i = 1; i <= k; i++)
			f[a[i] - 'A']++;

		int ans = n * m;
		for(int p = 0; p < 26; p++) {
			for(int s = 0; s <= n; s++)
				dp[s] = 0;

			dp[0] = 1;

			for(int i = 0; i < 26; i++) {
				if(i == p)
					continue;

				for(int s = n; s >= f[i]; s--)
					dp[s] |= dp[s - f[i]];
			}

			for(int x = 0; x <= n && x <= f[p]; x++) {
				int y = min(m, max(0, f[p] - x - (k - n - m)));

				if(dp[n - x])
					ans = min(ans, x * y);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details