Submission #223654

# Submission time Handle Problem Language Result Execution time Memory
223654 2020-04-15T23:41:13 Z MODDI Bali Sculptures (APIO15_sculpture) C++14
100 / 100
107 ms 4608 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 12 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 4480 KB Output is correct
5 Correct 12 ms 4480 KB Output is correct
6 Correct 11 ms 4352 KB Output is correct
7 Correct 13 ms 4352 KB Output is correct
8 Correct 12 ms 4352 KB Output is correct
9 Correct 12 ms 4352 KB Output is correct
10 Correct 12 ms 4352 KB Output is correct
11 Correct 11 ms 4352 KB Output is correct
12 Correct 12 ms 4480 KB Output is correct
13 Correct 12 ms 4480 KB Output is correct
14 Correct 11 ms 4352 KB Output is correct
15 Correct 11 ms 4352 KB Output is correct
16 Correct 12 ms 4352 KB Output is correct
17 Correct 11 ms 4352 KB Output is correct
18 Correct 12 ms 4352 KB Output is correct
19 Correct 12 ms 4352 KB Output is correct
20 Correct 13 ms 4480 KB Output is correct
21 Correct 12 ms 4352 KB Output is correct
22 Correct 12 ms 4352 KB Output is correct
23 Correct 11 ms 4352 KB Output is correct
24 Correct 11 ms 4352 KB Output is correct
25 Correct 12 ms 4352 KB Output is correct
26 Correct 11 ms 4352 KB Output is correct
27 Correct 11 ms 4480 KB Output is correct
28 Correct 12 ms 4480 KB Output is correct
29 Correct 13 ms 4352 KB Output is correct
30 Correct 13 ms 4480 KB Output is correct
31 Correct 12 ms 4352 KB Output is correct
32 Correct 11 ms 4480 KB Output is correct
33 Correct 11 ms 4352 KB Output is correct
34 Correct 14 ms 4352 KB Output is correct
35 Correct 13 ms 4352 KB Output is correct
36 Correct 13 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4480 KB Output is correct
2 Correct 12 ms 4352 KB Output is correct
3 Correct 12 ms 4352 KB Output is correct
4 Correct 11 ms 4352 KB Output is correct
5 Correct 12 ms 4480 KB Output is correct
6 Correct 11 ms 4480 KB Output is correct
7 Correct 11 ms 4352 KB Output is correct
8 Correct 13 ms 4352 KB Output is correct
9 Correct 12 ms 4352 KB Output is correct
10 Correct 19 ms 4352 KB Output is correct
11 Correct 11 ms 4352 KB Output is correct
12 Correct 13 ms 4480 KB Output is correct
13 Correct 14 ms 4480 KB Output is correct
14 Correct 11 ms 4480 KB Output is correct
15 Correct 11 ms 4480 KB Output is correct
16 Correct 12 ms 4480 KB Output is correct
17 Correct 13 ms 4352 KB Output is correct
18 Correct 12 ms 4352 KB Output is correct
19 Correct 13 ms 4352 KB Output is correct
20 Correct 11 ms 4352 KB Output is correct
21 Correct 12 ms 4480 KB Output is correct
22 Correct 11 ms 4480 KB Output is correct
23 Correct 11 ms 4352 KB Output is correct
24 Correct 11 ms 4352 KB Output is correct
25 Correct 11 ms 4352 KB Output is correct
26 Correct 12 ms 4500 KB Output is correct
27 Correct 13 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 14 ms 4400 KB Output is correct
31 Correct 12 ms 4480 KB Output is correct
32 Correct 11 ms 4480 KB Output is correct
33 Correct 12 ms 4480 KB Output is correct
34 Correct 11 ms 4480 KB Output is correct
35 Correct 11 ms 4480 KB Output is correct
36 Correct 11 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4352 KB Output is correct
2 Correct 13 ms 4352 KB Output is correct
3 Correct 11 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 4480 KB Output is correct
7 Correct 14 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 4480 KB Output is correct
12 Correct 12 ms 4480 KB Output is correct
13 Correct 11 ms 4352 KB Output is correct
14 Correct 11 ms 4480 KB Output is correct
15 Correct 11 ms 4352 KB Output is correct
16 Correct 11 ms 4480 KB Output is correct
17 Correct 11 ms 4480 KB Output is correct
18 Correct 13 ms 4352 KB Output is correct
19 Correct 13 ms 4352 KB Output is correct
20 Correct 11 ms 4352 KB Output is correct
21 Correct 12 ms 4352 KB Output is correct
22 Correct 13 ms 4480 KB Output is correct
23 Correct 13 ms 4352 KB Output is correct
24 Correct 12 ms 4480 KB Output is correct
25 Correct 13 ms 4352 KB Output is correct
26 Correct 12 ms 4224 KB Output is correct
27 Correct 12 ms 4352 KB Output is correct
28 Correct 13 ms 4352 KB Output is correct
29 Correct 13 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 13 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4352 KB Output is correct
2 Correct 13 ms 4432 KB Output is correct
3 Correct 11 ms 4400 KB Output is correct
4 Correct 11 ms 4352 KB Output is correct
5 Correct 14 ms 4608 KB Output is correct
6 Correct 13 ms 4352 KB Output is correct
7 Correct 11 ms 4352 KB Output is correct
8 Correct 12 ms 4352 KB Output is correct
9 Correct 11 ms 4480 KB Output is correct
10 Correct 13 ms 4352 KB Output is correct
11 Correct 11 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 12 ms 4352 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 11 ms 4352 KB Output is correct
20 Correct 11 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 11 ms 4352 KB Output is correct
24 Correct 11 ms 4480 KB Output is correct
25 Correct 11 ms 4480 KB Output is correct
26 Correct 11 ms 4352 KB Output is correct
27 Correct 13 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 11 ms 4352 KB Output is correct
33 Correct 12 ms 4352 KB Output is correct
34 Correct 13 ms 4352 KB Output is correct
35 Correct 12 ms 4384 KB Output is correct
36 Correct 11 ms 4480 KB Output is correct
37 Correct 11 ms 4352 KB Output is correct
38 Correct 13 ms 4352 KB Output is correct
39 Correct 14 ms 4480 KB Output is correct
40 Correct 13 ms 4352 KB Output is correct
41 Correct 12 ms 4352 KB Output is correct
42 Correct 13 ms 4436 KB Output is correct
43 Correct 13 ms 4352 KB Output is correct
44 Correct 12 ms 4352 KB Output is correct
45 Correct 14 ms 4480 KB Output is correct
46 Correct 12 ms 4480 KB Output is correct
47 Correct 12 ms 4352 KB Output is correct
48 Correct 12 ms 4480 KB Output is correct
49 Correct 12 ms 4352 KB Output is correct
50 Correct 12 ms 4480 KB Output is correct
51 Correct 12 ms 4352 KB Output is correct
52 Correct 12 ms 4480 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 11 ms 4480 KB Output is correct
58 Correct 12 ms 4352 KB Output is correct
59 Correct 12 ms 4352 KB Output is correct
60 Correct 14 ms 4480 KB Output is correct
61 Correct 13 ms 4352 KB Output is correct
62 Correct 12 ms 4352 KB Output is correct
63 Correct 11 ms 4480 KB Output is correct
64 Correct 13 ms 4352 KB Output is correct
65 Correct 11 ms 4480 KB Output is correct
66 Correct 12 ms 4352 KB Output is correct
67 Correct 11 ms 4480 KB Output is correct
68 Correct 12 ms 4352 KB Output is correct
69 Correct 11 ms 4352 KB Output is correct
70 Correct 11 ms 4352 KB Output is correct
71 Correct 12 ms 4352 KB Output is correct
72 Correct 12 ms 4352 KB Output is correct
73 Correct 14 ms 4352 KB Output is correct
74 Correct 13 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4352 KB Output is correct
2 Correct 17 ms 4352 KB Output is correct
3 Correct 12 ms 4480 KB Output is correct
4 Correct 11 ms 4352 KB Output is correct
5 Correct 12 ms 4352 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 11 ms 4352 KB Output is correct
8 Correct 11 ms 4352 KB Output is correct
9 Correct 12 ms 4352 KB Output is correct
10 Correct 11 ms 4352 KB Output is correct
11 Correct 11 ms 4352 KB Output is correct
12 Correct 12 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 11 ms 4352 KB Output is correct
16 Correct 13 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 11 ms 4352 KB Output is correct
20 Correct 11 ms 4480 KB Output is correct
21 Correct 11 ms 4480 KB Output is correct
22 Correct 11 ms 4352 KB Output is correct
23 Correct 11 ms 4352 KB Output is correct
24 Correct 11 ms 4480 KB Output is correct
25 Correct 12 ms 4352 KB Output is correct
26 Correct 11 ms 4352 KB Output is correct
27 Correct 13 ms 4352 KB Output is correct
28 Correct 13 ms 4480 KB Output is correct
29 Correct 12 ms 4352 KB Output is correct
30 Correct 14 ms 4480 KB Output is correct
31 Correct 12 ms 4352 KB Output is correct
32 Correct 12 ms 4480 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 4480 KB Output is correct
37 Correct 12 ms 4352 KB Output is correct
38 Correct 13 ms 4352 KB Output is correct
39 Correct 12 ms 4352 KB Output is correct
40 Correct 14 ms 4352 KB Output is correct
41 Correct 13 ms 4480 KB Output is correct
42 Correct 12 ms 4480 KB Output is correct
43 Correct 13 ms 4608 KB Output is correct
44 Correct 13 ms 4480 KB Output is correct
45 Correct 13 ms 4352 KB Output is correct
46 Correct 13 ms 4352 KB Output is correct
47 Correct 13 ms 4352 KB Output is correct
48 Correct 13 ms 4352 KB Output is correct
49 Correct 13 ms 4352 KB Output is correct
50 Correct 13 ms 4352 KB Output is correct
51 Correct 12 ms 4352 KB Output is correct
52 Correct 21 ms 4480 KB Output is correct
53 Correct 25 ms 4480 KB Output is correct
54 Correct 36 ms 4480 KB Output is correct
55 Correct 37 ms 4480 KB Output is correct
56 Correct 107 ms 4600 KB Output is correct
57 Correct 94 ms 4492 KB Output is correct
58 Correct 91 ms 4600 KB Output is correct
59 Correct 88 ms 4480 KB Output is correct
60 Correct 99 ms 4480 KB Output is correct
61 Correct 12 ms 4352 KB Output is correct
62 Correct 27 ms 4480 KB Output is correct
63 Correct 36 ms 4480 KB Output is correct
64 Correct 36 ms 4480 KB Output is correct
65 Correct 54 ms 4480 KB Output is correct
66 Correct 76 ms 4480 KB Output is correct
67 Correct 100 ms 4600 KB Output is correct
68 Correct 99 ms 4480 KB Output is correct
69 Correct 99 ms 4480 KB Output is correct