Submission #397853

# Submission time Handle Problem Language Result Execution time Memory
397853 2021-05-03T09:46:45 Z juggernaut Bali Sculptures (APIO15_sculpture) C++17
71 / 100
26 ms 336 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int n,l,r,a[2005];
ll ans,pref[2005];
bool check(int a,int b){return(((a>>b)|ans)==ans);}
int main(){
    scanf("%d%d%d",&n,&l,&r);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    if(n<=100){
        for(int bit=45;bit>=0;bit--){
            vector<bitset<2005>>dp(n+5);
            dp[0]=1;
            for(int j=1;j<=n;j++){
                ll sum=0;
                for(int k=j-1;k>=0;k--){
                    sum+=a[k];
                    if(((sum>>(bit+1))|ans)==ans&&!((sum>>bit)&1))dp[j]|=dp[k]<<1;
                }
            }
            bool flag=false;
            for(int i=l;i<=r;i++)flag|=dp[n][i];
            ans<<=1;
            ans|=(!flag);
        }
    }else{
        vector<ll>dp(n+5);
        for(int i=1;i<=n;i++)pref[i]=pref[i-1]+a[i-1];
        for(int bit=45;bit>=0;bit--){
			for(int i=1;i<=n;i++)dp[i]=9e18;
			for(int i=1;i<=n;i++){
				for(int j=0;j<i;j++)if(check(pref[i]-pref[j],bit+1))umin(dp[i],dp[j]+1);
			}
			ans<<=1;
			ans+=(dp[n]>r);
		}
    }
    printf("%lld",ans);
}

Compilation message

sculpture.cpp: In function 'void usaco(std::string)':
sculpture.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d%d%d",&n,&l,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
sculpture.cpp:25:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     for(int i=0;i<n;i++)scanf("%d",&a[i]);
      |                         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 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 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 204 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 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 204 KB Output is correct
36 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 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 2 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 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 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 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 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 3 ms 204 KB Output is correct
30 Correct 4 ms 204 KB Output is correct
31 Correct 5 ms 204 KB Output is correct
32 Correct 5 ms 204 KB Output is correct
33 Correct 6 ms 204 KB Output is correct
34 Correct 5 ms 204 KB Output is correct
35 Correct 5 ms 204 KB Output is correct
36 Correct 5 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 4 ms 204 KB Output is correct
17 Correct 4 ms 204 KB Output is correct
18 Correct 5 ms 204 KB Output is correct
19 Correct 5 ms 204 KB Output is correct
20 Correct 6 ms 204 KB Output is correct
21 Correct 5 ms 204 KB Output is correct
22 Correct 5 ms 204 KB Output is correct
23 Correct 5 ms 204 KB Output is correct
24 Correct 6 ms 204 KB Output is correct
25 Correct 8 ms 312 KB Output is correct
26 Correct 15 ms 320 KB Output is correct
27 Correct 16 ms 324 KB Output is correct
28 Correct 17 ms 328 KB Output is correct
29 Correct 17 ms 204 KB Output is correct
30 Correct 22 ms 328 KB Output is correct
31 Correct 18 ms 328 KB Output is correct
32 Correct 22 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 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 2 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 204 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 2 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 2 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 2 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 204 KB Output is correct
36 Correct 2 ms 204 KB Output is correct
37 Correct 2 ms 204 KB Output is correct
38 Correct 2 ms 204 KB Output is correct
39 Correct 4 ms 308 KB Output is correct
40 Correct 4 ms 204 KB Output is correct
41 Correct 5 ms 204 KB Output is correct
42 Correct 5 ms 312 KB Output is correct
43 Correct 6 ms 204 KB Output is correct
44 Correct 6 ms 204 KB Output is correct
45 Correct 5 ms 308 KB Output is correct
46 Correct 5 ms 204 KB Output is correct
47 Correct 5 ms 204 KB Output is correct
48 Correct 8 ms 204 KB Output is correct
49 Correct 12 ms 320 KB Output is correct
50 Correct 17 ms 204 KB Output is correct
51 Correct 26 ms 204 KB Output is correct
52 Correct 22 ms 332 KB Output is correct
53 Correct 19 ms 204 KB Output is correct
54 Correct 18 ms 332 KB Output is correct
55 Correct 18 ms 328 KB Output is correct
56 Correct 4 ms 204 KB Output is correct
57 Correct 5 ms 204 KB Output is correct
58 Correct 6 ms 204 KB Output is correct
59 Correct 7 ms 204 KB Output is correct
60 Correct 7 ms 204 KB Output is correct
61 Correct 6 ms 208 KB Output is correct
62 Correct 8 ms 204 KB Output is correct
63 Correct 8 ms 204 KB Output is correct
64 Correct 16 ms 320 KB Output is correct
65 Correct 3 ms 204 KB Output is correct
66 Correct 4 ms 204 KB Output is correct
67 Correct 5 ms 328 KB Output is correct
68 Correct 6 ms 204 KB Output is correct
69 Correct 7 ms 332 KB Output is correct
70 Correct 7 ms 204 KB Output is correct
71 Correct 7 ms 204 KB Output is correct
72 Correct 10 ms 204 KB Output is correct
73 Correct 9 ms 324 KB Output is correct
74 Correct 10 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 204 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 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 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 4 ms 204 KB Output is correct
27 Correct 4 ms 204 KB Output is correct
28 Correct 5 ms 328 KB Output is correct
29 Correct 5 ms 312 KB Output is correct
30 Correct 6 ms 204 KB Output is correct
31 Correct 6 ms 204 KB Output is correct
32 Correct 6 ms 204 KB Output is correct
33 Correct 5 ms 204 KB Output is correct
34 Correct 5 ms 204 KB Output is correct
35 Correct 9 ms 204 KB Output is correct
36 Correct 12 ms 316 KB Output is correct
37 Correct 14 ms 320 KB Output is correct
38 Correct 19 ms 324 KB Output is correct
39 Correct 18 ms 332 KB Output is correct
40 Correct 20 ms 204 KB Output is correct
41 Correct 22 ms 204 KB Output is correct
42 Correct 18 ms 204 KB Output is correct
43 Correct 3 ms 204 KB Output is correct
44 Correct 5 ms 324 KB Output is correct
45 Correct 6 ms 204 KB Output is correct
46 Correct 9 ms 204 KB Output is correct
47 Correct 6 ms 332 KB Output is correct
48 Correct 8 ms 332 KB Output is correct
49 Correct 9 ms 212 KB Output is correct
50 Correct 8 ms 332 KB Output is correct
51 Incorrect 1 ms 204 KB Output isn't correct
52 Halted 0 ms 0 KB -