답안 #400657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400657 2021-05-08T13:01:02 Z BERNARB01 Bali Sculptures (APIO15_sculpture) C++17
46 / 100
12 ms 8908 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = (int) 103;
const long long inf = (long long) 4e18;
 
int n, a, b, y[N];
long long dp[N][N][N];
long long Dp[2003][2003];

long long sol0(int i, long long run, int stage, long long sum = 0) {
	if (i == n) {
		if (a <= stage && stage <= b) {
			return run | sum;
		}
		return inf;
	}
	long long ret; //dp[i][stage][run];
	//if (ret != -1) {
		//return ret;
	//}
	sum += y[i];
	ret = sol0(i + 1, run, stage, sum);
	if (stage + 1 <= b && i + 1 < n) {
		ret = min(ret, sol0(i + 1, run | sum, stage + 1));
	}
	return ret;
}

long long sol(int i, int j, int stage, long long sum = 0) {
	if (i == n) {
		if (a <= stage && stage <= b) {
			return sum;
		}
		return inf;
	}
	long long& ret = dp[i][j][stage];
	if (ret != -1) {
		return ret;
	}
	sum += y[i];
	ret = sol(i + 1, j, stage, sum);
	if (stage + 1 <= b && i + 1 < n) {
		ret = min(ret, sum | sol(i + 1, i + 1, stage + 1));
	}
	return ret;
}
 
