# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
108927 | 2019-05-02T21:27:31 Z | AdrienVannson | Two Dishes (JOI19_dishes) | C++17 | 245 ms | 53204 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 221 ms | 50296 KB | Output is correct |
2 | Correct | 213 ms | 50276 KB | Output is correct |
3 | Correct | 243 ms | 53204 KB | Output is correct |
4 | Correct | 210 ms | 52852 KB | Output is correct |
5 | Correct | 40 ms | 44156 KB | Output is correct |
6 | Correct | 222 ms | 52472 KB | Output is correct |
7 | Correct | 132 ms | 50936 KB | Output is correct |
8 | Correct | 130 ms | 51132 KB | Output is correct |
9 | Correct | 245 ms | 52600 KB | Output is correct |
10 | Correct | 154 ms | 51576 KB | Output is correct |
11 | Correct | 165 ms | 51960 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 44152 KB | Output is correct |
2 | Correct | 34 ms | 44152 KB | Output is correct |
3 | Correct | 36 ms | 44152 KB | Output is correct |
4 | Correct | 36 ms | 44244 KB | Output is correct |
5 | Correct | 35 ms | 44152 KB | Output is correct |
6 | Correct | 34 ms | 44152 KB | Output is correct |
7 | Correct | 42 ms | 44152 KB | Output is correct |
8 | Correct | 33 ms | 44152 KB | Output is correct |
9 | Correct | 34 ms | 44280 KB | Output is correct |
10 | Correct | 33 ms | 44160 KB | Output is correct |
11 | Correct | 34 ms | 44152 KB | Output is correct |
12 | Correct | 37 ms | 44152 KB | Output is correct |
13 | Correct | 35 ms | 44152 KB | Output is correct |
14 | Correct | 33 ms | 44160 KB | Output is correct |
15 | Correct | 32 ms | 44152 KB | Output is correct |
16 | Correct | 34 ms | 44024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 44152 KB | Output is correct |
2 | Correct | 34 ms | 44152 KB | Output is correct |
3 | Correct | 36 ms | 44152 KB | Output is correct |
4 | Correct | 36 ms | 44244 KB | Output is correct |
5 | Correct | 35 ms | 44152 KB | Output is correct |
6 | Correct | 34 ms | 44152 KB | Output is correct |
7 | Correct | 42 ms | 44152 KB | Output is correct |
8 | Correct | 33 ms | 44152 KB | Output is correct |
9 | Correct | 34 ms | 44280 KB | Output is correct |
10 | Correct | 33 ms | 44160 KB | Output is correct |
11 | Correct | 34 ms | 44152 KB | Output is correct |
12 | Correct | 37 ms | 44152 KB | Output is correct |
13 | Correct | 35 ms | 44152 KB | Output is correct |
14 | Correct | 33 ms | 44160 KB | Output is correct |
15 | Correct | 32 ms | 44152 KB | Output is correct |
16 | Correct | 34 ms | 44024 KB | Output is correct |
17 | Correct | 90 ms | 44664 KB | Output is correct |
18 | Correct | 113 ms | 44664 KB | Output is correct |
19 | Correct | 95 ms | 44536 KB | Output is correct |
20 | Correct | 84 ms | 44508 KB | Output is correct |
21 | Correct | 101 ms | 44536 KB | Output is correct |
22 | Correct | 91 ms | 44536 KB | Output is correct |
23 | Correct | 93 ms | 44536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 44152 KB | Output is correct |
2 | Correct | 34 ms | 44152 KB | Output is correct |
3 | Correct | 36 ms | 44152 KB | Output is correct |
4 | Correct | 36 ms | 44244 KB | Output is correct |
5 | Correct | 35 ms | 44152 KB | Output is correct |
6 | Correct | 34 ms | 44152 KB | Output is correct |
7 | Correct | 42 ms | 44152 KB | Output is correct |
8 | Correct | 33 ms | 44152 KB | Output is correct |
9 | Correct | 34 ms | 44280 KB | Output is correct |
10 | Correct | 33 ms | 44160 KB | Output is correct |
11 | Correct | 34 ms | 44152 KB | Output is correct |
12 | Correct | 37 ms | 44152 KB | Output is correct |
13 | Correct | 35 ms | 44152 KB | Output is correct |
14 | Correct | 33 ms | 44160 KB | Output is correct |
15 | Correct | 32 ms | 44152 KB | Output is correct |
16 | Correct | 34 ms | 44024 KB | Output is correct |
17 | Correct | 90 ms | 44664 KB | Output is correct |
18 | Correct | 113 ms | 44664 KB | Output is correct |
19 | Correct | 95 ms | 44536 KB | Output is correct |
20 | Correct | 84 ms | 44508 KB | Output is correct |
21 | Correct | 101 ms | 44536 KB | Output is correct |
22 | Correct | 91 ms | 44536 KB | Output is correct |
23 | Correct | 93 ms | 44536 KB | Output is correct |
24 | Incorrect | 223 ms | 53044 KB | Output isn't correct |
25 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 44152 KB | Output is correct |
2 | Correct | 34 ms | 44152 KB | Output is correct |
3 | Correct | 36 ms | 44152 KB | Output is correct |
4 | Correct | 36 ms | 44244 KB | Output is correct |
5 | Correct | 35 ms | 44152 KB | Output is correct |
6 | Correct | 34 ms | 44152 KB | Output is correct |
7 | Correct | 42 ms | 44152 KB | Output is correct |
8 | Correct | 33 ms | 44152 KB | Output is correct |
9 | Correct | 34 ms | 44280 KB | Output is correct |
10 | Correct | 33 ms | 44160 KB | Output is correct |
11 | Correct | 34 ms | 44152 KB | Output is correct |
12 | Correct | 37 ms | 44152 KB | Output is correct |
13 | Correct | 35 ms | 44152 KB | Output is correct |
14 | Correct | 33 ms | 44160 KB | Output is correct |
15 | Correct | 32 ms | 44152 KB | Output is correct |
16 | Correct | 34 ms | 44024 KB | Output is correct |
17 | Correct | 90 ms | 44664 KB | Output is correct |
18 | Correct | 113 ms | 44664 KB | Output is correct |
19 | Correct | 95 ms | 44536 KB | Output is correct |
20 | Correct | 84 ms | 44508 KB | Output is correct |
21 | Correct | 101 ms | 44536 KB | Output is correct |
22 | Correct | 91 ms | 44536 KB | Output is correct |
23 | Correct | 93 ms | 44536 KB | Output is correct |
24 | Incorrect | 223 ms | 53044 KB | Output isn't correct |
25 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 44152 KB | Output is correct |
2 | Correct | 34 ms | 44152 KB | Output is correct |
3 | Correct | 36 ms | 44152 KB | Output is correct |
4 | Correct | 36 ms | 44244 KB | Output is correct |
5 | Correct | 35 ms | 44152 KB | Output is correct |
6 | Correct | 34 ms | 44152 KB | Output is correct |
7 | Correct | 42 ms | 44152 KB | Output is correct |
8 | Correct | 33 ms | 44152 KB | Output is correct |
9 | Correct | 34 ms | 44280 KB | Output is correct |
10 | Correct | 33 ms | 44160 KB | Output is correct |
11 | Correct | 34 ms | 44152 KB | Output is correct |
12 | Correct | 37 ms | 44152 KB | Output is correct |
13 | Correct | 35 ms | 44152 KB | Output is correct |
14 | Correct | 33 ms | 44160 KB | Output is correct |
15 | Correct | 32 ms | 44152 KB | Output is correct |
16 | Correct | 34 ms | 44024 KB | Output is correct |
17 | Correct | 90 ms | 44664 KB | Output is correct |
18 | Correct | 113 ms | 44664 KB | Output is correct |
19 | Correct | 95 ms | 44536 KB | Output is correct |
20 | Correct | 84 ms | 44508 KB | Output is correct |
21 | Correct | 101 ms | 44536 KB | Output is correct |
22 | Correct | 91 ms | 44536 KB | Output is correct |
23 | Correct | 93 ms | 44536 KB | Output is correct |
24 | Incorrect | 223 ms | 53044 KB | Output isn't correct |
25 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 221 ms | 50296 KB | Output is correct |
2 | Correct | 213 ms | 50276 KB | Output is correct |
3 | Correct | 243 ms | 53204 KB | Output is correct |
4 | Correct | 210 ms | 52852 KB | Output is correct |
5 | Correct | 40 ms | 44156 KB | Output is correct |
6 | Correct | 222 ms | 52472 KB | Output is correct |
7 | Correct | 132 ms | 50936 KB | Output is correct |
8 | Correct | 130 ms | 51132 KB | Output is correct |
9 | Correct | 245 ms | 52600 KB | Output is correct |
10 | Correct | 154 ms | 51576 KB | Output is correct |
11 | Correct | 165 ms | 51960 KB | Output is correct |
12 | Correct | 32 ms | 44152 KB | Output is correct |
13 | Correct | 34 ms | 44152 KB | Output is correct |
14 | Correct | 36 ms | 44152 KB | Output is correct |
15 | Correct | 36 ms | 44244 KB | Output is correct |
16 | Correct | 35 ms | 44152 KB | Output is correct |
17 | Correct | 34 ms | 44152 KB | Output is correct |
18 | Correct | 42 ms | 44152 KB | Output is correct |
19 | Correct | 33 ms | 44152 KB | Output is correct |
20 | Correct | 34 ms | 44280 KB | Output is correct |
21 | Correct | 33 ms | 44160 KB | Output is correct |
22 | Correct | 34 ms | 44152 KB | Output is correct |
23 | Correct | 37 ms | 44152 KB | Output is correct |
24 | Correct | 35 ms | 44152 KB | Output is correct |
25 | Correct | 33 ms | 44160 KB | Output is correct |
26 | Correct | 32 ms | 44152 KB | Output is correct |
27 | Correct | 34 ms | 44024 KB | Output is correct |
28 | Correct | 90 ms | 44664 KB | Output is correct |
29 | Correct | 113 ms | 44664 KB | Output is correct |
30 | Correct | 95 ms | 44536 KB | Output is correct |
31 | Correct | 84 ms | 44508 KB | Output is correct |
32 | Correct | 101 ms | 44536 KB | Output is correct |
33 | Correct | 91 ms | 44536 KB | Output is correct |
34 | Correct | 93 ms | 44536 KB | Output is correct |
35 | Incorrect | 223 ms | 53044 KB | Output isn't correct |
36 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 221 ms | 50296 KB | Output is correct |
2 | Correct | 213 ms | 50276 KB | Output is correct |
3 | Correct | 243 ms | 53204 KB | Output is correct |
4 | Correct | 210 ms | 52852 KB | Output is correct |
5 | Correct | 40 ms | 44156 KB | Output is correct |
6 | Correct | 222 ms | 52472 KB | Output is correct |
7 | Correct | 132 ms | 50936 KB | Output is correct |
8 | Correct | 130 ms | 51132 KB | Output is correct |
9 | Correct | 245 ms | 52600 KB | Output is correct |
10 | Correct | 154 ms | 51576 KB | Output is correct |
11 | Correct | 165 ms | 51960 KB | Output is correct |
12 | Correct | 32 ms | 44152 KB | Output is correct |
13 | Correct | 34 ms | 44152 KB | Output is correct |
14 | Correct | 36 ms | 44152 KB | Output is correct |
15 | Correct | 36 ms | 44244 KB | Output is correct |
16 | Correct | 35 ms | 44152 KB | Output is correct |
17 | Correct | 34 ms | 44152 KB | Output is correct |
18 | Correct | 42 ms | 44152 KB | Output is correct |
19 | Correct | 33 ms | 44152 KB | Output is correct |
20 | Correct | 34 ms | 44280 KB | Output is correct |
21 | Correct | 33 ms | 44160 KB | Output is correct |
22 | Correct | 34 ms | 44152 KB | Output is correct |
23 | Correct | 37 ms | 44152 KB | Output is correct |
24 | Correct | 35 ms | 44152 KB | Output is correct |
25 | Correct | 33 ms | 44160 KB | Output is correct |
26 | Correct | 32 ms | 44152 KB | Output is correct |
27 | Correct | 34 ms | 44024 KB | Output is correct |
28 | Correct | 90 ms | 44664 KB | Output is correct |
29 | Correct | 113 ms | 44664 KB | Output is correct |
30 | Correct | 95 ms | 44536 KB | Output is correct |
31 | Correct | 84 ms | 44508 KB | Output is correct |
32 | Correct | 101 ms | 44536 KB | Output is correct |
33 | Correct | 91 ms | 44536 KB | Output is correct |
34 | Correct | 93 ms | 44536 KB | Output is correct |
35 | Incorrect | 223 ms | 53044 KB | Output isn't correct |
36 | Halted | 0 ms | 0 KB | - |