Submission #219968

# Submission time Handle Problem Language Result Execution time Memory
219968 2020-04-06T18:15:47 Z MKopchev Bali Sculptures (APIO15_sculpture) C++14
100 / 100
105 ms 4600 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e3+42;
int n,a,b,inp[nmax];
long long pref[nmax];

long long current;

bool possible;

bool been[nmax][nmax];

void dfs(int groups,int last_end)
{
    if(possible)return;
    if(groups>b)return;

    if(last_end==n)
    {
        if(groups>=a)possible=1;
        return;
    }

    if(been[groups][last_end])return;
    been[groups][last_end]=1;

    if(((pref[n]-pref[last_end])&current)==(pref[n]-pref[last_end]))dfs(groups+1,n);

    for(int j=last_end+1;j<n;j++)
    {
        long long sum=pref[j]-pref[last_end];
        if((current&sum)==sum)dfs(groups+1,j);
    }
}

int dp[nmax];
void special()
{
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i]=1e9;
        for(int j=i;j>=1;j--)
        {
            long long sum=pref[i]-pref[j-1];
            if((sum&current)==sum)dp[i]=min(dp[i],dp[j-1]+1);
        }
    }

    //for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;

    possible=(dp[n]<=b);
}
bool can(long long to_test)
{
    current=to_test;

    memset(been,0,sizeof(been));

    possible=0;

    if(a==1)special();
    else dfs(0,0);

    return possible;
}
int main()
{
    scanf("%i%i%i",&n,&a,&b);
    for(int i=1;i<=n;i++)scanf("%i",&inp[i]);

    for(int i=1;i<=n;i++)pref[i]=pref[i-1]+inp[i];

    long long output=(1LL<<41)-1;

    for(int i=40;i>=0;i--)
        if(can(output-(1LL<<i)))output=output-(1LL<<i);

    printf("%lld\n",output);
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i%i",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~
sculpture.cpp:70:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
                          ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4352 KB Output is correct
2 Correct 11 ms 4352 KB Output is correct
3 Correct 11 ms 4352 KB Output is correct
4 Correct 11 ms 4352 KB Output is correct
5 Correct 11 ms 4352 KB Output is correct
6 Correct 11 ms 4480 KB Output is correct
7 Correct 12 ms 4352 KB Output is correct
8 Correct 14 ms 4352 KB Output is correct
9 Correct 11 ms 4352 KB Output is correct
10 Correct 12 ms 4480 KB Output is correct
11 Correct 12 ms 4352 KB Output is correct
12 Correct 12 ms 4352 KB Output is correct
13 Correct 12 ms 4480 KB Output is correct
14 Correct 11 ms 4352 KB Output is correct
15 Correct 12 ms 4480 KB Output is correct
16 Correct 11 ms 4352 KB Output is correct
17 Correct 12 ms 4352 KB Output is correct
18 Correct 12 ms 4352 KB Output is correct
19 Correct 12 ms 4480 KB Output is correct
20 Correct 12 ms 4352 KB Output is correct
21 Correct 12 ms 4352 KB Output is correct
22 Correct 11 ms 4352 KB Output is correct
23 Correct 11 ms 4480 KB Output is correct
24 Correct 12 ms 4352 KB Output is correct
25 Correct 11 ms 4352 KB Output is correct
26 Correct 11 ms 4480 KB Output is correct
27 Correct 11 ms 4352 KB Output is correct
28 Correct 11 ms 4352 KB Output is correct
29 Correct 11 ms 4480 KB Output is correct
30 Correct 11 ms 4352 KB Output is correct
31 Correct 12 ms 4480 KB Output is correct
32 Correct 12 ms 4352 KB Output is correct
33 Correct 11 ms 4352 KB Output is correct
34 Correct 12 ms 4352 KB Output is correct
35 Correct 11 ms 4352 KB Output is correct
36 Correct 12 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4352 KB Output is correct
2 Correct 12 ms 4344 KB Output is correct
3 Correct 11 ms 4352 KB Output is correct
4 Correct 12 ms 4352 KB Output is correct
5 Correct 12 ms 4480 KB Output is correct
6 Correct 11 ms 4352 KB Output is correct
7 Correct 12 ms 4480 KB Output is correct
8 Correct 12 ms 4352 KB Output is correct
9 Correct 13 ms 4352 KB Output is correct
10 Correct 11 ms 4352 KB Output is correct
11 Correct 16 ms 4352 KB Output is correct
12 Correct 12 ms 4352 KB Output is correct
13 Correct 12 ms 4352 KB Output is correct
14 Correct 12 ms 4352 KB Output is correct
15 Correct 12 ms 4352 KB Output is correct
16 Correct 14 ms 4352 KB Output is correct
17 Correct 12 ms 4480 KB Output is correct
18 Correct 11 ms 4352 KB Output is correct
19 Correct 11 ms 4352 KB Output is correct
20 Correct 12 ms 4352 KB Output is correct
21 Correct 12 ms 4352 KB Output is correct
22 Correct 12 ms 4352 KB Output is correct
23 Correct 12 ms 4480 KB Output is correct
24 Correct 12 ms 4352 KB Output is correct
25 Correct 11 ms 4352 KB Output is correct
26 Correct 12 ms 4352 KB Output is correct
27 Correct 11 ms 4352 KB Output is correct
28 Correct 11 ms 4352 KB Output is correct
29 Correct 12 ms 4352 KB Output is correct
30 Correct 12 ms 4480 KB Output is correct
31 Correct 12 ms 4352 KB Output is correct
32 Correct 12 ms 4352 KB Output is correct
33 Correct 19 ms 4352 KB Output is correct
34 Correct 12 ms 4352 KB Output is correct
35 Correct 12 ms 4352 KB Output is correct
36 Correct 12 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4480 KB Output is correct
2 Correct 11 ms 4352 KB Output is correct
3 Correct 11 ms 4352 KB Output is correct
4 Correct 12 ms 4352 KB Output is correct
5 Correct 12 ms 4352 KB Output is correct
6 Correct 11 ms 4352 KB Output is correct
7 Correct 12 ms 4352 KB Output is correct
8 Correct 11 ms 4352 KB Output is correct
9 Correct 11 ms 4352 KB Output is correct
10 Correct 11 ms 4352 KB Output is correct
11 Correct 14 ms 4352 KB Output is correct
12 Correct 11 ms 4352 KB Output is correct
13 Correct 11 ms 4352 KB Output is correct
14 Correct 11 ms 4352 KB Output is correct
15 Correct 15 ms 4352 KB Output is correct
16 Correct 11 ms 4480 KB Output is correct
17 Correct 11 ms 4352 KB Output is correct
18 Correct 11 ms 4352 KB Output is correct
19 Correct 11 ms 4352 KB Output is correct
20 Correct 12 ms 4352 KB Output is correct
21 Correct 12 ms 4352 KB Output is correct
22 Correct 11 ms 4352 KB Output is correct
23 Correct 12 ms 4480 KB Output is correct
24 Correct 11 ms 4352 KB Output is correct
25 Correct 15 ms 4480 KB Output is correct
26 Correct 12 ms 4352 KB Output is correct
27 Correct 12 ms 4352 KB Output is correct
28 Correct 12 ms 4352 KB Output is correct
29 Correct 12 ms 4352 KB Output is correct
30 Correct 12 ms 4352 KB Output is correct
31 Correct 12 ms 4352 KB Output is correct
32 Correct 13 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4352 KB Output is correct
2 Correct 12 ms 4352 KB Output is correct
3 Correct 12 ms 4352 KB Output is correct
4 Correct 12 ms 4480 KB Output is correct
5 Correct 12 ms 4352 KB Output is correct
6 Correct 12 ms 4480 KB Output is correct
7 Correct 12 ms 4352 KB Output is correct
8 Correct 12 ms 4480 KB Output is correct
9 Correct 13 ms 4352 KB Output is correct
10 Correct 12 ms 4352 KB Output is correct
11 Correct 12 ms 4480 KB Output is correct
12 Correct 11 ms 4352 KB Output is correct
13 Correct 11 ms 4352 KB Output is correct
14 Correct 12 ms 4352 KB Output is correct
15 Correct 11 ms 4352 KB Output is correct
16 Correct 12 ms 4480 KB Output is correct
17 Correct 15 ms 4352 KB Output is correct
18 Correct 17 ms 4352 KB Output is correct
19 Correct 12 ms 4352 KB Output is correct
20 Correct 12 ms 4352 KB Output is correct
21 Correct 11 ms 4352 KB Output is correct
22 Correct 11 ms 4352 KB Output is correct
23 Correct 12 ms 4352 KB Output is correct
24 Correct 12 ms 4352 KB Output is correct
25 Correct 11 ms 4352 KB Output is correct
26 Correct 11 ms 4352 KB Output is correct
27 Correct 12 ms 4352 KB Output is correct
28 Correct 12 ms 4352 KB Output is correct
29 Correct 11 ms 4352 KB Output is correct
30 Correct 12 ms 4352 KB Output is correct
31 Correct 12 ms 4352 KB Output is correct
32 Correct 12 ms 4352 KB Output is correct
33 Correct 12 ms 4352 KB Output is correct
34 Correct 12 ms 4352 KB Output is correct
35 Correct 12 ms 4352 KB Output is correct
36 Correct 12 ms 4352 KB Output is correct
37 Correct 12 ms 4352 KB Output is correct
38 Correct 11 ms 4352 KB Output is correct
39 Correct 12 ms 4480 KB Output is correct
40 Correct 11 ms 4352 KB Output is correct
41 Correct 12 ms 4480 KB Output is correct
42 Correct 12 ms 4352 KB Output is correct
43 Correct 12 ms 4480 KB Output is correct
44 Correct 12 ms 4352 KB Output is correct
45 Correct 12 ms 4352 KB Output is correct
46 Correct 12 ms 4352 KB Output is correct
47 Correct 12 ms 4352 KB Output is correct
48 Correct 12 ms 4352 KB Output is correct
49 Correct 12 ms 4352 KB Output is correct
50 Correct 12 ms 4352 KB Output is correct
51 Correct 12 ms 4352 KB Output is correct
52 Correct 12 ms 4352 KB Output is correct
53 Correct 12 ms 4352 KB Output is correct
54 Correct 13 ms 4352 KB Output is correct
55 Correct 12 ms 4480 KB Output is correct
56 Correct 12 ms 4352 KB Output is correct
57 Correct 12 ms 4352 KB Output is correct
58 Correct 12 ms 4480 KB Output is correct
59 Correct 12 ms 4352 KB Output is correct
60 Correct 12 ms 4352 KB Output is correct
61 Correct 12 ms 4352 KB Output is correct
62 Correct 12 ms 4352 KB Output is correct
63 Correct 19 ms 4480 KB Output is correct
64 Correct 12 ms 4480 KB Output is correct
65 Correct 12 ms 4352 KB Output is correct
66 Correct 12 ms 4352 KB Output is correct
67 Correct 11 ms 4352 KB Output is correct
68 Correct 12 ms 4352 KB Output is correct
69 Correct 14 ms 4352 KB Output is correct
70 Correct 12 ms 4352 KB Output is correct
71 Correct 12 ms 4480 KB Output is correct
72 Correct 12 ms 4352 KB Output is correct
73 Correct 13 ms 4352 KB Output is correct
74 Correct 12 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4352 KB Output is correct
2 Correct 12 ms 4352 KB Output is correct
3 Correct 12 ms 4480 KB Output is correct
4 Correct 12 ms 4352 KB Output is correct
5 Correct 11 ms 4352 KB Output is correct
6 Correct 11 ms 4352 KB Output is correct
7 Correct 12 ms 4352 KB Output is correct
8 Correct 11 ms 4352 KB Output is correct
9 Correct 11 ms 4352 KB Output is correct
10 Correct 11 ms 4352 KB Output is correct
11 Correct 12 ms 4352 KB Output is correct
12 Correct 11 ms 4352 KB Output is correct
13 Correct 14 ms 4480 KB Output is correct
14 Correct 12 ms 4352 KB Output is correct
15 Correct 12 ms 4352 KB Output is correct
16 Correct 12 ms 4352 KB Output is correct
17 Correct 13 ms 4480 KB Output is correct
18 Correct 11 ms 4352 KB Output is correct
19 Correct 12 ms 4352 KB Output is correct
20 Correct 12 ms 4352 KB Output is correct
21 Correct 11 ms 4352 KB Output is correct
22 Correct 14 ms 4352 KB Output is correct
23 Correct 12 ms 4352 KB Output is correct
24 Correct 12 ms 4352 KB Output is correct
25 Correct 12 ms 4352 KB Output is correct
26 Correct 12 ms 4352 KB Output is correct
27 Correct 12 ms 4352 KB Output is correct
28 Correct 12 ms 4352 KB Output is correct
29 Correct 12 ms 4352 KB Output is correct
30 Correct 11 ms 4352 KB Output is correct
31 Correct 12 ms 4480 KB Output is correct
32 Correct 14 ms 4352 KB Output is correct
33 Correct 18 ms 4480 KB Output is correct
34 Correct 11 ms 4480 KB Output is correct
35 Correct 12 ms 4352 KB Output is correct
36 Correct 12 ms 4352 KB Output is correct
37 Correct 12 ms 4352 KB Output is correct
38 Correct 12 ms 4352 KB Output is correct
39 Correct 13 ms 4352 KB Output is correct
40 Correct 12 ms 4352 KB Output is correct
41 Correct 12 ms 4352 KB Output is correct
42 Correct 14 ms 4352 KB Output is correct
43 Correct 12 ms 4352 KB Output is correct
44 Correct 12 ms 4352 KB Output is correct
45 Correct 12 ms 4456 KB Output is correct
46 Correct 12 ms 4352 KB Output is correct
47 Correct 13 ms 4480 KB Output is correct
48 Correct 12 ms 4480 KB Output is correct
49 Correct 12 ms 4480 KB Output is correct
50 Correct 12 ms 4352 KB Output is correct
51 Correct 12 ms 4352 KB Output is correct
52 Correct 20 ms 4480 KB Output is correct
53 Correct 26 ms 4480 KB Output is correct
54 Correct 37 ms 4480 KB Output is correct
55 Correct 37 ms 4480 KB Output is correct
56 Correct 95 ms 4480 KB Output is correct
57 Correct 100 ms 4480 KB Output is correct
58 Correct 93 ms 4480 KB Output is correct
59 Correct 88 ms 4480 KB Output is correct
60 Correct 103 ms 4480 KB Output is correct
61 Correct 12 ms 4352 KB Output is correct
62 Correct 25 ms 4480 KB Output is correct
63 Correct 40 ms 4480 KB Output is correct
64 Correct 34 ms 4480 KB Output is correct
65 Correct 54 ms 4480 KB Output is correct
66 Correct 88 ms 4600 KB Output is correct
67 Correct 104 ms 4480 KB Output is correct
68 Correct 105 ms 4488 KB Output is correct
69 Correct 93 ms 4480 KB Output is correct