Submission #317487

#TimeUsernameProblemLanguageResultExecution timeMemory
317487Return_0Bali Sculptures (APIO15_sculpture)C++17
100 / 100
130 ms4472 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx,avx2,fma")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef LOCAL
#define dbg(x) cout<< #x << " : " << x << endl
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1);
#else
#define dbg(x) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< x << endl, 0
#define cl const ll
#define fr first
#define sc second
#define mid ((l + r) / 2)
#define All(x) (x).begin(), (x).end()

const long long inf = 1e18;
cl mod = 1e9 + 7, MOD = 998244353;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << '(' << a.first << ", " << a.second << ')';    }
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
    if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e3 + 7;

ll a [N], dp1 [N], n, A, B, ans;
bool dp2 [N][N];

bool check () {
    if (A == 1) {
        memset(dp1, 61, sizeof dp1);
		ll sum;
	    dp1[0] = 0;
	    for (ll i = 1; i <= n; i++) {
		    sum = 0;
            for (ll j = i; j; j--) {
			    sum += a[j];
			    if ((sum | ans) == ans) dp1[i] = min(dp1[j-1] + 1, dp1[i]);
	        }
	    }
	    
        return (dp1[n] <= B);
    }

    else {
        memset(dp2, false, sizeof dp2);
        ll sum;
        dp2[0][0] = true;
        
        for (ll j = 1; j <= B; j++) {
            for (ll i = 1; i <= n; i++) {
                sum = 0;
                for (ll k = i; k; k--) {
                    sum += a[k];
                    if ((sum | ans) == ans) dp2[i][j] |= dp2[k-1][j-1];
                }
            }
        }

        for (ll i = A; i <= B; i++) if (dp2[n][i])   return true;
        return false;
    }
}

int main ()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n >> A >> B;
    input(1, n, a);

    ans = (1LL << 45) - 1LL;
    for (ll i = 44; ~i; i--) {
        ans ^= (1LL << i);
        if (!check())   ans ^= (1LL << i);
    }

    cout<< ans << endl;

    // cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}
/*
6 1 3
8 1 2 1 5 4

*/

Compilation message (stderr)

sculpture.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
sculpture.cpp:39:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   39 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |     ^~
sculpture.cpp:39:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   39 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |                                    ^~~~
#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...