QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660619#5303. No Bug No GameLJY_ljyRE 1ms9916kbC++112.4kb2024-10-20 12:24:072024-10-20 12:24:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-20 12:24:09]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:9916kb
  • [2024-10-20 12:24:07]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const long long MAXN = 3010;
long long n, k, p[MAXN], w[MAXN][13];
long long maxw[13][MAXN], eid[13];
priority_queue<pair<long long, long long>> pq[13];
long long ans[13], maxx[13][13][MAXN], Ans;
long long maxx2[13][13][MAXN], sum[13][MAXN];

void dfs(long long N, long long K) {
	if (N == n + 1) {
		for (long long i = 1; i <= 10; i++) {
			if (K + i > k) {
				if (ans[i] > 0) {
					long long cnt = 0;
					for (long long u = 1; u <= 10; u++)
						cnt += sum[u][ans[u]];
					cnt += maxx[i][k - K][ans[i]];
					cnt += sum[i][ans[i] + 1] - sum[i][ans[i]];
					Ans = max(Ans, cnt);
				}
				long long cnt = 0;
				for (long long u = 1; u <= 10; u++)
					cnt += sum[u][ans[u]];
				cnt += maxx2[i][k - K][ans[i] + 1];
				Ans = max(Ans, cnt);
			} 
		}
		long long cnt = 0;
		for (long long u = 1; u <= 10; u++)
			cnt += sum[u][ans[u]]; 
		Ans = max(Ans, cnt);
		return;
	}
	for (long long i = eid[N]; i >= 0; i--) {
		if (K + N * i <= k) {
			ans[N] = i;
			dfs(N + 1, K + N * i);
			ans[N] = 0;
		}	
	}
}

int main() {
	scanf("%lld %lld", &n, &k);
	for (long long i = 1; i <= n; i++) {
		scanf("%lld", &p[i]);
		for (long long j = 1; j <= p[i]; j++) {
			scanf("%lld", &w[i][j]);
		}
		pq[p[i]].push(make_pair(w[i][p[i]], i));
	}
	for (long long u = 1; u <= 10; u++) {
		while (!pq[u].empty()) {
			eid[u]++;
			maxw[u][eid[u]] = pq[u].top().second;
			pq[u].pop();
		}
	}
	for (long long u = 1; u <= 10; u++) {
		for (long long i = 1; i <= eid[u]; i++)
			sum[u][i] = sum[u][i - 1] + w[maxw[u][i]][u];
	}
	for (long long u = 1; u <= 10; u++) {
		for (long long y = 1; y < u; y++) {
			maxx[u][y][0] = 0;
			for (long long i = 1; i <= eid[u]; i++)
				maxx[u][y][i] = max(maxx[u][y][i - 1], w[maxw[u][i]][y] - w[maxw[u][i]][u]);
		}
		for (long long y = 1; y < u; y++) {
			maxx2[u][eid[u] + 1][0] = 0;
			for (long long i = eid[u]; i >= 1; i--)
				maxx2[u][y][i] = max(maxx[u][y][i + 1], w[maxw[u][i]][y]);
		}
	}
//	for (long long u = 1; u <= 10; u++) {
//		cout << u << endl;
//		for (long long y = 1; y < u; y++) {
//			for (long long i = 1; i <= eid[u]; i++)
//				cout << maxx[u][y][i] << " ";
//			cout << endl;
//			for (long long i = eid[u]; i >= 1; i--)
//				cout << maxx[u][y][i] << " ";
//			cout << endl;
//		}
//	}
	dfs(1, 0);
	printf("%lld\n", Ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Runtime Error

input:

3000 3000
10 70562 30723 79371 82224 63977 3362 26909 96449 48163 66159
4 18007 33590 80674 91139
4 10304 31694 70745 50656
10 63090 17226 13187 73881 38137 15237 55750 82751 75854 39658
8 95640 66120 87735 36388 44046 92415 6952 94772
9 60565 27904 98726 87052 35768 25453 14563 34273 92501
10 66332...

output:


result: