Submission #91577

#TimeUsernameProblemLanguageResultExecution timeMemory
91577MercenaryBali Sculptures (APIO15_sculpture)C++11
100 / 100
76 ms1932 KiB
#include<bits/stdc++.h>

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn1 = 105;
const int maxn2 = 2e3 + 5;
int n , a , b , y[maxn2];
ll s[maxn2];

void enter()
{
    cin >> n >> a >> b;
    for(int i = 1 ; i <= n ; ++i){
        cin >> y[i];
        s[i] = s[i - 1] + y[i];
    }
}

ll get(int i , int j)
{
    return s[j] - s[i - 1];
}

bool ok(ll x , ll y)
{
    return !(x & y);
}

struct Sub1
{
    bool f[maxn1][maxn1];
    // f(i,j) chon den thg i va dk j nhom
    void init(){memset(f,0,sizeof f / sizeof(f[0][0]));}
    bool can(ll need)
    {
        f[0][0] = 1;
        for(int i = 1 ; i <= n ; ++i)
        {
            for(int j = 1 ; j <= b ; ++j)
            {
                for(int t = i ; t >= 1 && !f[i][j] ; --t)
                    if(ok(get(t,i),need))f[i][j] |= f[t - 1][j - 1];
            }
        }
        for(int i = a ; i <= b ; ++i)if(f[n][i])return 1;
        return 0;
    }
}Sub1;

struct Sub2
{
    const int inf = 1e9;
    int f[maxn2];
    void init(){for(int i = 1 ; i <= n ; ++i)f[i] = inf;}
    bool can(ll need)
    {
        for(int i = 1 ; i <= n ; ++i)
            for(int t = i ; t >= 1 ; --t)
                if(ok(get(t,i),need))f[i] = min(f[i] , f[t - 1] + 1);
        return f[n] <= b;
    }
}Sub2;

void solve()
{
    ll res = 0;
    for(int i = 40 ; i >= 0 ; --i)
    {
        if(a == 1)
        {
            Sub2.init();
            if(Sub2.can(res | (1ll << i)))res |=  (1ll << i);
        }
        else
        {
            Sub1.init();
            if(Sub1.can(res | (1ll << i)))res |=  (1ll << i);
        }
    }
    cout << ((~res) & ((1ll << 41) - 1));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    enter();
    solve();
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:91:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
sculpture.cpp:91:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...