Submission #626808

#TimeUsernameProblemLanguageResultExecution timeMemory
626808KaitokidCatfish Farm (IOI22_fish)C++17
67 / 100
1079 ms38680 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int mx; ll dp2[309][309][2]; ll sum[3009][3009]; ll go5(int x,int lst,int u) { if(x==mx)return 0; if(dp2[x][lst][u]!=-1)return dp2[x][lst][u]; for(int i=0;i<=mx;i++) { ll d=0; if(u==0 && i>lst) d=sum[x-1][i]-sum[x-1][lst]; dp2[x][lst][u]=max(dp2[x][lst][u],d+go5(x+1,i,0)); if(i<lst)d+=sum[x][lst]-sum[x][i]; dp2[x][lst][u]=max(dp2[x][lst][u],d+go5(x+1,i,1)); } return dp2[x][lst][u]; } ll max_weights5(int N,int M,vector<int>X,vector<int>Y,vector<int>W) { mx=N; for(int i=0;i<M;i++)sum[X[i]][Y[i]+1]+=W[i]; for(int i=0;i<N;i++) for(int j=1;j<=N;j++)sum[i][j]+=sum[i][j-1]; memset(dp2,-1,sizeof dp2); ll ans=0; for(int i=0;i<=N;i++) ans=max(ans,go5(1,i,0)); return ans; } vector<int>g[100009],f[300009]; ll dp[100009][3][2]; ll go7(int x,int lst,int u) { if(x==mx)return 0; if(dp[x][lst][u]!=-1)return dp[x][lst][u]; for(int i=0;i<g[x].size();i++) { ll d=0; if((u==0) && g[x][i]>g[x-1][lst]) { for(int j=0;j<g[x-1].size();j++) if(g[x-1][j]>=g[x-1][lst] && g[x-1][j]<g[x][i])d+=f[x-1][j]; } dp[x][lst][u]=max(dp[x][lst][u],d+go7(x+1,i,0)); for(int j=0;j<g[x].size();j++) if(g[x][j]<g[x-1][lst] && g[x][j]>=g[x][i])d+=f[x][j]; dp[x][lst][u]=max(dp[x][lst][u],d+go7(x+1,i,1)); } return dp[x][lst][u]; } ll max_weights7(int N,int M,vector<int>X,vector<int>Y,vector<int>W) { mx=N; for(int i=0;i<M;i++) { g[X[i]].push_back(Y[i]+1); f[X[i]].push_back(W[i]); } for(int i=0;i<N;i++) { g[i].push_back(N+1);f[i].push_back(0); } memset(dp,-1,sizeof dp); ll ans=0; for(int i=0;i<g[0].size();i++) ans=max(ans,go7(1,i,0)); return ans; } ll max_weights1(int N,int M,vector<int>X,vector<int>Y,vector<int>W) { ll ans=0; for(int i=0;i<M;i++)ans+=W[i]; return ans; } int a[2][200009]; ll max_weights2(int N,int M,vector<int>X,vector<int>Y,vector<int>W) { for(int i=0;i<M;i++) a[X[i]][Y[i]]+=W[i]; ll ans=0,mx=0; for(int i=0;i<N;i++)ans+=a[1][i]; mx=ans; for(int i=0;i<N;i++) { ans-=a[1][i]; ans+=a[0][i]; mx=max(ans,mx); } return mx; } ll max_weights(int N,int M,vector<int>X,vector<int>Y,vector<int>W) { if(N<=300)return max_weights5(N,M,X,Y,W); bool bl1=true,bl2=true; for(int i=0;i<M;i++) {if(X[i]%2)bl1=false; if(X[i]>1)bl2=false;} if(bl1)return max_weights1(N,M,X,Y,W); if(bl2)return max_weights2(N,M,X,Y,W); return max_weights7(N,M,X,Y,W); }

Compilation message (stderr)

fish.cpp: In function 'll max_weights5(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   30 |     for(int i=0;i<=N;i++)
      |     ^~~
fish.cpp:32:8: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   32 |        return ans;
      |        ^~~~~~
fish.cpp: In function 'll go7(int, int, int)':
fish.cpp:40:18: 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<g[x].size();i++)
      |                 ~^~~~~~~~~~~~
fish.cpp:45:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 for(int j=0;j<g[x-1].size();j++)
      |                             ~^~~~~~~~~~~~~~
fish.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int j=0;j<g[x].size();j++)
      |                     ~^~~~~~~~~~~~
fish.cpp: In function 'll max_weights7(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=0;i<g[0].size();i++)
      |                 ~^~~~~~~~~~~~
fish.cpp:72:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   72 |     for(int i=0;i<g[0].size();i++)
      |     ^~~
fish.cpp:74:8: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   74 |        return ans;
      |        ^~~~~~
fish.cpp: In function 'll max_weights2(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:85:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   85 |     for(int i=0;i<M;i++)
      |     ^~~
fish.cpp:87:7: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   87 |       ll ans=0,mx=0;
      |       ^~
#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...