#include <bits/stdc++.h>
using namespace std;
long long int dp(long long int ind,long long int kol,long long int zbr,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 (zbr>=numeric_limits<long long int>::max()/20ll){
return zbr;
}
if (ind==lis.size()){
if (kol<a){
return numeric_limits<long long int>::max()/20ll;
}
if ((zbr|sad)>sad){
return numeric_limits<long long int>::max()/20ll;
}
return zbr;
}
if (mem[ind][kol]!=-1){
return mem[ind][kol]+zbr;
}
long long int najm=dp(ind+1ll,kol,zbr+lis[ind],lis,mem,sad,a,b);
if (kol!=b && (zbr|sad)<=sad && zbr!=0ll){
najm=min(najm,dp(ind+1ll,kol+1ll,lis[ind],lis,mem,sad,a,b));
}
mem[ind][kol]=najm-zbr;
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=0;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=1;
for (int i=0;i<62;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(0,1,0,lis,mem,sad-sadznam,a,b)<numeric_limits<long long int>::max()/20ll){
sad-=sadznam;
}
sadznam/=2ll;
}
cout << sad << "\n";
}
Compilation message
sculpture.cpp: In function 'long long int dp(long long int, 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:9: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]
9 | if (ind==lis.size()){
| ~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
224 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |