Submission #404976

#TimeUsernameProblemLanguageResultExecution timeMemory
404976HazemBali Sculptures (APIO15_sculpture)C++14
100 / 100
137 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define LL long long #define F first #define S second #define pii pair<int,int> #define piii pair<pair<int,int>,int> const int N = 2e5+10; const int M = 3e2+10; const LL INF = 1e9; const LL LINF = 2e18; const LL MOD = 1e9+7; const double PI = 3.141592653589793; LL a[N],dp[N]; bool dp1[M][M]; int n,l,r; bool check1(LL val){ dp[0] = 0; for(int i=1;i<=n;i++){ dp[i] = LINF; LL sum = 0; for(int j=i;j>=1;j--){ sum += a[j]; if((sum&val)==sum) dp[i] = min(dp[i],dp[j-1]+1); } } return dp[n]<=r; } bool check2(LL val){ dp1[0][0] = 1; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++){ LL sum = 0; dp1[i][j] = 0; for(int k=i;k>=1;k--){ sum += a[k]; if((sum&val)==sum) dp1[i][j] |= dp1[k-1][j-1]; } } bool q = 0; for(int i=l;i<=r;i++) q |= dp1[n][i]; return q; } int main(){ //freopen("out.txt","w",stdout); scanf("%d%d%d",&n,&l,&r); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); LL ans = (1ll<<45)-1; for(LL i=44;i>=0;i--){ ans ^= 1ll<<i; if(l==1){ if(!check1(ans))ans ^= 1ll<<i; } else if(!check2(ans))ans ^= 1ll<<i; } printf("%lld\n",ans); }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d%d",&n,&l,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
sculpture.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%lld",&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...