Submission #1038607

#TimeUsernameProblemLanguageResultExecution timeMemory
1038607Marco_EscandonCatfish Farm (IOI22_fish)C++17
0 / 100
1099 ms73184 KiB
#include<bits/stdc++.h> using namespace std; #include "fish.h" typedef long long ll; #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; } ll bs=0; for(int i=1; i<=n; i++) { for(int j=0; j<indice[i].size(); j++) { for(int l=idx(i-1,indice[i][j])+1; l<dp[i-1].size(); l++)/// 321 & 231 dp[i][j][0]=max(dp[i][j][0],(max(dp[i-1][l][0],dp[i-1][l][1])+cost(i,indice[i-1][l]))-cost(i,indice[i][j])); for(int l=0; l<=idx(i-1,indice[i][j]); l++)/// 123 dp[i][j][1]=max(dp[i][j][1],(dp[i-1][l][1]-cost(i,indice[i-1][l]))+cost(i,indice[i][j])); if(i>=2) for(int l=0; l<dp[i-2].size(); l++)/// 103 dp[i][j][1]=max(dp[i][j][1],max(dp[i-2][l][1],dp[i-2][l][1])+cost(i-1,max(indice[i][j],indice[i-2][l])) ); bs=max(bs,max(dp[i][j][0],dp[i][j][1]));// salvar la respuesta } } return bs; }

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0; i<X.size(); i++){
      |                  ~^~~~~~~~~
fish.cpp:44: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]
   44 |     for(int i=0; i<cad.size(); i++)
      |                  ~^~~~~~~~~~~
fish.cpp:50: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]
   50 |         for(int j=1; j<cad[i].size(); j++)
      |                      ~^~~~~~~~~~~~~~
fish.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int j=0; j<indice[i].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~
fish.cpp:59:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for(int l=idx(i-1,indice[i][j])+1; l<dp[i-1].size(); l++)///                                              321 & 231
      |                                                ~^~~~~~~~~~~~~~~
fish.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |             for(int l=0; l<dp[i-2].size(); l++)///                                                            103
      |                          ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...