Submission #766769

# Submission time Handle Problem Language Result Execution time Memory
766769 2023-06-26T07:10:48 Z ivopav Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

bool dp(long long int ind,long long int kol,const vector<long long int>& lis,vector<vector<long long int>>& mem,long long int sad,long long int a,long long int b){
   // cout << sad << " " << ind << " " << kol << " " << zbr << "\n";
    if (ind==lis.size()){
        if (kol<a){
            return false;
        }
        return true;
    }
    if (mem[ind][kol]!=-1){
        return mem[ind][kol];
    }
    if (kol==b){
        return false;
    }
    //long long int najm=dp(ind+1ll,kol,zbr+lis[ind],lis,mem,sad,a,b);
    long long int zbr=0ll;
    bool najm=false;
    for (long long int i=ind;i<lis.size();i++){
        zbr+=lis[i];
        if ((zbr|sad)==sad){
            najm=najm||dp(i+1ll,kol+1ll,lis,mem,sad,a,b);
        }
    }
    mem[ind][kol]=najm;
    return najm;
}

long long int dp2(long long int ind,long long int najb,const vector<long long int>& lis,vector<long long int>& mem,long long int sad,long long int a,long long int b){
   // cout << sad << " " << ind << " " << najb << "\n";
    if (ind==lis.size()){
        return najb;
    }
    if (mem[ind]!=-1){
        return mem[ind]+najb;
    }
    //long long int najm=dp(ind+1ll,kol,zbr+lis[ind],lis,mem,sad,a,b);
    long long int zbr=0ll;
    long long int najm=numeric_limits<long long int>::max()/5;
    for (long long int i=ind;i<lis.size();i++){
        zbr+=lis[i];
       // cout << ind << " "  << i << " " << zbr << " " << sad << "a\n";
        if ((zbr|sad)==sad){
     //       cout << "a\n";
            najm=min(najm,dp2(i+1ll,najb+1ll,lis,mem,sad,a,b));
        }
    }
    mem[ind]=najm-najb;
   // cout << najm << "\n";
    return najm; 
}

int main(){
    
    long long int n;
    long long int a;
    long long int b;
    cin >> n >> a >> b; 
    vector<long long int> lis={};
    for (long long int i=0ll;i<n;i++){
        long long int unos;
        cin >> unos;
        lis.push_back(unos);                 
    }
    if (a>1){

        long long int sad=numeric_limits<long long int>::max();
        long long int sadznam=1ll;
        for (long long int i=0ll;i<62ll;i++){
            sadznam*=2ll;
        }
        while (sadznam>0){
            vector <vector<long long int>> mem=vector<vector<long long int>>(n+5ll,vector<long long int>(b+5ll,-1));
            if (dp(0ll,0ll,lis,mem,sad-sadznam,a,b)){
                sad-=sadznam;
            }
            sadznam/=2ll;
        }
      //  cout << sad << "\n";
    }
    else {
        long long int sad=numeric_limits<long long int>::max();
        long long int sadznam=1ll;
        for (long long int i=0ll;i<62ll;i++){
            sadznam*=2ll;
        }
        while (sadznam>0){
            vector<long long int> mem=vector<long long int>(n+5ll,-1);
            if (dp2(0ll,0ll,lis,mem,sad-sadznam,a,b)<=b){
                sad-=sadznam;
            }
            sadznam/=2ll;
        }
    //    cout << sad << "\n";
    }
}

Compilation message

sculpture.cpp: In function 'bool dp(long long int, long long int, const std::vector<long long int>&, std::vector<std::vector<long long int> >&, long long int, long long int, long long int)':
sculpture.cpp:6:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     if (ind==lis.size()){
      |         ~~~^~~~~~~~~~~~
sculpture.cpp:21:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (long long int i=ind;i<lis.size();i++){
      |                              ~^~~~~~~~~~~
sculpture.cpp: In function 'long long int dp2(long long int, long long int, const std::vector<long long int>&, std::vector<long long int>&, long long int, long long int, long long int)':
sculpture.cpp:33:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (ind==lis.size()){
      |         ~~~^~~~~~~~~~~~
sculpture.cpp:42:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (long long int i=ind;i<lis.size();i++){
      |                              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -