Submission #1039172

# Submission time Handle Problem Language Result Execution time Memory
1039172 2024-07-30T14:02:25 Z Marco_Escandon Catfish Farm (IOI22_fish) C++17
100 / 100
328 ms 112744 KB
#include<bits/stdc++.h>
using namespace std;
//#include "fish.h"
typedef long long ll;
#pragma optimize("O3")
#define x first
#define y second
vector<vector<pair<ll,ll>>>  cad;
vector<vector<ll>>  indice;
/// @brief costo en la columna i
/// @param i columna
/// @param j valor del puente
/// @return 
ll cost(ll i, ll j){
    ll a=-1,b=cad[i].size();
    while(abs(a-b)!=1){
        ll m=(a+b)/2;
        if(cad[i][m].x<=j) a=m;
        else b=m;
    }
    if(b==0) return 0;
    return cad[i][b-1].y;
}
/// @brief mayor k tal que indice[i][k] <= j
/// @param i columna 
/// @param j valor
/// @return posicion 
ll idx(ll i, ll j){
    ll a=-1,b=indice[i].size();
    while(abs(a-b)!=1){
        ll m=(a+b)/2;
        if(indice[i][m]<=j) a=m;
        else b=m;
    }
    return b-1;
}
long long max_weights(int n, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> w) {
    cad.resize(n+1); indice.resize(n+1);
    vector<vector<vector<ll>>>  dp(n+1);
    for(int i=0; i<X.size(); i++){
        cad[X[i]+1].push_back({Y[i]+1,w[i]});
        if(X[i]!=0)   indice[X[i]].push_back(Y[i]+1);
        if(X[i]+2<=n) indice[X[i]+2].push_back(Y[i]+1);
    }
    for(int i=0; i<cad.size(); i++)
    {
        indice[i].push_back(0);
        sort(cad[i].begin(),cad[i].end());
        sort(indice[i].begin(),indice[i].end());
        dp[i].assign(indice[i].size(),{0,0});
        for(int j=1; j<cad[i].size(); j++)
            cad[i][j].y+=cad[i][j-1].y;
    }
    vector<vector<vector<ll>>>  dpac=dp;
    ll bs=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<indice[i].size(); j++)
        {
            ll idxtemp=idx(i-1,indice[i][j]);
            ll costoij=cost(i,indice[i][j]);
            ll costoi_1j=cost(i-1,indice[i][j]);
            if(idxtemp+1<dpac[i-1].size()) dp[i][j][0]=max(dp[i][j][0],dpac[i-1][idxtemp+1][0]-costoij);
            
            if(idxtemp>-1) dp[i][j][1]=max(dp[i][j][1],dp[i-1][idxtemp][1]+costoi_1j);
            if(i>=2) dp[i][j][1]=max(dp[i][j][1],dpac[i-2][0][1]+costoi_1j);    
 
            dpac[i][j][0]=max(dp[i][j][0],dp[i][j][1]);
            if(i<n) dpac[i][j][0]+=cost(i+1,indice[i][j]);
            dpac[i][j][1]=max(dp[i][j][0],dp[i][j][1]);
            bs=max(bs,max(dp[i][j][0],dp[i][j][1]));// salvar la respuesta
 
            dp[i][j][1]-=costoij;
            if(j>0)dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][1]);
        }
        for(int j=indice[i].size()-2; j>-1; j--)
        {
            dpac[i][j][0]=max(dpac[i][j][0],dpac[i][j+1][0]);
            dpac[i][j][1]=max(dpac[i][j][1],dpac[i][j+1][1]);
        }
            
    }
    return bs;
}

Compilation message

fish.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    5 | #pragma optimize("O3")
      | 
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0; i<X.size(); i++){
      |                  ~^~~~~~~~~
fish.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<cad.size(); i++)
      |                  ~^~~~~~~~~~~
fish.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j=1; j<cad[i].size(); j++)
      |                      ~^~~~~~~~~~~~~~
fish.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j=0; j<indice[i].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~
fish.cpp:63:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             if(idxtemp+1<dpac[i-1].size()) dp[i][j][0]=max(dp[i][j][0],dpac[i-1][idxtemp+1][0]-costoij);
      |                ~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 63 ms 35584 KB Output is correct
