Submission #1023427

#TimeUsernameProblemLanguageResultExecution timeMemory
1023427IssaCatfish Farm (IOI22_fish)C++17
0 / 100
898 ms468648 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3e3 + 100; const int maxl = 11; int n; ll dp[maxn][maxn][2]; ll a[maxn][maxn]; long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){ n = N; for(int i = 0; i < M; i++){ X[i]++; Y[i]++; a[X[i]][Y[i]] += W[i]; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ a[i][j] += a[i][j-1]; } } for(int i = 1; i <= n; i++){ for(int j = 0; j <= n; j++){ dp[i][j][0] = dp[i][j][1] = -(ll)1e18; if(i == 1) dp[i][j][1] = dp[i][j][0] = 0; } } for(int i = 1; i < n; i++){ for(int j = 0; j <= n; j++){ for(int k = 0; k <= n; k++){ if(j <= k){ dp[i+1][k][1] = max(dp[i+1][k][1], dp[i][j][1] + a[i][k] - a[i][j]); } if(j >= k){ dp[i+1][k][0] = max(dp[i+1][k][0], dp[i][j][0] + a[i+1][j] - a[i+1][k]); } if(i + 2 <= n){ dp[i+2][k][0] = max(dp[i+2][k][0], dp[i][j][1] + a[i][n] + a[i+2][n] - a[i][j] - a[i+2][k]); dp[i+2][k][1] = max(dp[i+2][k][1], dp[i][j][0] + a[i+1][min(i, k)]); } } } } // for(int i = 1; i <= n; i++){ // for(int j = 0; j <= n; j++){ // cout << dp[i][j][0] << ' '; // } cout << endl; // for(int j = 0; j <= n; j++){ // cout << dp[i][j][1] << ' '; // } cout << endl << endl; // } ll ans = 0; for(int i = 0; i <= n; i++){ for(int c = 0; c < 2; c++){ ans = max(ans, dp[n][i][c]); } } return ans; }
#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...