이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int oo = INT_MAX;
int n,a,b;
int v[100005];
int sp[100005];
int dp[100005];
bool dp2[105][105];
void solve_1()
{
int val = 0;
for(int bit=60; bit>=0; bit--)
{
for(int i=1; i<=n; i++)
{
dp[i] = oo;
}
for(int i=1; i<=n; i++)
{
for(int j=i-1; j>=0; j--)
{
int sum = sp[i] - sp[j];
if(((val >> bit) | (sum >> bit)) != (val >> bit))
{
continue;
}
dp[i] = min(dp[i],1 + dp[j]);
}
}
if(dp[n] > b)
{
val += (1LL<<bit);
}
}
cout<<val<<'\n';
}
void solve()
{
int val = 0;
for(int bit=60; bit>=0; bit--)
{
dp2[0][0] = true;
for(int i=1; i<=n; i++)
{
for(int nr=1; nr<=b; nr++)
{
dp2[i][nr] = false;
for(int j=i-1; j>=0; j--)
{
int sum = sp[i] - sp[j];
if(((val >> bit) | (sum >> bit)) != (val >> bit))
{
continue;
}
dp2[i][nr] |= dp2[j][nr-1];
}
}
}
bool ok = false;
for(int i=a;i<=b;i++)
{
if(dp2[n][i])
{
ok = true;
}
}
if(!ok)
{
val += (1LL<<bit);
}
}
cout<<val<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n>>a>>b;
for(int i=1; i<=n; i++)
{
cin>>v[i];
sp[i] = sp[i-1] + v[i];
}
if(a==1)
{
solve_1();
return 0;
}
solve();
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... |