Submission #766745

# Submission time Handle Problem Language Result Execution time Memory
766745 2023-06-26T06:13:40 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<bool>>& 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]){
        return true;
    }
    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;
}  

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);                 
    }
    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<bool>> mem=vector<vector<bool>>(n+5ll,vector<bool>(b+5ll,0));
        if (dp(0ll,1ll,lis,mem,sad-sadznam,a,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<bool> >&, 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++){
      |                              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 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 212 KB Output is correct
3 Incorrect 1 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 212 KB Output is correct
3 Incorrect 1 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 212 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 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -