Submission #107115

#TimeUsernameProblemLanguageResultExecution timeMemory
107115abilBali Sculptures (APIO15_sculpture)C++14
100 / 100
147 ms512 KiB
#include <bits/stdc++.h> #define mk make_pair #define sc second #define fr first #define pb emplace_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) #define int long long using namespace std; const int inf = (int)1e9 + 7 ; const long long mod = 1e9 + 7; const int N = (int)2007; int n, a, b, pr[N]; bool check(int val){ int dp[N]; memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0] = 0; for(int i = 1;i <= n; i++){ for(int j = 0;j < i; j++){ if(((pr[i] - pr[j]) | val) == val){ dp[i] = min(dp[i],dp[j] + 1); } } } if(dp[n] <= b && dp[n] >= a){ return true; } else{ return false; } } bool check2(int val){ bool dp[n + 1][n + 1]; for(int i = 0;i <= n; i++){ for(int j = 0;j <= n; j++){ dp[i][j] = false; } } dp[0][0] = true; for(int i = 1;i <= n; i++){ for(int j = 0;j < i; j++){ for(int k = 1;k <= i; k++){ if(dp[j][k - 1] && (((pr[i] - pr[j]) | val) == val)){ dp[i][k] = true; } } } } for(int i = a;i <= b; i++){ if(dp[n][i]){ return true; } } return false; } main(){ cin >> n >> a >> b; for(int i = 1;i <= n; i++){ cin >> pr[i]; pr[i] = pr[i - 1] + pr[i]; } int ans = (1ll << 50ll) - 1; for(int i = 49;i >= 0; i--){ if(a == 1){ if(check(ans ^ (1ll << i))){ ans ^= (1ll << i); } } else{ if(check2(ans ^ (1ll << i))){ ans ^= (1ll << i); } } } cout << ans; } /* 6 2 3 8 1 2 1 5 4 */

Compilation message (stderr)

sculpture.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#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...