This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "jelly.h"
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <fstream>
using namespace std;
vector<vector<vector<int> > >dp;
int maxi(int x, int y, std::vector<int> a, std::vector<int> b,int nodo){
if(nodo==a.size()||(x==0 && y==0))return 0;
int &ans=dp[nodo][x][y];
if(ans !=-1)return ans;
if(a[nodo]<=x && b[nodo]<=y){
return dp[nodo][x][y]=max(maxi(x,y,a,b,nodo+1),max(maxi(x-a[nodo],y,a,b,nodo+1)+1,maxi(x,y-b[nodo],a,b,nodo+1)+1));
}
else if(a[nodo]<=x){
return dp[nodo][x][y]=max(maxi(x,y,a,b,nodo+1),maxi(x-a[nodo],y,a,b,nodo+1)+1);
}
else if(b[nodo]<=y){
return dp[nodo][x][y]=max(maxi(x,y,a,b,nodo+1),maxi(x,y-b[nodo],a,b,nodo+1)+1);
}
else{
return dp[nodo][x][y]=maxi(x,y,a,b,nodo+1);
}
}
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int n = a.size();
if(y!=0){
vector<int>j(y+x,-1);
vector<vector<int> > g;
for(int i=0;i<x+y;i++)g.push_back(j);
for(int i=0;i<n;i++)dp.push_back(g);
return maxi(x,y,a,b,0);
}
else{
sort(a.begin(),a.end());
int m=0;
for(int i=0;i<n;i++){
if(a[i]<=x){
m++;
x-=a[i];
}
else{
break;
}
}
return m;
}
}
Compilation message (stderr)
jelly.cpp: In function 'int maxi(int, int, std::vector<int>, std::vector<int>, int)':
jelly.cpp:16:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if(nodo==a.size()||(x==0 && y==0))return 0;
| ~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |