QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#889425#5131. Grinding Gravel0000pncWA 1ms3840kbC++14801b2025-02-08 16:04:552025-02-08 16:05:03

Judging History

This is the latest submission verdict.

  • [2025-02-08 16:05:03]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-08 16:04:55]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int n, k, al = 1, cnt[15], ans, a[105], sm, cf[15], dp[100005][10];

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sm += a[i], cnt[a[i] % k]++;
	}
	for (int i = 1, j = k - 1; i < j; i++, j--) {
		int tmp = min(cnt[i], cnt[j]);
		ans += tmp, cnt[i] -= tmp, cnt[j] -= tmp;
	}
	if (k % 2 == 0) ans += cnt[k / 2] / 2, cnt[k / 2] &= 1;
	for (int i = 1; i < k; i++) cf[i] = al, al *= cnt[i] + 1;
	for (int i = 1; i < al; i++) {
		for (int j = 1; j < k; j++) {
			if (cnt[j] && i / cf[j] % (cnt[j] + 1)) {
				for (int o = 0; o < k; o++) {
					dp[i][o] = max(dp[i][o], dp[i - cf[j]][(j + o) % k] + (!o));
				}
			}
		}
	}
	printf("%d\n", sm / k - (ans + dp[al - 1][0]));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3840kb

input:

5 8
2 4 5 6 7

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

2 5
12 13

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

1 1
1

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'