Submission #397856

#TimeUsernameProblemLanguageResultExecution timeMemory
397856juggernautBali Sculptures (APIO15_sculpture)C++17
71 / 100
23 ms336 KiB
#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]=2e9; for(int i=1;i<=n;i++){ for(int j=i-1;j>=0;j--)if(check(pref[i]-pref[j],bit))umin(dp[i],dp[j]+1); } ans+=(dp[n]>r); ans<<=1; } ans>>=1; } printf("%lld",ans); }

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...