Submission #400667

# Submission time Handle Problem Language Result Execution time Memory
400667 2021-05-08T13:25:48 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;
}

template<const int A>
struct Trie {
	int id;
	vector<array<int, A>> T;
	Trie() {
		id = 2;
		T.assign(64 * 2003, {});
	}
	void inserT(const long long& x) {
		int cr = 0;
		for (int i = 61; i >= 0; i--) {
			int B = !!((1 << i) & x);
			if (!T[cr][B]) {
				T[cr][B] = id++;
			}
			cr = T[cr][B];
		}
	}
	long long querT(const long long& x) {
		int cr = 0;
		long long ans = 0;
		for (int i = 61; i >= 0; i--) {
			int B = !!((1 << i) & x);
			if (T[cr][B]) {
				cr = T[cr][B];
			} else {
				cr = T[cr][B];
				ans |= (1 << i);
			}
		}
		return ans;
	}
};

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);
		}
		vector<Trie<2>> t(b);
		vector<vector<long long>> DP(n, vector<long long>(b, inf));
		DP[0][0] = y[0];
		t[0].inserT(DP[0][0]);
		for (int i = 0; i < b; i++) {
			t[i].inserT(inf);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < min(b, i + 1); j++) {
				DP[i][j] = t[j - 1].querT(y[i]);
			}
			for (int j = 0; j < min(b, i + 1); j++) {
				t[j].inserT(DP[i][j]);
			}
		}
		res = min(res, *min_element(DP[n - 1].begin(), DP[n - 1].end()));
		cout << min(res, sol2(0, 1)) << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8784 KB Output is correct
2 Correct 5 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 8804 KB Output is correct
6 Correct 5 ms 8780 KB Output is correct
7 Correct 4 ms 8780 KB Output is correct
8 Correct 4 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 4 ms 8780 KB Output is correct
13 Correct 12 ms 8880 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 4 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 4 ms 8780 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 6 ms 8780 KB Output is correct
21 Correct 6 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 8860 KB Output is correct
25 Correct 5 ms 8876 KB Output is correct
26 Correct 12 ms 8780 KB Output is correct
27 Correct 4 ms 8780 KB Output is correct
28 Correct 4 ms 8872 KB Output is correct
29 Correct 4 ms 8780 KB Output is correct
30 Correct 5 ms 8844 KB Output is correct
31 Correct 5 ms 8780 KB Output is correct
32 Correct 4 ms 8780 KB Output is correct
33 Correct 11 ms 8872 KB Output is correct
34 Correct 12 ms 8880 KB Output is correct
35 Correct 5 ms 8780 KB Output is correct
36 Correct 12 ms 8780 KB Output is correct
# Verdict Execution time Memory 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 8852 KB Output is correct
5 Correct 5 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 4 ms 8780 KB Output is correct
9 Correct 5 ms 8780 KB Output is correct
10 Correct 4 ms 8824 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 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 4 ms 8780 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 6 ms 8780 KB Output is correct
23 Correct 5 ms 8780 KB Output is correct
24 Correct 4 ms 8780 KB Output is correct
25 Correct 5 ms 8780 KB Output is correct
26 Correct 11 ms 8880 KB Output is correct
27 Correct 5 ms 8780 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 5 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 8808 KB Output is correct
36 Correct 4 ms 8780 KB Output is correct
# Verdict Execution time Memory 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 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 4 ms 8780 KB Output is correct
8 Correct 4 ms 8784 KB Output is correct
9 Correct 5 ms 8784 KB Output is correct
10 Correct 4 ms 8780 KB Output is correct
11 Correct 5 ms 8800 KB Output is correct
12 Correct 5 ms 8784 KB Output is correct
13 Correct 11 ms 8780 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 4 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 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 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 5 ms 8780 KB Output is correct
27 Correct 6 ms 8852 KB Output is correct
28 Correct 7 ms 8780 KB Output is correct
29 Correct 8 ms 8856 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 8780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8784 KB Output is correct
2 Correct 5 ms 8908 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 4 ms 8780 KB Output is correct
5 Correct 5 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 8876 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 4 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 8804 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 5 ms 8800 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 4 ms 8780 KB Output is correct
25 Correct 5 ms 8780 KB Output is correct
26 Correct 11 ms 8780 KB Output is correct
27 Correct 5 ms 8796 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 5 ms 8800 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 11 ms 8780 KB Output is correct
34 Correct 11 ms 8780 KB Output is correct
35 Correct 4 ms 8780 KB Output is correct
36 Correct 12 ms 8780 KB Output is correct
37 Correct 5 ms 8780 KB Output is correct
38 Correct 5 ms 8780 KB Output is correct
39 Correct 5 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 4 ms 8780 KB Output is correct
44 Correct 5 ms 8780 KB Output is correct
45 Correct 5 ms 8780 KB Output is correct
46 Correct 5 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 5 ms 8780 KB Output is correct
50 Correct 6 ms 8780 KB Output is correct
51 Correct 7 ms 8876 KB Output is correct
52 Correct 7 ms 8780 KB Output is correct
53 Correct 4 ms 8780 KB Output is correct
54 Correct 7 ms 8780 KB Output is correct
55 Correct 7 ms 8780 KB Output is correct
56 Incorrect 5 ms 8780 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8788 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 6 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 4 ms 8780 KB Output is correct
9 Correct 5 ms 8864 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 11 ms 8780 KB Output is correct
14 Correct 4 ms 8780 KB Output is correct
15 Correct 4 ms 8780 KB Output is correct
16 Correct 5 ms 8780 KB Output is correct
17 Correct 5 ms 8864 KB Output is correct
18 Correct 5 ms 8892 KB Output is correct
19 Correct 5 ms 8780 KB Output is correct
20 Correct 11 ms 8880 KB Output is correct
21 Correct 12 ms 8852 KB Output is correct
22 Correct 4 ms 8780 KB Output is correct
23 Correct 11 ms 8780 KB Output is correct
24 Correct 4 ms 8848 KB Output is correct
25 Correct 5 ms 8808 KB Output is correct
26 Correct 5 ms 8780 KB Output is correct
27 Correct 4 ms 8820 KB Output is correct
28 Correct 5 ms 8780 KB Output is correct
29 Correct 5 ms 8780 KB Output is correct
30 Correct 5 ms 8780 KB Output is correct
31 Correct 5 ms 8784 KB Output is correct
32 Correct 5 ms 8780 KB Output is correct
33 Correct 4 ms 8756 KB Output is correct
34 Correct 5 ms 8780 KB Output is correct
35 Correct 5 ms 8772 KB Output is correct
36 Correct 5 ms 8780 KB Output is correct
37 Correct 6 ms 8780 KB Output is correct
38 Correct 7 ms 8780 KB Output is correct
39 Correct 7 ms 8780 KB Output is correct
40 Correct 5 ms 8780 KB Output is correct
41 Correct 7 ms 8780 KB Output is correct
42 Correct 7 ms 8780 KB Output is correct
43 Incorrect 5 ms 8780 KB Output isn't correct
44 Halted 0 ms 0 KB -