Submission #739483

# Submission time Handle Problem Language Result Execution time Memory
739483 2023-05-10T14:13:43 Z Username4132 Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 340 KB
#include<iostream>
#include<vector>
#include<random>
#include<algorithm>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)

const int MAXN=2010, INF=1000000000;
int n, A, B, arr[MAXN], jump[MAXN][MAXN], dp1[MAXN];

bool test(ll bit){
    forn(i, n){
        ll sum=0;
        forsn(j, i+1, n+1){
            sum+=arr[j-1];
            jump[i][j]=((sum|bit)==bit);
        }
    }
    if(A==1){
        dp1[n]=0;
        dforn(i, n){
            dp1[i]=INF;
            forsn(j, i+1, n+1) if(jump[i][j]) dp1[i]=min(dp1[i], dp1[j]+1);
        }
        return dp1[0]<=B;
    }    
    return false;
}

int main(){
    scanf("%d %d %d", &n, &A, &B);
    forn(i, n) scanf("%d", &arr[i]);
    ll lo=0, hi=(1LL<<32)-1;
    while(hi-lo>1){
        int mid=(hi+lo)>>1;
        if(test(mid)) hi=mid;
        else lo=mid;
    }
    cout << hi << "\n";
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d %d", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:35:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     forn(i, n) scanf("%d", &arr[i]);
      |                ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -