Submission #829294

#TimeUsernameProblemLanguageResultExecution timeMemory
829294tolbiCatfish Farm (IOI22_fish)C++17
35 / 100
1156 ms1747924 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #include "fish.h" vector<vector<vector<ll>>> dp; vector<vector<ll>> grid; int N; long long f(int x, int y, int flag){ if (dp[x][y][flag]!=-1) return dp[x][y][flag]; if (flag==1){ dp[x][y][flag]=0; if (y<N){ ll crr = 0; if (x>0) crr = grid[x-1][y]; dp[x][y][flag]=crr+f(x,y+1,1); } if (x+1<N){ dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,1)); dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,0)); } } else if (flag==0){ dp[x][y][flag]=0; if (y-1>=0){ dp[x][y][flag]=grid[x][y-1]+f(x,y-1,0); } if (x+1<N){ dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,0)); if (y==0){ dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,2)); } } } else { dp[x][y][flag]=0; if (y<N){ dp[x][y][flag]=f(x,y+1,2); } if (x+1<N){ dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,1)); dp[x][y][flag]=max(dp[x][y][flag],f(x+1,y,0)); } } if (flag!=0 && x+2<N){ dp[x][y][flag]=max(dp[x][y][flag],f(x+2,0,1)); } return dp[x][y][flag]; }; long long max_weights(int _N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { N=_N; dp.resize(N,vector<vector<ll>>(N+1,vector<ll>(3,-1))); grid.resize(N,vector<ll>(N+1,0)); for (int i = 0; i < M; ++i) { grid[X[i]][Y[i]]=W[i]; } //0 decreasing //1 increasing //2 increasing, \ but forbidden to profit from back return f(0,0,2); }

Compilation message (stderr)

fish.cpp:60:5: warning: multi-line comment [-Wcomment]
   60 |     //2 increasing, \
      |     ^
#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...