Submission #463814

# Submission time Handle Problem Language Result Execution time Memory
463814 2021-08-11T19:41:42 Z MohamedAhmed04 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
235 ms 16072 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 2004 ;

int arr[MAX] ;
int n , a , b ;

long long mask , ans ;

int dp[MAX][MAX] ;

int solve(int idx , int groups)
{
	if(groups > b)
		return 0 ;
	if(idx == n)
		return (groups >= a && groups <= b) ;
	int &ret = dp[idx][groups] ;
	if(ret != -1)
		return ret ;
	ret = 0 ;
	long long sum = 0 ;
	for(int i = idx ; i < n ; ++i)
	{
		sum += arr[i] ;
		if((sum & mask))
			continue ;
		ret |= solve(i+1 , groups+1) ;
	}
	return ret ;
}

bool check1()
{
	memset(dp , -1 , sizeof(dp)) ;
	return (solve(0 , 0) == 1) ;
}

void calc1()
{
	for(int bit = 50 ; bit >= 0 ; --bit)
	{
		mask |= (1ll << bit) ;
		if(!check1())
			mask ^= (1ll << bit) , ans += (1ll << bit) ;
	}
}

int dp2[MAX] ;

int solve2(int idx)
{
	if(idx == n)
		return 0 ;
	int &ret = dp2[idx] ;
	if(ret != -1)
		return ret ;
	ret = 1e9 ;
	long long sum = 0 ;
	for(int i = idx ; i < n ; ++i)
	{
		sum += arr[i] ;
		if((sum & mask))
			continue ;
		ret = min(ret , solve2(i+1) + 1) ;
	}
	return ret ;
}

bool check2()
{
	memset(dp2 , -1 , sizeof(dp2)) ;
	return (solve2(0) <= b) ;
}

void calc2()
{
	for(int bit = 50 ; bit >= 0 ; --bit)
	{
		mask |= (1ll << bit) ;
		if(!check2())
			mask ^= (1ll << bit) , ans += (1ll << bit) ;
	}	
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>a>>b ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	if(a > 1)
		calc1() ;
	else
		calc2() ;
	return cout<<ans<<"\n" , 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 105 ms 16020 KB Output is correct
15 Correct 104 ms 16028 KB Output is correct
16 Correct 109 ms 16020 KB Output is correct
17 Correct 106 ms 15948 KB Output is correct
18 Correct 107 ms 16012 KB Output is correct
19 Correct 109 ms 15916 KB Output is correct
20 Correct 109 ms 16020 KB Output is correct
21 Correct 107 ms 16016 KB Output is correct
22 Correct 103 ms 15948 KB Output is correct
23 Correct 103 ms 16016 KB Output is correct
24 Correct 105 ms 15948 KB Output is correct
25 Correct 102 ms 16068 KB Output is correct
26 Correct 105 ms 16024 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 102 ms 15948 KB Output is correct
15 Correct 108 ms 15948 KB Output is correct
16 Correct 102 ms 15948 KB Output is correct
17 Correct 102 ms 16068 KB Output is correct
18 Correct 103 ms 16012 KB Output is correct
19 Correct 104 ms 16032 KB Output is correct
20 Correct 103 ms 15948 KB Output is correct
21 Correct 102 ms 15948 KB Output is correct
22 Correct 102 ms 15948 KB Output is correct
23 Correct 107 ms 15948 KB Output is correct
24 Correct 101 ms 16020 KB Output is correct
25 Correct 102 ms 16012 KB Output is correct
26 Correct 102 ms 16016 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 216 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 232 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 105 ms 15948 KB Output is correct
15 Correct 105 ms 16016 KB Output is correct
16 Correct 102 ms 15948 KB Output is correct
17 Correct 101 ms 15948 KB Output is correct
18 Correct 103 ms 15948 KB Output is correct
19 Correct 103 ms 16016 KB Output is correct
20 Correct 108 ms 15948 KB Output is correct
21 Correct 103 ms 16020 KB Output is correct
22 Correct 103 ms 15948 KB Output is correct
23 Correct 101 ms 15948 KB Output is correct
24 Correct 102 ms 16016 KB Output is correct
25 Correct 100 ms 16068 KB Output is correct
26 Correct 101 ms 16012 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 272 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 204 KB Output is correct
55 Correct 2 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 143 ms 15948 KB Output is correct
65 Correct 103 ms 16012 KB Output is correct
66 Correct 104 ms 15948 KB Output is correct
67 Correct 108 ms 15948 KB Output is correct
68 Correct 117 ms 16016 KB Output is correct
69 Correct 126 ms 15948 KB Output is correct
70 Correct 123 ms 15948 KB Output is correct
71 Correct 103 ms 16020 KB Output is correct
72 Correct 126 ms 16020 KB Output is correct
73 Correct 131 ms 16072 KB Output is correct
74 Correct 129 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 2 ms 204 KB Output is correct
40 Correct 2 ms 204 KB Output is correct
41 Correct 2 ms 204 KB Output is correct
42 Correct 2 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 18 ms 352 KB Output is correct
53 Correct 23 ms 368 KB Output is correct
54 Correct 65 ms 372 KB Output is correct
55 Correct 50 ms 332 KB Output is correct
56 Correct 154 ms 332 KB Output is correct
57 Correct 148 ms 332 KB Output is correct
58 Correct 163 ms 332 KB Output is correct
59 Correct 189 ms 428 KB Output is correct
60 Correct 174 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 24 ms 332 KB Output is correct
63 Correct 63 ms 368 KB Output is correct
64 Correct 40 ms 332 KB Output is correct
65 Correct 75 ms 392 KB Output is correct
66 Correct 112 ms 332 KB Output is correct
67 Correct 149 ms 452 KB Output is correct
68 Correct 235 ms 428 KB Output is correct
69 Correct 144 ms 420 KB Output is correct