Submission #127614

# Submission time Handle Problem Language Result Execution time Memory
127614 2019-07-09T16:28:49 Z MohamedAhmed04 Bali Sculptures (APIO15_sculpture) C++14
71 / 100
148 ms 9592 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 2005 ;
const int MAX2 = 105 ;

long long arr[MAX] , pref[MAX];

long long dp[MAX2][MAX2][MAX2] ;
long long dp2[MAX][MAX] ;

int n , a , b ;

long long now = 0 ;

long long bit1 = 0 , bit2 = 0;

long long calc1(int idx , int st , int groups)
{
    if(idx == n && groups >= a && groups <= b)
    {
        long long val ;
        if(st == 0)
            val = pref[idx-1] ;
        else
            val = pref[idx-1] - pref[st-1] ;
        if(!((val & bit1)))
            return val ;
        return (1ll << 58) ;
    }
    if(groups > b)
        return (1ll << 58) ;
    if(idx == n && groups < a || groups > b)
        return (1ll << 58) ;
    long long &ret = dp[idx][st][groups] ;
    if(ret != -1)
        return ret ;
    long long val ;
    if(st == 0)
        val = pref[idx-1] ;
    else
        val = pref[idx-1] - pref[st-1] ;
    long long choice1 = calc1(idx+1 , st , groups) ;
    long long choice2 = (1ll << 58) ;
    if(!((val & bit1)))
        choice2 = calc1(idx+1 , idx , groups+1) | val ;
    ret = min(choice1 , choice2) ;
    return ret ;
}

long long calc2(int idx , int st)
{
    if(idx == n)
    {
        long long val ;
        if(st == 0)
            val = pref[idx-1] ;
        else
            val = pref[idx-1] - pref[st-1] ;
        if(!((val & bit1)))
            return 0 ;
        return (1ll << 30) ;
    }
    long long &ret = dp2[idx][st] ;
    if(ret != -1)
        return ret ;
    long long val ;
    if(st == 0)
        val = pref[idx-1] ;
    else
        val = pref[idx-1] - pref[st-1] ;
    long long choice1 = calc2(idx+1 , st) ;
    long long choice2 = (1ll << 30) ;
    if(!((val & bit1)))
        choice2 = calc2(idx+1 , idx) + 1;
    ret = min(choice1 , choice2) ;
    return ret ;
}

void solve1()
{
    long long ans = 0 ;
    for(int i = 42 ; i >= 0 ; --i)
    {
        memset(dp2 , -1 , sizeof(dp)) ;
        bit1 |= (1ll << i) ;
        long long a = calc2(1 , 0) + 1;
        if(a > b)
        {
            bit1 ^= (1ll << i) ;
            ans += (1ll << i) ;
        }
    }
    cout<<ans<<"\n" ;
    return ;
}

void solve2()
{
    long long ans = 0 ;
    for(int i = 42 ; i >= 0 ; --i)
    {
        memset(dp , -1 , sizeof(dp)) ;
        bit1 |= (1ll << i) ;
        long long a = calc1(1 , 0 , 1) ;
        if(a >= (1ll << 58))
        {
            bit1 ^= (1ll << i) ;
            ans += (1ll << i) ;
        }
    }
    cout<<ans<<"\n" ;
    return ;
}


int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ;
    cin>>n>>a>>b ;
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    pref[0] = arr[0] ;
    for(int i = 1 ; i < n ; ++i)
        pref[i] = pref[i-1] + arr[i] ;
    if(a == 1)
    {
        solve1() ;
        return 0 ;
    }
    solve2() ;
    return 0 ;
}

Compilation message

sculpture.cpp: In function 'long long int calc1(int, int, int)':
sculpture.cpp:34:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if(idx == n && groups < a || groups > b)
        ~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 9464 KB Output is correct
2 Correct 31 ms 9336 KB Output is correct
3 Correct 32 ms 9464 KB Output is correct
4 Correct 30 ms 9336 KB Output is correct
5 Correct 31 ms 9336 KB Output is correct
6 Correct 30 ms 9464 KB Output is correct
7 Correct 31 ms 9336 KB Output is correct
8 Correct 30 ms 9464 KB Output is correct
9 Correct 30 ms 9464 KB Output is correct
10 Correct 31 ms 9456 KB Output is correct
11 Correct 32 ms 9464 KB Output is correct
12 Correct 30 ms 9336 KB Output is correct
13 Correct 30 ms 9340 KB Output is correct
14 Correct 34 ms 9464 KB Output is correct
15 Correct 33 ms 9336 KB Output is correct
16 Correct 34 ms 9336 KB Output is correct
17 Correct 34 ms 9336 KB Output is correct
18 Correct 33 ms 9452 KB Output is correct
19 Correct 30 ms 9336 KB Output is correct
20 Correct 31 ms 9448 KB Output is correct
21 Correct 30 ms 9336 KB Output is correct
22 Correct 30 ms 9464 KB Output is correct
23 Correct 30 ms 9464 KB Output is correct
24 Correct 30 ms 9336 KB Output is correct
25 Correct 31 ms 9336 KB Output is correct
26 Correct 31 ms 9464 KB Output is correct
27 Correct 30 ms 9336 KB Output is correct
28 Correct 31 ms 9336 KB Output is correct
29 Correct 31 ms 9336 KB Output is correct
30 Correct 31 ms 9336 KB Output is correct
31 Correct 29 ms 9336 KB Output is correct
32 Correct 31 ms 9336 KB Output is correct
33 Correct 29 ms 9336 KB Output is correct
34 Correct 31 ms 9464 KB Output is correct
35 Correct 30 ms 9336 KB Output is correct
36 Correct 31 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 9464 KB Output is correct
2 Correct 30 ms 9452 KB Output is correct
3 Correct 32 ms 9464 KB Output is correct
4 Correct 31 ms 9336 KB Output is correct
5 Correct 30 ms 9464 KB Output is correct
6 Correct 31 ms 9336 KB Output is correct
7 Correct 30 ms 9336 KB Output is correct
8 Correct 35 ms 9464 KB Output is correct
9 Correct 30 ms 9464 KB Output is correct
10 Correct 30 ms 9336 KB Output is correct
11 Correct 31 ms 9464 KB Output is correct
12 Correct 30 ms 9448 KB Output is correct
13 Correct 31 ms 9464 KB Output is correct
14 Correct 31 ms 9468 KB Output is correct
15 Correct 30 ms 9464 KB Output is correct
16 Correct 31 ms 9464 KB Output is correct
17 Correct 30 ms 9464 KB Output is correct
18 Correct 30 ms 9464 KB Output is correct
19 Correct 31 ms 9336 KB Output is correct
20 Correct 30 ms 9464 KB Output is correct
21 Correct 32 ms 9464 KB Output is correct
22 Correct 32 ms 9464 KB Output is correct
23 Correct 31 ms 9464 KB Output is correct
24 Correct 30 ms 9336 KB Output is correct
25 Correct 32 ms 9464 KB Output is correct
26 Correct 31 ms 9464 KB Output is correct
27 Correct 30 ms 9464 KB Output is correct
28 Correct 30 ms 9464 KB Output is correct
29 Correct 32 ms 9464 KB Output is correct
30 Correct 31 ms 9464 KB Output is correct
31 Correct 31 ms 9464 KB Output is correct
32 Correct 31 ms 9336 KB Output is correct
33 Correct 30 ms 9340 KB Output is correct
34 Correct 32 ms 9384 KB Output is correct
35 Correct 30 ms 9336 KB Output is correct
36 Correct 32 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 9336 KB Output is correct
2 Correct 30 ms 9464 KB Output is correct
3 Correct 32 ms 9464 KB Output is correct
4 Correct 31 ms 9448 KB Output is correct
5 Correct 31 ms 9452 KB Output is correct
6 Correct 31 ms 9436 KB Output is correct
7 Correct 30 ms 9340 KB Output is correct
8 Correct 31 ms 9464 KB Output is correct
9 Correct 30 ms 9464 KB Output is correct
10 Correct 29 ms 9336 KB Output is correct
11 Correct 30 ms 9336 KB Output is correct
12 Correct 30 ms 9592 KB Output is correct
13 Correct 31 ms 9464 KB Output is correct
14 Correct 30 ms 9464 KB Output is correct
15 Correct 31 ms 9468 KB Output is correct
16 Correct 31 ms 9336 KB Output is correct
17 Correct 30 ms 9336 KB Output is correct
18 Correct 31 ms 9448 KB Output is correct
19 Correct 31 ms 9464 KB Output is correct
20 Correct 30 ms 9468 KB Output is correct
21 Correct 31 ms 9464 KB Output is correct
22 Correct 30 ms 9336 KB Output is correct
23 Correct 30 ms 9464 KB Output is correct
24 Correct 31 ms 9464 KB Output is correct
25 Correct 32 ms 9468 KB Output is correct
26 Correct 32 ms 9336 KB Output is correct
27 Correct 33 ms 9464 KB Output is correct
28 Correct 34 ms 9464 KB Output is correct
29 Correct 35 ms 9464 KB Output is correct
30 Correct 35 ms 9464 KB Output is correct
31 Correct 36 ms 9488 KB Output is correct
32 Correct 36 ms 9488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 9336 KB Output is correct
2 Correct 30 ms 9488 KB Output is correct
3 Correct 30 ms 9336 KB Output is correct
4 Correct 31 ms 9336 KB Output is correct
5 Correct 30 ms 9464 KB Output is correct
6 Correct 30 ms 9464 KB Output is correct
7 Correct 31 ms 9336 KB Output is correct
8 Correct 30 ms 9436 KB Output is correct
9 Correct 36 ms 9592 KB Output is correct
10 Correct 30 ms 9336 KB Output is correct
11 Correct 31 ms 9516 KB Output is correct
12 Correct 31 ms 9464 KB Output is correct
13 Correct 31 ms 9464 KB Output is correct
14 Correct 31 ms 9464 KB Output is correct
15 Correct 30 ms 9464 KB Output is correct
16 Correct 29 ms 9464 KB Output is correct
17 Correct 30 ms 9464 KB Output is correct
18 Correct 30 ms 9464 KB Output is correct
19 Correct 30 ms 9464 KB Output is correct
20 Correct 31 ms 9464 KB Output is correct
21 Correct 30 ms 9464 KB Output is correct
22 Correct 32 ms 9464 KB Output is correct
23 Correct 32 ms 9464 KB Output is correct
24 Correct 30 ms 9336 KB Output is correct
25 Correct 31 ms 9340 KB Output is correct
26 Correct 32 ms 9464 KB Output is correct
27 Correct 32 ms 9336 KB Output is correct
28 Correct 30 ms 9336 KB Output is correct
29 Correct 30 ms 9464 KB Output is correct
30 Correct 30 ms 9512 KB Output is correct
31 Correct 34 ms 9464 KB Output is correct
32 Correct 32 ms 9464 KB Output is correct
33 Correct 31 ms 9336 KB Output is correct
34 Correct 30 ms 9464 KB Output is correct
35 Correct 30 ms 9464 KB Output is correct
36 Correct 31 ms 9452 KB Output is correct
37 Correct 33 ms 9464 KB Output is correct
38 Correct 30 ms 9468 KB Output is correct
39 Correct 30 ms 9336 KB Output is correct
40 Correct 31 ms 9464 KB Output is correct
41 Correct 32 ms 9464 KB Output is correct
42 Correct 31 ms 9336 KB Output is correct
43 Correct 32 ms 9464 KB Output is correct
44 Correct 33 ms 9452 KB Output is correct
45 Correct 33 ms 9464 KB Output is correct
46 Correct 31 ms 9336 KB Output is correct
47 Correct 32 ms 9436 KB Output is correct
48 Correct 31 ms 9464 KB Output is correct
49 Correct 34 ms 9464 KB Output is correct
50 Correct 35 ms 9464 KB Output is correct
51 Correct 33 ms 9436 KB Output is correct
52 Correct 35 ms 9464 KB Output is correct
53 Correct 35 ms 9464 KB Output is correct
54 Correct 36 ms 9452 KB Output is correct
55 Correct 35 ms 9452 KB Output is correct
56 Correct 30 ms 9336 KB Output is correct
57 Correct 33 ms 9468 KB Output is correct
58 Correct 32 ms 9464 KB Output is correct
59 Correct 31 ms 9336 KB Output is correct
60 Correct 32 ms 9464 KB Output is correct
61 Correct 31 ms 9464 KB Output is correct
62 Correct 32 ms 9464 KB Output is correct
63 Correct 32 ms 9464 KB Output is correct
64 Correct 148 ms 9464 KB Output is correct
65 Correct 33 ms 9464 KB Output is correct
66 Correct 36 ms 9468 KB Output is correct
67 Correct 43 ms 9468 KB Output is correct
68 Correct 64 ms 9592 KB Output is correct
69 Correct 73 ms 9464 KB Output is correct
70 Correct 69 ms 9452 KB Output is correct
71 Correct 31 ms 9436 KB Output is correct
72 Correct 90 ms 9464 KB Output is correct
73 Correct 88 ms 9464 KB Output is correct
74 Correct 87 ms 9436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 9340 KB Output is correct
2 Correct 29 ms 9336 KB Output is correct
3 Correct 30 ms 9464 KB Output is correct
4 Correct 31 ms 9336 KB Output is correct
5 Correct 34 ms 9336 KB Output is correct
6 Correct 30 ms 9464 KB Output is correct
7 Correct 30 ms 9464 KB Output is correct
8 Correct 31 ms 9464 KB Output is correct
9 Correct 31 ms 9468 KB Output is correct
10 Correct 31 ms 9336 KB Output is correct
11 Correct 31 ms 9336 KB Output is correct
12 Correct 30 ms 9464 KB Output is correct
13 Correct 29 ms 9336 KB Output is correct
14 Correct 30 ms 9464 KB Output is correct
15 Correct 29 ms 9464 KB Output is correct
16 Correct 29 ms 9464 KB Output is correct
17 Correct 31 ms 9336 KB Output is correct
18 Correct 31 ms 9468 KB Output is correct
19 Correct 32 ms 9440 KB Output is correct
20 Correct 31 ms 9340 KB Output is correct
21 Correct 31 ms 9488 KB Output is correct
22 Correct 30 ms 9464 KB Output is correct
23 Correct 30 ms 9464 KB Output is correct
24 Correct 30 ms 9464 KB Output is correct
25 Correct 30 ms 9464 KB Output is correct
26 Correct 32 ms 9464 KB Output is correct
27 Correct 30 ms 9464 KB Output is correct
28 Correct 33 ms 9464 KB Output is correct
29 Correct 32 ms 9464 KB Output is correct
30 Correct 31 ms 9336 KB Output is correct
31 Correct 36 ms 9464 KB Output is correct
32 Correct 34 ms 9464 KB Output is correct
33 Correct 31 ms 9464 KB Output is correct
34 Correct 32 ms 9464 KB Output is correct
35 Correct 32 ms 9336 KB Output is correct
36 Correct 33 ms 9336 KB Output is correct
37 Correct 33 ms 9492 KB Output is correct
38 Correct 33 ms 9464 KB Output is correct
39 Correct 33 ms 9464 KB Output is correct
40 Correct 34 ms 9464 KB Output is correct
41 Correct 34 ms 9464 KB Output is correct
42 Correct 33 ms 9464 KB Output is correct
43 Correct 32 ms 9464 KB Output is correct
44 Correct 31 ms 9336 KB Output is correct
45 Correct 31 ms 9336 KB Output is correct
46 Correct 31 ms 9336 KB Output is correct
47 Correct 33 ms 9464 KB Output is correct
48 Correct 32 ms 9336 KB Output is correct
49 Correct 33 ms 9464 KB Output is correct
50 Correct 33 ms 9336 KB Output is correct
51 Correct 31 ms 9464 KB Output is correct
52 Correct 101 ms 9464 KB Output is correct
53 Incorrect 79 ms 9464 KB Output isn't correct
54 Halted 0 ms 0 KB -