Submission #1167265

#TimeUsernameProblemLanguageResultExecution timeMemory
1167265MuhammetBali Sculptures (APIO15_sculpture)C++17
100 / 100
61 ms460 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define ll long long #define SZ(s) (int)s.size() const int N = 1e2 + 5; int n, A, B, a[20005], dp[N][N], dp1[20005]; ll ans; bool check(ll x) { memset (dp, -1, sizeof dp); dp[0][0] = 1; for(int i = 1; i <= n; i++) { ll s = 0; for(int j = i; j > 0; j--) { s += a[j]; if((s | x) == x) { for(int k = 0; k < B; k++) { if(dp[j-1][k] == 1) dp[i][k+1] = 1; } } } } for(int k = A; k <= B; k++) { if(dp[n][k] == 1) return true; } return false; } bool chek(ll x) { for(int i = 1; i <= n; i++) { dp1[i] = 1e9; } for(int i = 1; i <= n; i++) { ll s = 0; for(int j = i; j > 0; j--) { s += a[j]; if((s | x) == x) { dp1[i] = min(dp1[i], dp1[j-1] + 1); } } } return (dp1[n] <= B); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> A >> B; for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int x = 40; x >= 0; x--) { ll k = ans; k += ((1LL<<x)-1); if(A == 1) { if(!chek(k)) ans += (1LL<<x); } else { if(!check(k)) ans += (1LL<<x); } } cout << ans; return 0; }
#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...