Submission #107894

#TimeUsernameProblemLanguageResultExecution timeMemory
107894patrikpavic2Bali Sculptures (APIO15_sculpture)C++17
100 / 100
731 ms23288 KiB
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef set < int > si;

const int N = 2050;
const int M = 105;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const int OFF = (1 << LOG);
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll sum[N][N], ans = 0;
int dp[N], A, B, x[N], n, dp2[M][M];

bool check(int k){
    for(int i = 0;i < n;i++){
        dp[i] = INF;
        for(int j = -1;j < i;j++){
            if((sum[j + 1][i] & (~ans)) < (1LL << k))
                dp[i] = min(1 + (j >= 0 ? dp[j] : 0), dp[i]);
        }
    }
    return dp[n - 1] <= B;
}

bool check2(int k){
    memset(dp2, 0, sizeof(dp2));
    for(int i = 0;i < n;i++){
        for(int j = -1;j < i;j++){
            if((sum[j + 1][i] & (~ans)) < (1LL << k)){
                if(j == -1){ dp2[i][1] = 1; continue; }
                for(int k = 1;k <= n;k++){
                    dp2[i][k] |= dp2[j][k - 1];
                }
            }
        }
    }
    for(int t = A;t <= B;t++)
        if(dp2[n - 1][t])
            return 1;
    return 0;
}


int main(){
    scanf("%d%d%d", &n, &A, &B);
    for(int i = 0;i < n;i++)
        scanf("%d", x + i);
    for(int i = 0;i < n;i++){
        ll cur = 0;
        for(int j = i;j < n;j++){
            cur += (ll)x[j];
            sum[i][j] = cur;
        }
    }
    if(n <= 100){
        for(int i = 45; i >= 0;i--)
            if(!check2(i)) ans |= (1LL << i);
        printf("%lld\n", ans);
        return 0;
    }

    for(int i = 45; i >= 0;i--)
        if(!check(i)) ans |= (1LL << i);
    printf("%lld\n", ans);
    return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", x + i);
         ~~~~~^~~~~~~~~~~~~
#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...