long long sol2(int i, int stage, int j = 0, long long sum = 0) {
	if (i == n) {
		return (a <= stage && stage <= b ? sum : inf);
	}
	long long& ret = Dp[i][j];
	if (ret != -1) {
		return ret;
	}
	sum += y[i];
	ret = sol2(i + 1, stage, j, sum);
	if (i + 1 < n && stage + 1 <= b) {
		ret = min(ret, sum | sol2(i + 1, stage + 1, i + 1));
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	memset(dp, -1, sizeof dp);
	if (n <= 20) {
		cout << sol0(0, 0, 1) << '\n';
	} else if (n <= 100) {
		cout << sol(0, 0, 1) << '\n';
	} else {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += y[i];
		}
		long long res = sum;
		long long summ = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum -= y[i];
			summ += y[i];
			res = min(res, sum | summ);
		}
		cout << min(res, sol2(0, 1)) << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8780 KB Output is correct
2 Correct 4 ms 8780 KB Output is correct
3 Correct 5 ms 8780 KB Output is correct
4 Correct 4 ms 8780 KB Output is correct
5 Correct 4 ms 8780 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 5 ms 8780 KB Output is correct
8 Correct 5 ms 8780 KB Output is correct
9 Correct 5 ms 8780 KB Output is correct
10 Correct 4 ms 8780 KB Output is correct
11 Correct 4 ms 8780 KB Output is correct
12 Correct 4 ms 8780 KB Output is correct
13 Correct 11 ms 8876 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 5 ms 8780 KB Output is correct
16 Correct 5 ms 8804 KB Output is correct
17 Correct 5 ms 8780 KB Output is correct
18 Correct 5 ms 8852 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 5 ms 8812 KB Output is correct
21 Correct 5 ms 8780 KB Output is correct
22 Correct 5 ms 8868 KB Output is correct
23 Correct 5 ms 8780 KB Output is correct
24 Correct 4 ms 8780 KB Output is correct
25 Correct 6 ms 8824 KB Output is correct
26 Correct 11 ms 8872 KB Output is correct
27 Correct 5 ms 8780 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 4 ms 8780 KB Output is correct
30 Correct 5 ms 8780 KB Output is correct
31 Correct 5 ms 8764 KB Output is correct
32 Correct 4 ms 8780 KB Output is correct
33 Correct 12 ms 8876 KB Output is correct
34 Correct 12 ms 8876 KB Output is correct
35 Correct 5 ms 8780 KB Output is correct
36 Correct 11 ms 8780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8780 KB Output is correct
2 Correct 5 ms 8904 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 5 ms 8780 KB Output is correct
5 Correct 4 ms 8780 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 5 ms 8780 KB Output is correct
8 Correct 5 ms 8780 KB Output is correct
9 Correct 5 ms 8784 KB Output is correct
10 Correct 5 ms 8780 KB Output is correct
11 Correct 5 ms 8904 KB Output is correct
12 Correct 4 ms 8784 KB Output is correct
13 Correct 11 ms 8784 KB Output is correct
14 Correct 5 ms 8780 KB Output is correct
15 Correct 4 ms 8780 KB Output is correct
16 Correct 5 ms 8836 KB Output is correct
17 Correct 5 ms 8780 KB Output is correct
18 Correct 5 ms 8780 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 5 ms 8780 KB Output is correct
21 Correct 5 ms 8780 KB Output is correct
22 Correct 6 ms 8828 KB Output is correct
23 Correct 5 ms 8780 KB Output is correct
24 Correct 5 ms 8780 KB Output is correct
25 Correct 6 ms 8780 KB Output is correct
26 Correct 12 ms 8908 KB Output is correct
27 Correct 5 ms 8780 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 4 ms 8780 KB Output is correct
30 Correct 5 ms 8780 KB Output is correct
31 Correct 5 ms 8780 KB Output is correct
32 Correct 5 ms 8780 KB Output is correct
33 Correct 4 ms 8780 KB Output is correct
34 Correct 5 ms 8780 KB Output is correct
35 Correct 5 ms 8780 KB Output is correct
36 Correct 5 ms 8780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8780 KB Output is correct
2 Correct 4 ms 8780 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 5 ms 8780 KB Output is correct
5 Correct 4 ms 8780 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 5 ms 8780 KB Output is correct
8 Correct 5 ms 8780 KB Output is correct
9 Correct 5 ms 8780 KB Output is correct
10 Correct 5 ms 8780 KB Output is correct
11 Correct 4 ms 8780 KB Output is correct
12 Correct 4 ms 8780 KB Output is correct
13 Correct 12 ms 8780 KB Output is correct
14 Correct 5 ms 8780 KB Output is correct
15 Correct 5 ms 8780 KB Output is correct
16 Correct 5 ms 8780 KB Output is correct
17 Correct 5 ms 8780 KB Output is correct
18 Correct 5 ms 8780 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 4 ms 8784 KB Output is correct
21 Correct 5 ms 8780 KB Output is correct
22 Correct 4 ms 8780 KB Output is correct
23 Correct 4 ms 8780 KB Output is correct
24 Correct 5 ms 8780 KB Output is correct
25 Correct 5 ms 8780 KB Output is correct
26 Correct 7 ms 8780 KB Output is correct
27 Correct 6 ms 8780 KB Output is correct
28 Correct 7 ms 8780 KB Output is correct
29 Correct 7 ms 8780 KB Output is correct
30 Correct 5 ms 8780 KB Output is correct
31 Correct 6 ms 8780 KB Output is correct
32 Correct 7 ms 8824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8780 KB Output is correct
2 Correct 4 ms 8780 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 4 ms 8780 KB Output is correct
5 Correct 4 ms 8780 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 4 ms 8780 KB Output is correct
8 Correct 5 ms 8780 KB Output is correct
9 Correct 5 ms 8780 KB Output is correct
10 Correct 5 ms 8832 KB Output is correct
11 Correct 5 ms 8780 KB Output is correct
12 Correct 4 ms 8780 KB Output is correct
13 Correct 11 ms 8880 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 5 ms 8780 KB Output is correct
16 Correct 4 ms 8780 KB Output is correct
17 Correct 5 ms 8780 KB Output is correct
18 Correct 5 ms 8868 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 4 ms 8780 KB Output is correct
21 Correct 5 ms 8780 KB Output is correct
22 Correct 5 ms 8780 KB Output is correct
23 Correct 5 ms 8780 KB Output is correct
24 Correct 5 ms 8780 KB Output is correct
25 Correct 5 ms 8780 KB Output is correct
26 Correct 11 ms 8872 KB Output is correct
27 Correct 4 ms 8780 KB Output is correct
28 Correct 4 ms 8780 KB Output is correct
29 Correct 4 ms 8780 KB Output is correct
30 Correct 4 ms 8780 KB Output is correct
31 Correct 5 ms 8780 KB Output is correct
32 Correct 5 ms 8780 KB Output is correct
33 Correct 12 ms 8780 KB Output is correct
34 Correct 12 ms 8880 KB Output is correct
35 Correct 4 ms 8780 KB Output is correct
36 Correct 11 ms 8780 KB Output is correct
37 Correct 4 ms 8780 KB Output is correct
38 Correct 5 ms 8872 KB Output is correct
39 Correct 4 ms 8780 KB Output is correct
40 Correct 5 ms 8780 KB Output is correct
41 Correct 5 ms 8780 KB Output is correct
42 Correct 5 ms 8780 KB Output is correct
43 Correct 5 ms 8780 KB Output is correct
44 Correct 5 ms 8780 KB Output is correct
45 Correct 5 ms 8904 KB Output is correct
46 Correct 4 ms 8780 KB Output is correct
47 Correct 5 ms 8780 KB Output is correct
48 Correct 5 ms 8780 KB Output is correct
49 Correct 7 ms 8780 KB Output is correct
50 Correct 6 ms 8780 KB Output is correct
51 Correct 7 ms 8780 KB Output is correct
52 Correct 7 ms 8780 KB Output is correct
53 Correct 5 ms 8780 KB Output is correct
54 Correct 6 ms 8780 KB Output is correct
55 Correct 7 ms 8780 KB Output is correct
56 Incorrect 5 ms 8800 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8780 KB Output is correct
2 Correct 5 ms 8780 KB Output is correct
3 Correct 5 ms 8780 KB Output is correct
4 Correct 4 ms 8780 KB Output is correct
5 Correct 4 ms 8780 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 5 ms 8780 KB Output is correct
8 Correct 5 ms 8780 KB Output is correct
9 Correct 4 ms 8780 KB Output is correct
10 Correct 4 ms 8780 KB Output is correct
11 Correct 4 ms 8780 KB Output is correct
12 Correct 5 ms 8780 KB Output is correct
13 Correct 12 ms 8780 KB Output is correct
14 Correct 5 ms 8780 KB Output is correct
15 Correct 5 ms 8780 KB Output is correct
16 Correct 5 ms 8760 KB Output is correct
17 Correct 5 ms 8784 KB Output is correct
18 Correct 6 ms 8780 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 12 ms 8880 KB Output is correct
21 Correct 12 ms 8876 KB Output is correct
22 Correct 5 ms 8780 KB Output is correct
23 Correct 12 ms 8876 KB Output is correct
24 Correct 5 ms 8780 KB Output is correct
25 Correct 4 ms 8780 KB Output is correct
26 Correct 5 ms 8780 KB Output is correct
27 Correct 4 ms 8780 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 5 ms 8864 KB Output is correct
30 Correct 5 ms 8780 KB Output is correct
31 Correct 5 ms 8780 KB Output is correct
32 Correct 5 ms 8780 KB Output is correct
33 Correct 5 ms 8780 KB Output is correct
34 Correct 5 ms 8780 KB Output is correct
35 Correct 5 ms 8780 KB Output is correct
36 Correct 5 ms 8780 KB Output is correct
37 Correct 8 ms 8880 KB Output is correct
38 Correct 7 ms 8832 KB Output is correct
39 Correct 9 ms 8764 KB Output is correct
40 Correct 5 ms 8768 KB Output is correct
41 Correct 7 ms 8780 KB Output is correct
42 Correct 9 ms 8780 KB Output is correct
43 Incorrect 5 ms 8780 KB Output isn't correct
44 Halted 0 ms 0 KB -