답안 #32074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32074 2017-09-24T07:29:59 Z imeimi2000 스트랩 (JOI14_straps) C++14
100 / 100
13 ms 17816 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

using namespace std;
typedef long long llong;
typedef pair<int, int> pi;

int n;
const int inf = -2147483648;

int as[2000];
int bs[2000];
int dp[2000][2000];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	int x, a, b;
	for (int i = 0; i < n; ++i) {
		cin >> as[i] >> bs[i];
	}

	int i = 0, j = n - 1;
	while (i < j) {
		while (i < j && as[i] != 0) ++i;
		while (i < j && as[j] == 0) --j;
		if (i < j) {
			x = as[i]; as[i] = as[j]; as[j] = x;
			x = bs[i]; bs[i] = bs[j]; bs[j] = x;
		}
	}

	for (int i = 0; i < n; ++i) {
		a = as[i]; b = bs[i];
		if (i == 0) {
			for (int j = 0; j < n; ++j) dp[0][j] = inf;
			dp[0][1] = 0;
			if (a < n)
				dp[0][a] = max(dp[0][a], b);
			else
				dp[0][n - 1] = max(dp[0][n - 1], b);
		}
		else {
			dp[i][0] = dp[i - 1][0];
			for (int j = 1; j < n - i; ++j) dp[i][j] = inf;
			for (int j = 1; j <= n - i; ++j) {
				if (dp[i - 1][j] == inf) continue;
				if (j < n - i)
					dp[i][j] = max(dp[i][j], dp[i - 1][j]);
				else
					dp[i][j - 1] = max(dp[i][j - 1], dp[i - 1][j]);
				x = j + a - 1;
				if (x < n - i) {
					dp[i][x] = max(dp[i][x], dp[i - 1][j] + b);
				}
				else {
					dp[i][n - i - 1] = max(dp[i][n - i - 1], dp[i - 1][j] + b);
				}
			}
		}
	}
	printf("%d\n", dp[n - 1][0]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17816 KB Output is correct
2 Correct 0 ms 17816 KB Output is correct
3 Correct 0 ms 17816 KB Output is correct
4 Correct 0 ms 17816 KB Output is correct
5 Correct 0 ms 17816 KB Output is correct
6 Correct 0 ms 17816 KB Output is correct
7 Correct 0 ms 17816 KB Output is correct
8 Correct 0 ms 17816 KB Output is correct
9 Correct 0 ms 17816 KB Output is correct
10 Correct 0 ms 17816 KB Output is correct
11 Correct 0 ms 17816 KB Output is correct
12 Correct 0 ms 17816 KB Output is correct
13 Correct 0 ms 17816 KB Output is correct
14 Correct 0 ms 17816 KB Output is correct
15 Correct 0 ms 17816 KB Output is correct
16 Correct 0 ms 17816 KB Output is correct
17 Correct 0 ms 17816 KB Output is correct
18 Correct 0 ms 17816 KB Output is correct
19 Correct 0 ms 17816 KB Output is correct
20 Correct 0 ms 17816 KB Output is correct
21 Correct 0 ms 17816 KB Output is correct
22 Correct 0 ms 17816 KB Output is correct
23 Correct 0 ms 17816 KB Output is correct
24 Correct 0 ms 17816 KB Output is correct
25 Correct 0 ms 17816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17816 KB Output is correct
2 Correct 0 ms 17816 KB Output is correct
3 Correct 0 ms 17816 KB Output is correct
4 Correct 0 ms 17816 KB Output is correct
5 Correct 0 ms 17816 KB Output is correct
6 Correct 0 ms 17816 KB Output is correct
7 Correct 0 ms 17816 KB Output is correct
8 Correct 3 ms 17816 KB Output is correct
9 Correct 0 ms 17816 KB Output is correct
10 Correct 0 ms 17816 KB Output is correct
11 Correct 0 ms 17816 KB Output is correct
12 Correct 13 ms 17816 KB Output is correct
13 Correct 9 ms 17816 KB Output is correct
14 Correct 0 ms 17816 KB Output is correct
15 Correct 9 ms 17816 KB Output is correct
16 Correct 3 ms 17816 KB Output is correct
17 Correct 0 ms 17816 KB Output is correct
18 Correct 13 ms 17816 KB Output is correct
19 Correct 9 ms 17816 KB Output is correct
20 Correct 3 ms 17816 KB Output is correct
21 Correct 6 ms 17816 KB Output is correct
22 Correct 6 ms 17816 KB Output is correct
23 Correct 9 ms 17816 KB Output is correct
24 Correct 13 ms 17816 KB Output is correct
25 Correct 9 ms 17816 KB Output is correct
26 Correct 13 ms 17816 KB Output is correct
27 Correct 13 ms 17816 KB Output is correct
28 Correct 6 ms 17816 KB Output is correct
29 Correct 3 ms 17816 KB Output is correct
30 Correct 13 ms 17816 KB Output is correct
31 Correct 13 ms 17816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17816 KB Output is correct
2 Correct 0 ms 17816 KB Output is correct
3 Correct 0 ms 17816 KB Output is correct
4 Correct 0 ms 17816 KB Output is correct
5 Correct 0 ms 17816 KB Output is correct
6 Correct 0 ms 17816 KB Output is correct
7 Correct 0 ms 17816 KB Output is correct
8 Correct 0 ms 17816 KB Output is correct
9 Correct 3 ms 17816 KB Output is correct
10 Correct 3 ms 17816 KB Output is correct
11 Correct 0 ms 17816 KB Output is correct
12 Correct 3 ms 17816 KB Output is correct
13 Correct 3 ms 17816 KB Output is correct
14 Correct 3 ms 17816 KB Output is correct
15 Correct 0 ms 17816 KB Output is correct
16 Correct 0 ms 17816 KB Output is correct
17 Correct 13 ms 17816 KB Output is correct
18 Correct 9 ms 17816 KB Output is correct
19 Correct 9 ms 17816 KB Output is correct
20 Correct 0 ms 17816 KB Output is correct
21 Correct 6 ms 17816 KB Output is correct
22 Correct 6 ms 17816 KB Output is correct
23 Correct 6 ms 17816 KB Output is correct
24 Correct 0 ms 17816 KB Output is correct
25 Correct 0 ms 17816 KB Output is correct
26 Correct 6 ms 17816 KB Output is correct
27 Correct 3 ms 17816 KB Output is correct
28 Correct 13 ms 17816 KB Output is correct
29 Correct 6 ms 17816 KB Output is correct
30 Correct 0 ms 17816 KB Output is correct
31 Correct 9 ms 17816 KB Output is correct
32 Correct 3 ms 17816 KB Output is correct
33 Correct 6 ms 17816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 17816 KB Output is correct
2 Correct 6 ms 17816 KB Output is correct
3 Correct 0 ms 17816 KB Output is correct
4 Correct 6 ms 17816 KB Output is correct
5 Correct 13 ms 17816 KB Output is correct
6 Correct 6 ms 17816 KB Output is correct
7 Correct 6 ms 17816 KB Output is correct
8 Correct 9 ms 17816 KB Output is correct
9 Correct 6 ms 17816 KB Output is correct
10 Correct 3 ms 17816 KB Output is correct
11 Correct 3 ms 17816 KB Output is correct
12 Correct 13 ms 17816 KB Output is correct
13 Correct 13 ms 17816 KB Output is correct
14 Correct 9 ms 17816 KB Output is correct
15 Correct 6 ms 17816 KB Output is correct
16 Correct 6 ms 17816 KB Output is correct
17 Correct 13 ms 17816 KB Output is correct
18 Correct 3 ms 17816 KB Output is correct
19 Correct 13 ms 17816 KB Output is correct
20 Correct 3 ms 17816 KB Output is correct
21 Correct 0 ms 17816 KB Output is correct
22 Correct 9 ms 17816 KB Output is correct
23 Correct 6 ms 17816 KB Output is correct
24 Correct 0 ms 17816 KB Output is correct
25 Correct 9 ms 17816 KB Output is correct