#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAX_TAILLE=100*1000+5,MAX_BON=500*1000+5,INFINI=(ll)1000*1000*1000*1000*1000*10;
ll taille,nbBonus;
ll posBon[MAX_BON][2];
vector<tuple<ll,ll,ll>> bonSurCol[MAX_TAILLE];
ll memo[MAX_BON][3];
ll premSous(ll col,ll lig) {
ll deb=0,mid,fin=bonSurCol[col].size()-1;
while (deb!=fin) {
mid=(deb+fin+1)/2;
if (get<0>(bonSurCol[col][mid])<=lig) {
deb=mid;
}
else {
fin=mid-1;
}
}
return get<2>(bonSurCol[col][deb]);
}
ll premSur(ll col,ll lig) {
ll deb=0,mid,fin=bonSurCol[col].size()-1;
while (deb!=fin) {
mid=(deb+fin)/2;
if (get<0>(bonSurCol[col][mid])>=lig) {
fin=mid;
}
else {
deb=mid+1;
}
}
return get<2>(bonSurCol[col][deb]);
}
ll dyna(ll idReq,ll desc) {
if (memo[idReq][desc]!=-1) {
return memo[idReq][desc];
}
ll col=posBon[idReq][0],num=posBon[idReq][1];
//cout<<idReq<<" : "<<premSous(col+1,get<0>(bonSurCol[col][num]))<<" "<<premSur(col+1,get<0>(bonSurCol[col][num]))<<endl;
//return 42;
if (desc==0) {
if (num==0) {
memo[idReq][desc]=dyna(idReq+2,1);
return memo[idReq][desc];
}
if (num==(ll)bonSurCol[col].size()-1) {
memo[idReq][desc]=max(get<1>(bonSurCol[col][num])+dyna(get<2>(bonSurCol[col][num-1]),0),
dyna(idReq+2,0));
}
else {
memo[idReq][desc]=max(get<1>(bonSurCol[col][num])+dyna(get<2>(bonSurCol[col][num-1]),0),
dyna(premSous(col+1,max(get<0>(bonSurCol[col][num+1])-1,(ll)0)),0));
}
return memo[idReq][desc];
}
else {
if (num==(ll)bonSurCol[col].size()-1) {
if (desc==1) {
memo[idReq][desc]=max(dyna(premSur(col+1,get<0>(bonSurCol[col][num-1])+1),1),dyna(idReq+2,0));
}
else {
memo[idReq][desc]=max(dyna(premSur(col+1,get<0>(bonSurCol[col][num-1])+1),1),dyna(idReq+2,1));
}
return memo[idReq][desc];
}
if (num==0) {
memo[idReq][desc]=max(dyna(idReq+3,0),
max(get<1>(bonSurCol[col][num])+dyna(get<2>(bonSurCol[col][num+1]),2),
dyna(idReq+2,1)));
return memo[idReq][desc];
}
memo[idReq][desc]=max(get<1>(bonSurCol[col][num])+dyna(get<2>(bonSurCol[col][num+1]),2),
dyna(premSur(col+1,get<0>(bonSurCol[col][num-1])+1),1));
return memo[idReq][desc];
}
}
ll max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W) {
taille=N;
nbBonus=M+2*(N+1);
for (ll i=0;i<M;i++) {
bonSurCol[X[i]].push_back(make_tuple(Y[i],W[i],i));
}
for (ll i=0;i<=taille;i++) {
bonSurCol[i].push_back(make_tuple(0,0,M+2*i));
bonSurCol[i].push_back(make_tuple(taille+1,0,M+2*i+1));
sort(bonSurCol[i].begin(),bonSurCol[i].end());
//cout<<i<<" : ";
for (ll j=0;j<(ll)bonSurCol[i].size();j++) {
//cout<<get<0>(bonSurCol[i][j])<<" "<<get<1>(bonSurCol[i][j])<<" "<<get<2>(bonSurCol[i][j])<<" ";
posBon[get<2>(bonSurCol[i][j])][0]=i;
posBon[get<2>(bonSurCol[i][j])][1]=j;
}
//cout<<endl;
}
for (ll i=0;i<nbBonus-2;i++) {
memo[i][0]=-1;
memo[i][1]=-1;
memo[i][2]=-1;
}
for (auto k:bonSurCol[taille-1]) {
memo[get<2>(k)][2]=-INFINI;
}
ll temp=dyna(M,1);
/*for (ll i=0;i<nbBonus;i++) {
for (ll j=0;j<3;j++) {
cout<<i<<" "<<j<<" : "<<dyna(i,j)<<endl;
}
}*/
return temp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
30472 KB |
Output is correct |
2 |
Correct |
60 ms |
34240 KB |
Output is correct |
3 |
Correct |
23 ms |
24572 KB |
Output is correct |
4 |
Correct |
24 ms |
24588 KB |
Output is correct |
5 |
Correct |
181 ms |
58144 KB |
Output is correct |
6 |
Correct |
179 ms |
55536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
94 ms |
39080 KB |
Output is correct |
3 |
Correct |
112 ms |
45288 KB |
Output is correct |
4 |
Correct |
51 ms |
30712 KB |
Output is correct |
5 |
Correct |
59 ms |
34876 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2664 KB |
Output is correct |
10 |
Correct |
23 ms |
24560 KB |
Output is correct |
11 |
Correct |
28 ms |
24524 KB |
Output is correct |
12 |
Correct |
52 ms |
30732 KB |
Output is correct |
13 |
Correct |
63 ms |
34840 KB |
Output is correct |
14 |
Correct |
55 ms |
30788 KB |
Output is correct |
15 |
Correct |
59 ms |
33900 KB |
Output is correct |
16 |
Correct |
51 ms |
30772 KB |
Output is correct |
17 |
Correct |
56 ms |
33812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
24504 KB |
Output is correct |
2 |
Correct |
22 ms |
24532 KB |
Output is correct |
3 |
Correct |
42 ms |
29320 KB |
Output is correct |
4 |
Correct |
36 ms |
29288 KB |
Output is correct |
5 |
Correct |
67 ms |
37420 KB |
Output is correct |
6 |
Correct |
65 ms |
37184 KB |
Output is correct |
7 |
Correct |
67 ms |
37384 KB |
Output is correct |
8 |
Correct |
68 ms |
37424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2660 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2664 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2660 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2664 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2660 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2664 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
24504 KB |
Output is correct |
2 |
Correct |
22 ms |
24532 KB |
Output is correct |
3 |
Correct |
42 ms |
29320 KB |
Output is correct |
4 |
Correct |
36 ms |
29288 KB |
Output is correct |
5 |
Correct |
67 ms |
37420 KB |
Output is correct |
6 |
Correct |
65 ms |
37184 KB |
Output is correct |
7 |
Correct |
67 ms |
37384 KB |
Output is correct |
8 |
Correct |
68 ms |
37424 KB |
Output is correct |
9 |
Correct |
67 ms |
37428 KB |
Output is correct |
10 |
Correct |
54 ms |
24652 KB |
Output is correct |
11 |
Correct |
117 ms |
46604 KB |
Output is correct |
12 |
Correct |
1 ms |
2664 KB |
Output is correct |
13 |
Correct |
2 ms |
2788 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
30472 KB |
Output is correct |
2 |
Correct |
60 ms |
34240 KB |
Output is correct |
3 |
Correct |
23 ms |
24572 KB |
Output is correct |
4 |
Correct |
24 ms |
24588 KB |
Output is correct |
5 |
Correct |
181 ms |
58144 KB |
Output is correct |
6 |
Correct |
179 ms |
55536 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
94 ms |
39080 KB |
Output is correct |
9 |
Correct |
112 ms |
45288 KB |
Output is correct |
10 |
Correct |
51 ms |
30712 KB |
Output is correct |
11 |
Correct |
59 ms |
34876 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2664 KB |
Output is correct |
16 |
Correct |
23 ms |
24560 KB |
Output is correct |
17 |
Correct |
28 ms |
24524 KB |
Output is correct |
18 |
Correct |
52 ms |
30732 KB |
Output is correct |
19 |
Correct |
63 ms |
34840 KB |
Output is correct |
20 |
Correct |
55 ms |
30788 KB |
Output is correct |
21 |
Correct |
59 ms |
33900 KB |
Output is correct |
22 |
Correct |
51 ms |
30772 KB |
Output is correct |
23 |
Correct |
56 ms |
33812 KB |
Output is correct |
24 |
Correct |
22 ms |
24504 KB |
Output is correct |
25 |
Correct |
22 ms |
24532 KB |
Output is correct |
26 |
Correct |
42 ms |
29320 KB |
Output is correct |
27 |
Correct |
36 ms |
29288 KB |
Output is correct |
28 |
Correct |
67 ms |
37420 KB |
Output is correct |
29 |
Correct |
65 ms |
37184 KB |
Output is correct |
30 |
Correct |
67 ms |
37384 KB |
Output is correct |
31 |
Correct |
68 ms |
37424 KB |
Output is correct |
32 |
Correct |
1 ms |
2660 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2664 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
40 |
Halted |
0 ms |
0 KB |
- |