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 <bits/stdc++.h>
#include "jelly.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int MAX = 2005;
const int INF = 0x3f3f3f3f;
int n, a[MAX], b[MAX];
bool cmp(int i, int j){ return a[i] > a[j]; }
int find_maximum_unique(int x, int y, vector<int> _a, vector<int> _b) {
n = _a.size();
bool aux = true;
bool aux2 = true;
for(int i = 1; i <= n; i++){
a[i] = _a[i - 1];
b[i] = _b[i - 1];
aux &= (a[i] == b[i]);
if(i > 1) aux2 &= (b[i] == b[i - 1]);
}
if(aux){
x += y; y = 0;
vector<vector<int>> dp(n + 1, vector<int>(x + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 0; j <= x; j++){
dp[i][j] = dp[i - 1][j];
if(j >= a[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + 1);
}
}
return dp[n][x];
}
if(aux2){
vector<int> t;
for(int i = 1; i <= n; i++)
t.push_back(i);
sort(t.begin(), t.end(), cmp);
int i = 0, resp = 0;
while(y - b[t[i]] >= 0 && i < n){
y -= b[t[i]];
a[t[i]] = INF;
resp++; i++;
}
vector<vector<int>> dp(n + 1, vector<int>(x + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 0; j <= x; j++){
dp[i][j] = dp[i - 1][j];
if(j >= a[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + 1);
}
}
return dp[n][x] + resp;
}
vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(x + 1, vector<int>(y + 1, 0)));
for(int i = 1; i <= n; i++){
for(int j = 0; j <= x; j++){
for(int k = 0; k <= y; k++){
int cur = dp[i - 1][j][k];
if(j >= a[i]) cur = max(cur, dp[i - 1][j - a[i]][k] + 1);
if(k >= b[i]) cur = max(cur, dp[i - 1][j][k - b[i]] + 1);
dp[i][j][k] = cur;
}
}
}
return dp[n][x][y];
}
# | 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... |