2 Correct 77 ms 40896 KB Output is correct
3 Correct 26 ms 25432 KB Output is correct
4 Correct 28 ms 25436 KB Output is correct
5 Correct 249 ms 108292 KB Output is correct
6 Correct 247 ms 111956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 148 ms 58040 KB Output is correct
3 Correct 163 ms 68676 KB Output is correct
4 Correct 61 ms 35524 KB Output is correct
5 Correct 70 ms 41152 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 26 ms 25424 KB Output is correct
11 Correct 26 ms 25436 KB Output is correct
12 Correct 71 ms 45176 KB Output is correct
13 Correct 97 ms 52716 KB Output is correct
14 Correct 81 ms 40508 KB Output is correct
15 Correct 90 ms 44988 KB Output is correct
16 Correct 82 ms 40676 KB Output is correct
17 Correct 104 ms 44992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25436 KB Output is correct
2 Correct 28 ms 25436 KB Output is correct
3 Correct 67 ms 38484 KB Output is correct
4 Correct 53 ms 35916 KB Output is correct
5 Correct 99 ms 54352 KB Output is correct
6 Correct 97 ms 54348 KB Output is correct
7 Correct 114 ms 54352 KB Output is correct
8 Correct 107 ms 54356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 31 ms 13016 KB Output is correct
18 Correct 34 ms 14040 KB Output is correct
19 Correct 32 ms 13832 KB Output is correct
20 Correct 31 ms 13660 KB Output is correct
21 Correct 30 ms 13660 KB Output is correct
22 Correct 66 ms 26972 KB Output is correct
23 Correct 6 ms 2904 KB Output is correct
24 Correct 20 ms 8988 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 31 ms 13016 KB Output is correct
18 Correct 34 ms 14040 KB Output is correct
19 Correct 32 ms 13832 KB Output is correct
20 Correct 31 ms 13660 KB Output is correct
21 Correct 30 ms 13660 KB Output is correct
22 Correct 66 ms 26972 KB Output is correct
23 Correct 6 ms 2904 KB Output is correct
24 Correct 20 ms 8988 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
27 Correct 3 ms 2048 KB Output is correct
28 Correct 167 ms 63132 KB Output is correct
29 Correct 256 ms 86628 KB Output is correct
30 Correct 217 ms 85812 KB Output is correct
31 Correct 216 ms 85844 KB Output is correct
32 Correct 225 ms 88424 KB Output is correct
33 Correct 217 ms 85912 KB Output is correct
34 Correct 221 ms 85876 KB Output is correct
35 Correct 92 ms 34656 KB Output is correct
36 Correct 222 ms 88952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25436 KB Output is correct
2 Correct 28 ms 25436 KB Output is correct
3 Correct 67 ms 38484 KB Output is correct
4 Correct 53 ms 35916 KB Output is correct
5 Correct 99 ms 54352 KB Output is correct
6 Correct 97 ms 54348 KB Output is correct
7 Correct 114 ms 54352 KB Output is correct
8 Correct 107 ms 54356 KB Output is correct
9 Correct 98 ms 54316 KB Output is correct
10 Correct 86 ms 42580 KB Output is correct
11 Correct 186 ms 84564 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 30 ms 25428 KB Output is correct
19 Correct 26 ms 25432 KB Output is correct
20 Correct 27 ms 25432 KB Output is correct
21 Correct 26 ms 25436 KB Output is correct
22 Correct 116 ms 54256 KB Output is correct
23 Correct 187 ms 84712 KB Output is correct
24 Correct 187 ms 84560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 35584 KB Output is correct
2 Correct 77 ms 40896 KB Output is correct
3 Correct 26 ms 25432 KB Output is correct
4 Correct 28 ms 25436 KB Output is correct
5 Correct 249 ms 108292 KB Output is correct
6 Correct 247 ms 111956 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 148 ms 58040 KB Output is correct
9 Correct 163 ms 68676 KB Output is correct
10 Correct 61 ms 35524 KB Output is correct
11 Correct 70 ms 41152 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 26 ms 25424 KB Output is correct
17 Correct 26 ms 25436 KB Output is correct
18 Correct 71 ms 45176 KB Output is correct
19 Correct 97 ms 52716 KB Output is correct
20 Correct 81 ms 40508 KB Output is correct
21 Correct 90 ms 44988 KB Output is correct
22 Correct 82 ms 40676 KB Output is correct
23 Correct 104 ms 44992 KB Output is correct
24 Correct 26 ms 25436 KB Output is correct
25 Correct 28 ms 25436 KB Output is correct
26 Correct 67 ms 38484 KB Output is correct
27 Correct 53 ms 35916 KB Output is correct
28 Correct 99 ms 54352 KB Output is correct
29 Correct 97 ms 54348 KB Output is correct
30 Correct 114 ms 54352 KB Output is correct
31 Correct 107 ms 54356 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 1116 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 31 ms 13016 KB Output is correct
49 Correct 34 ms 14040 KB Output is correct
50 Correct 32 ms 13832 KB Output is correct
51 Correct 31 ms 13660 KB Output is correct
52 Correct 30 ms 13660 KB Output is correct
53 Correct 66 ms 26972 KB Output is correct
54 Correct 6 ms 2904 KB Output is correct
55 Correct 20 ms 8988 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 5 ms 2908 KB Output is correct
58 Correct 3 ms 2048 KB Output is correct
59 Correct 167 ms 63132 KB Output is correct
60 Correct 256 ms 86628 KB Output is correct
61 Correct 217 ms 85812 KB Output is correct
62 Correct 216 ms 85844 KB Output is correct
63 Correct 225 ms 88424 KB Output is correct
64 Correct 217 ms 85912 KB Output is correct
65 Correct 221 ms 85876 KB Output is correct
66 Correct 92 ms 34656 KB Output is correct
67 Correct 222 ms 88952 KB Output is correct
68 Correct 98 ms 54316 KB Output is correct
69 Correct 86 ms 42580 KB Output is correct
70 Correct 186 ms 84564 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 30 ms 25428 KB Output is correct
78 Correct 26 ms 25432 KB Output is correct
79 Correct 27 ms 25432 KB Output is correct
80 Correct 26 ms 25436 KB Output is correct
81 Correct 116 ms 54256 KB Output is correct
82 Correct 187 ms 84712 KB Output is correct
83 Correct 187 ms 84560 KB Output is correct
84 Correct 309 ms 106160 KB Output is correct
85 Correct 328 ms 108344 KB Output is correct
86 Correct 278 ms 109136 KB Output is correct
87 Correct 274 ms 112468 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 296 ms 112744 KB Output is correct
90 Correct 256 ms 111952 KB Output is correct
91 Correct 304 ms 111720 KB Output is correct