QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133469#4931. Comic BingeBoulevardDust#WA 2ms12388kbC++171.6kb2023-08-02 09:47:422023-08-02 09:47:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 09:47:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12388kb
  • [2023-08-02 09:47:42]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <utility>

using namespace std;

int n, a[1055], b[1055], v[1055][5055], s[1055];
pair<int, int> dp[1055][5055];

pair<int, int> Get(pair<int, int> p, int t, int r) {
	int x = p.first, y = p.second;
	// printf("%d %d %d %d\n", x, y, t, r);
	if(y + t <= a[x]) {
		return make_pair(x, y + t);
	}
	t -= a[x] - y;
	int i = x + 1;
	while(i <= r) {
		if(i == r) return make_pair(r - 1, a[r - 1]);
		if(a[i] < t) {
			t -= a[i];
		}
		else {
			return make_pair(i, t);
		}
		++i;
	}
	return make_pair(r - 1, a[r - 1]);
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	int m = 0;
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &b[i]);
		m = max(m, b[i]);
	}
	s[n + 1] = 0;
	for(int i = n; i >= 1; --i) {
		s[i] = s[i - 1] + a[i];
	}
	m = m * n / 2 + m * 5;
	// printf("%d\n", m);
	v[1][b[1]] = 1;
	dp[1][b[1]] = make_pair(0, 0);
	for(int i = 2; i <= n; ++i) {
		for(int j = b[i]; j <= m; ++j) {
			if(v[i - 1][j - b[i]]) {
				dp[i][j] = Get(dp[i - 1][j - b[i]], b[i], i);
				v[i][j] = 1;
			}
			if(i > 1 && v[i - 2][j - b[i]]) {
				dp[i][j] = max(dp[i][j], Get(dp[i - 2][j - b[i]], b[i], i));
				v[i][j] = 1;
			}
			// printf("%d %d %d %d\n", i, j, dp[i][j].first, dp[i][j].second);
		}
	}
	int ans = 1e9;
	for(int i = 0; i <= m; ++i) {
		if(v[n][i]) {
			// printf("%d %d %d\n", i, dp[n][i].first, dp[n][i].second);
			ans = min(ans, i + s[dp[n][i].first + 1] + a[dp[n][i].first] - dp[n][i].second);
		}
	}
	printf("%d", ans);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5740kb

input:

6
3 1 1 1 1 2
1 5 3 3 7 4

output:

13

result:

ok single line: '13'

Test #2:

score: 0
Accepted
time: 0ms
memory: 5652kb

input:

2
2 1
1 1

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5812kb

input:

1
1
1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 12388kb

input:

161
146 662 336 441 626 77 362 697 911 248 879 40 435 60 518 62 475 908 185 740 435 899 188 673 716 529 524 305 321 998 4 363 598 471 650 379 6 980 971 175 664 328 294 681 201 64 926 608 310 478 404 284 634 239 891 515 433 368 929 457 593 338 432 971 593 134 355 97 658 344 653 592 822 660 403 398 38...

output:

1153

result:

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