Submission #527590

# Submission time Handle Problem Language Result Execution time Memory
527590 2022-02-17T17:40:31 Z SlavicG Bali Sculptures (APIO15_sculpture) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 2005;
ll p[N];
ll sum(int l, int r) {
    return p[r] - (l ? p[l - 1] : 0);
}

//dp[index][OR][number of subarrays] = 1 if possible to obtain such partition

ll dp[N][N];
ll excluded;

bool check(ll k, int n, vector<ll>& a, int A, int B) {
    for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = 0;
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0;j < i; ++j) {
            ll s = sum(j, i - 1);
            if((s & excluded) || (s & (1LL << k))) continue;
            for(int x = 0;x < n; ++x) {
                dp[i][x + 1] |= dp[j][x];
            }
        }
    }
    for(int j = A; j <= B; ++j) {
        if(dp[n][j]) return true;
    }
    return false;
}

bool check2(ll k, int n, vector<ll>& a, int A, int B) {
    for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = INT_MAX;
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0;j < i; ++j) {
            ll s = sum(j, i - 1);
            if((s & excluded) || (s & (1LL << k))) continue;
            dp[i][0] = min(dp[i][0], dp[j][0] + 1]);
        }
    }
    return dp[n] <= B;
}
void solve() { 
    ll n, A, B;
    cin >> n >> A >> B;
    vector<ll> a(n);
    for(int i = 0;i < n; ++i) {
        cin >> a[i];
        p[i] = (i ? p[i - 1] : 0) + a[i];
    }

    if(n <= 100) { 
        ll ans = 0;
        for(ll pw = 62; pw >= 0; --pw) {
            if(check(pw, n, a, A, B)) {
                excluded += (1LL << pw);
            } else {
                ans += (1LL << pw);
            }
        }
        cout << ans << "\n";
    } else {
        ll ans = 0;
        for(ll pw = 62; pw >= 0; --pw) {
            if(check2(pw, n, a, A, B)) {
                excluded += (1LL << pw);
            } else {
                ans += (1LL << pw);
            }
        }
        cout << ans << "\n";
    }
} 
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}

Compilation message

sculpture.cpp: In function 'bool check2(long long int, int, std::vector<long long int>&, int, int)':
sculpture.cpp:49:50: error: expected ')' before ']' token
   49 |             dp[i][0] = min(dp[i][0], dp[j][0] + 1]);
      |                           ~                      ^
      |                                                  )
sculpture.cpp:52:18: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   52 |     return dp[n] <= B;
      |            ~~~~~~^~~~