# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223654 | MODDI | Bali Sculptures (APIO15_sculpture) | C++14 | 107 ms | 4608 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e3+42;
int n,a,b,inp[nmax];
long long pref[nmax];
long long current;
bool possible;
bool been[nmax][nmax];
void dfs(int groups,int last_end)
{
if(possible)return;
if(groups>b)return;
if(last_end==n)
{
if(groups>=a)possible=1;
return;
}
if(been[groups][last_end])return;
been[groups][last_end]=1;
if(((pref[n]-pref[last_end])¤t)==(pref[n]-pref[last_end]))dfs(groups+1,n);
for(int j=last_end+1;j<n;j++)
{
long long sum=pref[j]-pref[last_end];
if((current&sum)==sum)dfs(groups+1,j);
}
}
int dp[nmax];
void special()
{
dp[0]=0;
for(int i=1;i<=n;i++)
{
dp[i]=1e9;
for(int j=i;j>=1;j--)
{
long long sum=pref[i]-pref[j-1];
if((sum¤t)==sum)dp[i]=min(dp[i],dp[j-1]+1);
}
}
//for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
possible=(dp[n]<=b);
}
bool can(long long to_test)
{
current=to_test;
memset(been,0,sizeof(been));
possible=0;
if(a==1)special();
else dfs(0,0);
return possible;
}
int main()
{
scanf("%i%i%i",&n,&a,&b);
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
for(int i=1;i<=n;i++)pref[i]=pref[i-1]+inp[i];
long long output=(1LL<<41)-1;
for(int i=40;i>=0;i--)
if(can(output-(1LL<<i)))output=output-(1LL<<i);
printf("%lld\n",output);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |