Submission #46589

# Submission time Handle Problem Language Result Execution time Memory
46589 2018-04-21T15:20:49 Z Mahdi_Jfri Bali Sculptures (APIO15_sculpture) C++14
100 / 100
178 ms 868 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back

const int maxn = 2e3 + 20;
const ll inf = (1LL << 51) - 1;
const int shit = 1e2 + 20;

int a[maxn] , dp[maxn] , n , _ , b;

bool pd[shit][shit];

int f(ll m)
{
	for(int i = 1; i <= n; i++)
	{
		dp[i] = 1e9;
		ll sum = 0;

		for(int j = i - 1; j >= 0; j--)
		{
			sum += a[j + 1];

			if((sum | m) == m)
				dp[i] = min(dp[i] , dp[j] + 1);
		}
	}

	return dp[n];

}

bool f2(ll m)
{
	memset(pd , 0 , sizeof pd);
	pd[0][0] = 1;

	for(int i = 1; i <= n; i++)
	{
		for(int k = 1; k <= i; k++)
		{
			ll sum = 0;
			for(int j = i - 1; j >= 0; j--)
			{
				sum += a[j + 1];
	
				if((sum | m) == m)
					pd[i][k] |= pd[j][k - 1];
			}
		}
	}

	bool f = 0;
	for(int i = _; i <= b; i++)
		f |= pd[n][i];

	return f;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> _ >> b;

	for(int i = 1; i <= n; i++)
		cin >> a[i];

	if(_ != 1)
	{
		ll tmp = inf;

		for(int i = 50; i >= 0; i--)
			if(f2(tmp ^ (1LL << i)))
				tmp ^= (1LL << i);

		cout << tmp << endl;
		return 0;
	}

	ll tmp = inf;

	for(int i = 50; i >= 0; i--)
		if(f(tmp ^ (1LL << i)) <= b)
			tmp ^= (1LL << i);

	cout << tmp << endl;
}





# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 708 KB Output is correct
8 Correct 2 ms 708 KB Output is correct
9 Correct 2 ms 708 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 15 ms 708 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 752 KB Output is correct
35 Correct 2 ms 752 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 752 KB Output is correct
2 Correct 2 ms 752 KB Output is correct
3 Correct 2 ms 752 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 2 ms 752 KB Output is correct
19 Correct 2 ms 752 KB Output is correct
20 Correct 2 ms 752 KB Output is correct
21 Correct 2 ms 752 KB Output is correct
22 Correct 2 ms 752 KB Output is correct
23 Correct 2 ms 752 KB Output is correct
24 Correct 2 ms 752 KB Output is correct
25 Correct 2 ms 752 KB Output is correct
26 Correct 2 ms 752 KB Output is correct
27 Correct 2 ms 752 KB Output is correct
28 Correct 3 ms 752 KB Output is correct
29 Correct 3 ms 752 KB Output is correct
30 Correct 3 ms 752 KB Output is correct
31 Correct 3 ms 752 KB Output is correct
32 Correct 2 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 752 KB Output is correct
2 Correct 2 ms 752 KB Output is correct
3 Correct 2 ms 752 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 2 ms 752 KB Output is correct
19 Correct 2 ms 752 KB Output is correct
20 Correct 2 ms 752 KB Output is correct
21 Correct 3 ms 752 KB Output is correct
22 Correct 2 ms 752 KB Output is correct
23 Correct 2 ms 752 KB Output is correct
24 Correct 3 ms 752 KB Output is correct
25 Correct 2 ms 752 KB Output is correct
26 Correct 2 ms 752 KB Output is correct
27 Correct 2 ms 752 KB Output is correct
28 Correct 2 ms 752 KB Output is correct
29 Correct 2 ms 752 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 764 KB Output is correct
32 Correct 2 ms 764 KB Output is correct
33 Correct 2 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 2 ms 764 KB Output is correct
36 Correct 2 ms 764 KB Output is correct
37 Correct 2 ms 764 KB Output is correct
38 Correct 2 ms 764 KB Output is correct
39 Correct 2 ms 764 KB Output is correct
40 Correct 2 ms 764 KB Output is correct
41 Correct 2 ms 764 KB Output is correct
42 Correct 2 ms 764 KB Output is correct
43 Correct 2 ms 764 KB Output is correct
44 Correct 2 ms 764 KB Output is correct
45 Correct 2 ms 764 KB Output is correct
46 Correct 2 ms 764 KB Output is correct
47 Correct 2 ms 764 KB Output is correct
48 Correct 2 ms 764 KB Output is correct
49 Correct 2 ms 764 KB Output is correct
50 Correct 2 ms 764 KB Output is correct
51 Correct 3 ms 764 KB Output is correct
52 Correct 2 ms 764 KB Output is correct
53 Correct 2 ms 764 KB Output is correct
54 Correct 3 ms 764 KB Output is correct
55 Correct 3 ms 764 KB Output is correct
56 Correct 2 ms 764 KB Output is correct
57 Correct 2 ms 764 KB Output is correct
58 Correct 2 ms 764 KB Output is correct
59 Correct 3 ms 764 KB Output is correct
60 Correct 2 ms 764 KB Output is correct
61 Correct 2 ms 764 KB Output is correct
62 Correct 2 ms 764 KB Output is correct
63 Correct 2 ms 764 KB Output is correct
64 Correct 31 ms 764 KB Output is correct
65 Correct 6 ms 764 KB Output is correct
66 Correct 14 ms 764 KB Output is correct
67 Correct 15 ms 764 KB Output is correct
68 Correct 24 ms 764 KB Output is correct
69 Correct 30 ms 764 KB Output is correct
70 Correct 32 ms 764 KB Output is correct
71 Correct 32 ms 764 KB Output is correct
72 Correct 39 ms 764 KB Output is correct
73 Correct 34 ms 764 KB Output is correct
74 Correct 36 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 764 KB Output is correct
2 Correct 2 ms 764 KB Output is correct
3 Correct 2 ms 764 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 764 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 2 ms 764 KB Output is correct
11 Correct 2 ms 764 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 2 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 2 ms 764 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 2 ms 764 KB Output is correct
23 Correct 2 ms 764 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 764 KB Output is correct
26 Correct 2 ms 764 KB Output is correct
27 Correct 2 ms 764 KB Output is correct
28 Correct 2 ms 764 KB Output is correct
29 Correct 2 ms 764 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 764 KB Output is correct
32 Correct 2 ms 764 KB Output is correct
33 Correct 2 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 2 ms 764 KB Output is correct
36 Correct 2 ms 764 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 3 ms 764 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 3 ms 764 KB Output is correct
41 Correct 3 ms 764 KB Output is correct
42 Correct 3 ms 764 KB Output is correct
43 Correct 2 ms 764 KB Output is correct
44 Correct 2 ms 764 KB Output is correct
45 Correct 2 ms 764 KB Output is correct
46 Correct 3 ms 764 KB Output is correct
47 Correct 2 ms 764 KB Output is correct
48 Correct 3 ms 764 KB Output is correct
49 Correct 2 ms 764 KB Output is correct
50 Correct 3 ms 764 KB Output is correct
51 Correct 2 ms 764 KB Output is correct
52 Correct 16 ms 764 KB Output is correct
53 Correct 28 ms 764 KB Output is correct
54 Correct 53 ms 764 KB Output is correct
55 Correct 45 ms 764 KB Output is correct
56 Correct 178 ms 764 KB Output is correct
57 Correct 160 ms 764 KB Output is correct
58 Correct 158 ms 768 KB Output is correct
59 Correct 147 ms 768 KB Output is correct
60 Correct 157 ms 768 KB Output is correct
61 Correct 3 ms 768 KB Output is correct
62 Correct 29 ms 768 KB Output is correct
63 Correct 51 ms 768 KB Output is correct
64 Correct 47 ms 768 KB Output is correct
65 Correct 77 ms 768 KB Output is correct
66 Correct 116 ms 768 KB Output is correct
67 Correct 175 ms 868 KB Output is correct
68 Correct 161 ms 868 KB Output is correct
69 Correct 152 ms 868 KB Output is correct