답안 #200947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200947 2020-02-08T18:39:14 Z ZwariowanyMarcin Holding (COCI20_holding) C++14
110 / 110
290 ms 251000 KB
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define cat(x) cerr << #x << " = " << x << endl
#define ss(x) (int) x.size()

using namespace std;

const int nax = 102;

int n, L, R, k;
int a[nax];

int dp[nax][nax][10001];
int dp2[nax][nax][10001];

bool ok(int x, int y) {
	int r = 0;
	r += (L <= x && x <= R);
	r += (L <= y && y <= R);
	return (r == 1);
}

int main() {
	scanf ("%d%d%d%d", &n, &L, &R, &k);
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", a + i);
		if (L <= i && i <= R) sum += a[i];
	}
	
	for (int dl = 1; dl <= n; ++dl) {
		for (int l = 1; l + dl - 1 <= R; ++l) {
			int r = l + dl - 1;
			for (int cost = 0; cost <= k; ++cost) {
				dp[l][r][cost] = min(dp[l + 1][r][cost], dp[l][r - 1][cost]);
				if (abs(l - r) <= cost && ok(l, r)) {
					int x = 0;
					if (L <= l && l <= R) {
						x -= a[l];
						x += a[r];
					}
					else {
						x += a[l];
						x -= a[r];
					}
					dp[l][r][cost] = min(dp[l][r][cost], dp[l + 1][r - 1][cost - abs(l - r)] + x);
				}
			}
		}
	}
	
	for (int dl = 1; dl <= n; ++dl) {
		for (int l = L; l + dl - 1 <= n; ++l) {
			int r = l + dl - 1;
			for (int cost = 0; cost <= k; ++cost) {
				dp2[l][r][cost] = min(dp2[l + 1][r][cost], dp2[l][r - 1][cost]);
				if (abs(l - r) <= cost && ok(l, r)) {
					int x = 0;
					if (L <= l && l <= R) {
						x -= a[l];
						x += a[r];
					}
					else {
						x += a[l];
						x -= a[r];
					}
					dp2[l][r][cost] = min(dp2[l][r][cost], dp2[l + 1][r - 1][cost - abs(l - r)] + x);
				}
			}
		}
	}
	
	int g = 0;
	for (int i = L - 1; i <= R; ++i)
		for (int c = 0; c <= k; ++c)
			g = min(g, dp[1][i][c] + dp2[i + 1][n][k - c]);
	
	printf ("%d\n", sum + g);
	
	return 0;
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d%d%d", &n, &L, &R, &k);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:31:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", a + i);
   ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 9 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 9 ms 4600 KB Output is correct
8 Correct 8 ms 6392 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Correct 8 ms 7544 KB Output is correct
11 Correct 10 ms 9080 KB Output is correct
12 Correct 10 ms 10104 KB Output is correct
13 Correct 68 ms 64632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 9 ms 4600 KB Output is correct
8 Correct 8 ms 6392 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Correct 8 ms 7544 KB Output is correct
11 Correct 10 ms 9080 KB Output is correct
12 Correct 10 ms 10104 KB Output is correct
13 Correct 68 ms 64632 KB Output is correct
14 Correct 6 ms 3448 KB Output is correct
15 Correct 7 ms 5624 KB Output is correct
16 Correct 7 ms 4216 KB Output is correct
17 Correct 7 ms 4600 KB Output is correct
18 Correct 9 ms 6264 KB Output is correct
19 Correct 67 ms 64632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 9 ms 4600 KB Output is correct
8 Correct 8 ms 6392 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Correct 8 ms 7544 KB Output is correct
11 Correct 10 ms 9080 KB Output is correct
12 Correct 10 ms 10104 KB Output is correct
13 Correct 68 ms 64632 KB Output is correct
14 Correct 6 ms 3448 KB Output is correct
15 Correct 7 ms 5624 KB Output is correct
16 Correct 7 ms 4216 KB Output is correct
17 Correct 7 ms 4600 KB Output is correct
18 Correct 9 ms 6264 KB Output is correct
19 Correct 67 ms 64632 KB Output is correct
20 Correct 20 ms 25208 KB Output is correct
21 Correct 17 ms 19064 KB Output is correct
22 Correct 15 ms 19576 KB Output is correct
23 Correct 79 ms 89660 KB Output is correct
24 Correct 29 ms 38904 KB Output is correct
25 Correct 290 ms 251000 KB Output is correct