Submission #1039169

# Submission time Handle Problem Language Result Execution time Memory
1039169 2024-07-30T14:01:28 Z Marco_Escandon Catfish Farm (IOI22_fish) C++17
100 / 100
337 ms 112508 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][0]);
                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 64 ms 35520 KB Output is correct
2 Correct 77 ms 40896 KB Output is correct
3 Correct 28 ms 25444 KB Output is correct
4 Correct 43 ms 25428 KB Output is correct
5 Correct 260 ms 108280 KB Output is correct
6 Correct 284 ms 112104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 170 ms 58176 KB Output is correct
3 Correct 176 ms 68716 KB Output is correct
4 Correct 74 ms 35628 KB Output is correct
5 Correct 80 ms 40968 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 34 ms 25388 KB Output is correct
11 Correct 29 ms 25436 KB Output is correct
12 Correct 87 ms 45184 KB Output is correct
13 Correct 113 ms 52756 KB Output is correct
14 Correct 83 ms 40412 KB Output is correct
15 Correct 98 ms 45064 KB Output is correct
16 Correct 82 ms 40680 KB Output is correct
17 Correct 89 ms 44988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 25320 KB Output is correct
2 Correct 31 ms 25352 KB Output is correct
3 Correct 83 ms 38484 KB Output is correct
4 Correct 79 ms 35920 KB Output is correct
5 Correct 120 ms 54432 KB Output is correct
6 Correct 133 ms 54288 KB Output is correct
7 Correct 148 ms 54324 KB Output is correct
8 Correct 146 ms 54352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 31 ms 13032 KB Output is correct
18 Correct 31 ms 13916 KB Output is correct
19 Correct 30 ms 13660 KB Output is correct
20 Correct 32 ms 13660 KB Output is correct
21 Correct 31 ms 13660 KB Output is correct
22 Correct 68 ms 27096 KB Output is correct
23 Correct 6 ms 2908 KB Output is correct
24 Correct 20 ms 8792 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 6 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 31 ms 13032 KB Output is correct
18 Correct 31 ms 13916 KB Output is correct
19 Correct 30 ms 13660 KB Output is correct
20 Correct 32 ms 13660 KB Output is correct
21 Correct 31 ms 13660 KB Output is correct
22 Correct 68 ms 27096 KB Output is correct
23 Correct 6 ms 2908 KB Output is correct
24 Correct 20 ms 8792 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 6 ms 2908 KB Output is correct
27 Correct 3 ms 1884 KB Output is correct
28 Correct 170 ms 63200 KB Output is correct
29 Correct 251 ms 86608 KB Output is correct
30 Correct 226 ms 85992 KB Output is correct
31 Correct 224 ms 85880 KB Output is correct
32 Correct 221 ms 88440 KB Output is correct
33 Correct 256 ms 86136 KB Output is correct
34 Correct 255 ms 85876 KB Output is correct
35 Correct 115 ms 34644 KB Output is correct
36 Correct 253 ms 88860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 25320 KB Output is correct
2 Correct 31 ms 25352 KB Output is correct
3 Correct 83 ms 38484 KB Output is correct
4 Correct 79 ms 35920 KB Output is correct
5 Correct 120 ms 54432 KB Output is correct
6 Correct 133 ms 54288 KB Output is correct
7 Correct 148 ms 54324 KB Output is correct
8 Correct 146 ms 54352 KB Output is correct
9 Correct 111 ms 54352 KB Output is correct
10 Correct 97 ms 42580 KB Output is correct
11 Correct 248 ms 84564 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 46 ms 25272 KB Output is correct
19 Correct 46 ms 25372 KB Output is correct
20 Correct 28 ms 25436 KB Output is correct
21 Correct 27 ms 25332 KB Output is correct
22 Correct 146 ms 54356 KB Output is correct
23 Correct 207 ms 84740 KB Output is correct
24 Correct 220 ms 84700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 35520 KB Output is correct
2 Correct 77 ms 40896 KB Output is correct
3 Correct 28 ms 25444 KB Output is correct
4 Correct 43 ms 25428 KB Output is correct
5 Correct 260 ms 108280 KB Output is correct
6 Correct 284 ms 112104 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 170 ms 58176 KB Output is correct
9 Correct 176 ms 68716 KB Output is correct
10 Correct 74 ms 35628 KB Output is correct
11 Correct 80 ms 40968 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 34 ms 25388 KB Output is correct
17 Correct 29 ms 25436 KB Output is correct
18 Correct 87 ms 45184 KB Output is correct
19 Correct 113 ms 52756 KB Output is correct
20 Correct 83 ms 40412 KB Output is correct
21 Correct 98 ms 45064 KB Output is correct
22 Correct 82 ms 40680 KB Output is correct
23 Correct 89 ms 44988 KB Output is correct
24 Correct 27 ms 25320 KB Output is correct
25 Correct 31 ms 25352 KB Output is correct
26 Correct 83 ms 38484 KB Output is correct
27 Correct 79 ms 35920 KB Output is correct
28 Correct 120 ms 54432 KB Output is correct
29 Correct 133 ms 54288 KB Output is correct
30 Correct 148 ms 54324 KB Output is correct
31 Correct 146 ms 54352 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 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 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 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 604 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 31 ms 13032 KB Output is correct
49 Correct 31 ms 13916 KB Output is correct
50 Correct 30 ms 13660 KB Output is correct
51 Correct 32 ms 13660 KB Output is correct
52 Correct 31 ms 13660 KB Output is correct
53 Correct 68 ms 27096 KB Output is correct
54 Correct 6 ms 2908 KB Output is correct
55 Correct 20 ms 8792 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 6 ms 2908 KB Output is correct
58 Correct 3 ms 1884 KB Output is correct
59 Correct 170 ms 63200 KB Output is correct
60 Correct 251 ms 86608 KB Output is correct
61 Correct 226 ms 85992 KB Output is correct
62 Correct 224 ms 85880 KB Output is correct
63 Correct 221 ms 88440 KB Output is correct
64 Correct 256 ms 86136 KB Output is correct
65 Correct 255 ms 85876 KB Output is correct
66 Correct 115 ms 34644 KB Output is correct
67 Correct 253 ms 88860 KB Output is correct
68 Correct 111 ms 54352 KB Output is correct
69 Correct 97 ms 42580 KB Output is correct
70 Correct 248 ms 84564 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 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 46 ms 25272 KB Output is correct
78 Correct 46 ms 25372 KB Output is correct
79 Correct 28 ms 25436 KB Output is correct
80 Correct 27 ms 25332 KB Output is correct
81 Correct 146 ms 54356 KB Output is correct
82 Correct 207 ms 84740 KB Output is correct
83 Correct 220 ms 84700 KB Output is correct
84 Correct 304 ms 106140 KB Output is correct
85 Correct 302 ms 108344 KB Output is correct
86 Correct 317 ms 109272 KB Output is correct
87 Correct 337 ms 112508 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 296 ms 112468 KB Output is correct
90 Correct 265 ms 111956 KB Output is correct
91 Correct 253 ms 111956 KB Output is correct