Submission #996240

#TimeUsernameProblemLanguageResultExecution timeMemory
996240BaytoroBali Sculptures (APIO15_sculpture)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second #define pb push_back #define int long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } #define ll long long const int N=3e4+5; int n,a,b; const int INF=1e12; int y[N]; bool check(int x){ if(a==1){ vector<int> dp(n+1,INF); dp[0]=0; for(int i=0;i<n;i++){ int sum=0; for(int j=i+1;j<=n;j++){ sum+=y[j]; if((sum|x)==x){ dp[j]=min(dp[j],dp[i]+1); } } } return (dp[n]<=b); } vector<vector<int> > dp(n+1,vector<int>(n+1,0)); dp[0][0]=1; for(int i=0;i<n;i++){ for(int j=0;j<b;j++){ int sum=0; if(dp[i][j]){ for(int k=i+1;k<=n;k++){ sum+=y[k]; if((sum|x)==x) dp[k][j+1]=dp[i][j]; } } } } for(int i=a;i<=b;i++) if(dp[n][i]) return 1; return 0; } /* 6 1 3 8 1 2 1 5 4 */ void solve(){ cin>>n>>a>>b; for(int i=1;i<=n;i++) cin>>y[i]; int ans=(1<<40)-1; for(int i=39;i>=0;i--){ if(check(ans-(1<<i))){ ans-=(1<<i); } } cout<<ans<<endl; } signed main(){ //fopn("paint"); int t=1;//cin>>t; while(t--) solve(); }

Compilation message (stderr)

sculpture.cpp: In function 'void solve()':
sculpture.cpp:57:12: warning: left shift count >= width of type [-Wshift-count-overflow]
   57 |  int ans=(1<<40)-1;
      |           ~^~~~
sculpture.cpp: In function 'void fopn(std::string)':
sculpture.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...