This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2e3+100;
int N, A, B, a[MAXN];
map<pair<int, pair<int, ll>>, ll> memo;
ll f(int gruppo, int i, ll ans){
ll cur_ans = (1ll<<60)-1;
if(i == N){
if(gruppo - 1 > B || gruppo - 1 < A)
return cur_ans;
else
return ans;
}
if(gruppo + (N - i) < A || gruppo > B){
return cur_ans;
}
pair<int, pair<int, ll>> st = {gruppo, {i, ans}};
if(memo.count(st)){
return memo[st];
}
ll s = 0;
for(int j = i; j < N; j++){
s += a[j];
cur_ans = min(cur_ans, f(gruppo+1, j+1, (s|ans)));
}
memo[st] = cur_ans;
return cur_ans;
}
void solve(){
cin >> N >> A >> B;
for(int i = 0; i < N; i++){
cin >> a[i];
}
cout << f(1, 0, 0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
sculpture.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization("O3")
|
sculpture.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization("unroll-loops")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |