이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 2005;
ll n, A, B;
ll arr[mxn];
ll pre[mxn];
ll dp[mxn][mxn];
ll inf = 0;
ll solve(int pos, int k)
{
if(pos>n)
{
if(k>=A && k<=B) return 0;
return inf;
}
if(dp[pos][k]!=-1) return dp[pos][k];
ll ret = inf;
//cout << ret << '\n';
for(int i = pos; i <= n; i++)
{
ll tmp = solve(i+1, k+1);
if(tmp==inf) ret = tmp;
else ret = min(ret, tmp|(pre[i]-pre[pos-1]));
}
//cout << ret << '\n';
return dp[pos][k] = ret;
}
int main()
{
//cout << inf << '\n';
cin >> n >> A >> B;
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int i = 1; i <= n; i++) pre[i] = pre[i-1]+arr[i];
inf = pre[n]+10;
memset(dp, -1, sizeof dp);
ll ans = solve(1, 0);
cout << ans << '\n';
return 0;
}
# | 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... |