# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108927 | AdrienVannson | Two Dishes (JOI19_dishes) | C++17 | 245 ms | 53204 KiB |
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 <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;
const ll oo = 1ll<<62;
const int NB_MAX_ETAPES = 200*1000 + 42;
struct Etape
{
ll duree;
ll dateMaxRecompense;
ll recompense;
ll sommeAvant = 0;
};
int nbEtapes[2];
Etape etapes[2][NB_MAX_ETAPES];
ll dynamique[2000+1][2000+1];
ll getGainMax (const int iEtape1, const int iEtape2)
{
ll &res = dynamique[iEtape1][iEtape2];
if (res != -oo) {
return res;
}
if (iEtape1 == nbEtapes[0] && iEtape2 == nbEtapes[1]) {
return res = 0;
}
const ll date = etapes[0][iEtape1].sommeAvant + etapes[1][iEtape2].sommeAvant;
if (iEtape1 < nbEtapes[0]) {
ll score = getGainMax(iEtape1+1, iEtape2);
if (date + etapes[0][iEtape1].duree <= etapes[0][iEtape1].dateMaxRecompense) {
score += etapes[0][iEtape1].recompense;
}
res = max(score, res);
}
if (iEtape2 < nbEtapes[1]) {
ll score = getGainMax(iEtape1, iEtape2+1);
if (date + etapes[1][iEtape2].duree <= etapes[1][iEtape2].dateMaxRecompense) {
score += etapes[1][iEtape2].recompense;
}
res = max(score, res);
}
return res;
}
int main ()
{
fill(*dynamique, *dynamique+2001*2001, -oo);
scanf("%d %d", &nbEtapes[0], &nbEtapes[1]);
for (int i=0; i<nbEtapes[0]; i++) {
scanf("%lld %lld %lld", &etapes[0][i].duree, &etapes[0][i].dateMaxRecompense, &etapes[0][i].recompense);
}
for (int i=0; i<nbEtapes[1]; i++) {
scanf("%lld %lld %lld", &etapes[1][i].duree, &etapes[1][i].dateMaxRecompense, &etapes[1][i].recompense);
}
for (int iPlat=0; iPlat<2; iPlat++) {
etapes[iPlat][0].sommeAvant = 0;
for (int i=1; i<=nbEtapes[iPlat]; i++) {
etapes[iPlat][i].sommeAvant = etapes[iPlat][i-1].sommeAvant + etapes[iPlat][i-1].duree;
}
}
if (nbEtapes[0] <= 2000 && nbEtapes[1] <= 2000) {
printf("%lld\n", getGainMax(0, 0));
}
else {
const ll seuilGains = etapes[0][0].dateMaxRecompense;
int iEtape0 = 0;
int iEtape1 = 0;
ll gainActuel = 0;
while (iEtape0 < nbEtapes[0] && etapes[0][iEtape0+1].sommeAvant <= seuilGains) {
gainActuel += etapes[0][iEtape0].recompense;
iEtape0++;
}
while (iEtape1 < nbEtapes[1] && etapes[1][iEtape1+1].sommeAvant <= seuilGains - etapes[0][iEtape0].sommeAvant) {
gainActuel += etapes[1][iEtape1].recompense;
iEtape1++;
}
ll gainMax = gainActuel;
while (iEtape0) {
iEtape0--;
gainActuel -= etapes[0][iEtape0].recompense;
while (iEtape1 < nbEtapes[1] && etapes[1][iEtape1+1].sommeAvant <= seuilGains - etapes[0][iEtape0].sommeAvant) {
gainActuel += etapes[1][iEtape1].recompense;
iEtape1++;
}
// Il ne faut pas pouvoir reprendre l'étape que l'on vient de supprimer
if (etapes[0][iEtape0+1].sommeAvant > seuilGains - etapes[1][iEtape1].sommeAvant) {
gainMax = max(gainActuel, gainMax);
}
}
printf("%lld\n", gainMax);
}
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |