답안 #334036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334036 2020-12-08T07:17:10 Z ronnith Holding (COCI20_holding) C++14
88 / 110
289 ms 262148 KB
#include <bits/stdc++.h>

typedef long long ll;
#define v vector
#define vl vector<ll>
#define mk make_pair
#define f first
#define s second

using namespace std;

int main(){
	ll n, l, r, K;
	scanf("%lld%lld%lld%lld", &n, &l, &r, &K);
	ll a[n];
	for(int i = 0;i < n;i ++){
		scanf("%lld", &a[i]);
	}
	// int ans = INT_MAX;
	// for(int bit = 0;bit < (1<<n);bit ++){
	// 	if(__builtin_popcount(bit) == n - l + 1){
	// 		int sm = 0;
	// 		int cost = 0;
	// 		int h = l;
	// 		for(int i = 0;i < n;i ++){
	// 			if(!((1<<i)&bit))continue;
	// 			cost += h - (i + 1);
	// 			h ++;
	// 			sm += a[i];
	// 		}
	// 		if(cost <= k){
	// 			ans = min(ans, sm);
	// 		}
	// 	}
	// }
	// printf("%d\n", ans);
	ll ans = INT_MAX;
	v<v<vl>> dp1(n, v<vl>(r - l + 2, vl(K + 1, INT_MAX)));
	v<v<vl>> dp2(n, v<vl>(r - l + 2, vl(K + 1, INT_MAX)));
	for(int i = 0;i < n;i ++){
		for(int j = 0;j < r - l + 2;j ++){
			for(int k = 0;k <= K;k ++){
				if(j == 0){
					dp2[i][j][k] = 0;
				} else if(i == 0){
					if(j == 1){
						if(abs(l - i - 1) == k)
							dp1[i][j][k] = a[i];
					} else {
						dp1[i][j][k] = INT_MAX;
					}
				} else {
					if(abs(j - 1 + l - i - 1) <= k){
						dp1[i][j][k] = a[i] + min(dp1[i - 1][j - 1][k - abs(j - 1 + l - i - 1)], dp2[i - 1][j - 1][k - abs(j - 1 + l - i - 1)]);// abs(j - 1 + l - i)
					}
					dp2[i][j][k] = min(dp1[i - 1][j][k], dp2[i - 1][j][k]);
				}
				if(i == n - 1 and j == r - l + 1)
					ans = min(ans, min(dp1[i][j][k], dp2[i][j][k]));
				// cerr << dp1[i][j][k] << ' ' << dp2[i][j][k] << ' ';
			}
			// cerr << '\n';
		}
		// cerr << '\n';
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%lld%lld%lld%lld", &n, &l, &r, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%lld", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 20 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 20 ms 16108 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1516 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 7 ms 5100 KB Output is correct
12 Correct 6 ms 3564 KB Output is correct
13 Correct 289 ms 213996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 20 ms 16108 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1516 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 7 ms 5100 KB Output is correct
12 Correct 6 ms 3564 KB Output is correct
13 Correct 289 ms 213996 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 5 ms 3180 KB Output is correct
19 Correct 280 ms 213996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 20 ms 16108 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1516 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 7 ms 5100 KB Output is correct
12 Correct 6 ms 3564 KB Output is correct
13 Correct 289 ms 213996 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 5 ms 3180 KB Output is correct
19 Correct 280 ms 213996 KB Output is correct
20 Correct 14 ms 8688 KB Output is correct
21 Correct 7 ms 5484 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 24 ms 18028 KB Output is correct
24 Correct 51 ms 33132 KB Output is correct
25 Runtime error 153 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)