답안 #550249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550249 2022-04-17T17:14:24 Z ala2 Bali Sculptures (APIO15_sculpture) C++14
0 / 100
4 ms 5204 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
int n,l,r;
int a[1001000];
int p[1000100];
int suf[1001000];
int dp[55][22][505];
int sum(int i,int j)
{
    return p[j]-p[i]+a[i];
}
vector<int>bit(int x,int y)
{
    vector<int>V;
    for(int i=0;i<=500;i++)
    {
        if((i|x)==y){
            V.push_back(i);
            //cout<<i<<endl;
        }
    }
    return V;
}
bool good(int x)
{
    return x<=r&&x>=l;
}
int f(int i,int k,int x)
{
    //if(i==3&&k==0&&x==10)
   // cout<<i<<" ;;;   "<<k<<endl;;
   if(dp[i][k][x]!=-1)
    return dp[i][k][x];
    if(suf[i]==x&&good(k))
    {
        //cout<<"    "<<i<<"  "<<k<<"   "<<x<<endl;
        return 1;
    }
    if(i==n-1||k>r)
        return 0;
    int mx=0;
    for(int j=i;j<n;j++)
    {
        int y=sum(i,j);
        //y=(y|x);
        vector<int>v=bit(y,x);
        for(auto S:v)
        {
            mx=max(mx,f(j+1,k+1,S));

        }
    }
    return dp[i][k][x]=mx;

}
signed main()
{
    //cout<<(13|8);
    memset(dp,-1,sizeof dp);
    cin>>n>>l>>r;
    for(int i=0;i<n;i++)
        cin>>a[i];
    p[0]=a[0];
    for(int i=1;i<n;i++)
        p[i]=p[i-1]+a[i];
    suf[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        suf[i]=suf[i+1]+a[i];
    }
    for(int i=0;i<=500;i++)
    {
        if(f(0,0,i)){
            cout<<i<<endl;
            return 0;


            }
    }

}

Compilation message

sculpture.cpp: In function 'long long int f(long long int, long long int, long long int)':
sculpture.cpp:38:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   38 |    if(dp[i][k][x]!=-1)
      |    ^~
sculpture.cpp:40:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   40 |     if(suf[i]==x&&good(k))
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Correct 3 ms 5096 KB Output is correct
3 Incorrect 2 ms 5096 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5088 KB Output is correct
3 Incorrect 2 ms 5076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Incorrect 3 ms 5092 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Incorrect 3 ms 5092 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Incorrect 2 ms 5076 KB Output isn't correct
4 Halted 0 ms 0 KB -