Submission #317834

# Submission time Handle Problem Language Result Execution time Memory
317834 2020-10-30T13:19:47 Z ali_tavakoli Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 384 KB
//In the name of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define al(x) x.begin(), x.end()

const int N = 105, M = 40, inf = 1e9 + 5;

int n, a, b, y[N];

void s5()
{
    int N2 = 2005;
    int dp[N2];
    ll ans = (1LL << M) - 1;
    for(int i = M - 1; i >= 0; i--)
    {
        for(int j = 0; j < N2; j++)
            dp[j] = inf;
        
        dp[0] = 1;
        for(int j = 0; j <= n; j++)
        {
            ll sum = 0;
            for(int pos = j + 1; pos <= n; pos++)
            {
                sum += y[pos - 1];
                if((sum | ans) > ans|| (1LL << i) & sum)
                    continue;
                dp[pos] = min(dp[pos], dp[j] + 1);
            }
        }
        
        if(dp[n] <= b)
            ans -= (1LL << i);
    }

    cout << ans << endl;
}

int main()
{
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++)
        cin >> y[i];
    if(a == 1)
    {
        s5();
        return 0;
    }

    bool dp[N][N];
    ll ans = (1LL << M) - 1;
    for(int i = M - 1; i >= 0; i--)
    {
        for(int j = 0; j < N; j++)
            for(int k = 0; k < N; k++)
                dp[j][k] = 0;
        
        dp[0][0] = 1;
        for(int j = 0; j <= n; j++)
            for(int k = 0; k < N; k++)
            {
                ll sum = 0;
                for(int pos = j + 1; pos <= n; pos++)
                {
                    sum += y[pos - 1];
                    if((sum | ans) > ans|| (1LL << i) & sum)
                        continue;
                    dp[pos][k + 1] |= dp[j][k];
                }
            }
        
        for(int k = a; k <= b; k++)
            if(dp[n][k])
            {
                ans -= (1LL << i);
                break;
            }
    }

    cout << ans << endl;
    
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -