Submission #858387

#TimeUsernameProblemLanguageResultExecution timeMemory
858387LucaIlieCatfish Farm (IOI22_fish)C++17
9 / 100
1176 ms2097152 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 300000; const int MAX_M = 3e5; const long long INF = 1e18; long long dp[MAX_N][2], costCol[MAX_N]; long long max_weights( int n, int m, vector<int> X, vector<int> Y, vector<int> W ) { int maxY = 0; for ( int i = 0; i < m; i++ ) maxY = max( maxY, Y[i] ); int costCell[n + 2][maxY + 1]; for ( int i = 0; i <= n + 1; i++ ) { for ( int j = 0; j <= maxY; j++ ) costCell[i][j] = 0; } for ( int i = 0; i < m; i++ ) { X[i]++; costCell[X[i]][Y[i]] = W[i]; } long long costTotal = 0; for ( int y = 0; y <= maxY; y++ ) { dp[0][0] = 0; dp[0][1] = -INF; for ( int x = 1; x <= n + 1; x++ ) { dp[x][0] = dp[x][1] = -INF; dp[x][0] = max( dp[x][0], dp[x - 1][0] ); dp[x][0] = max( dp[x][0], dp[x - 1][1] + costCell[x][y] ); dp[x][1] = max( dp[x][1], dp[x - 1][0] - costCol[x] ); dp[x][1] = max( dp[x][1], dp[x - 1][1] - costCol[x] ); if ( x >= 2 ) { dp[x][1] = max( dp[x][1], dp[x - 2][0] + costCell[x - 1][y] - costCol[x] ); dp[x][1] = max( dp[x][1], dp[x - 2][1] + costCell[x - 1][y] - costCol[x] ); } } costTotal += dp[n + 1][0]; int side = 0, x = n + 1; while ( x > 0 ) { if ( side == 0 ) { if ( dp[x][0] == dp[x - 1][0] ) { x--; side = 0; } else if ( dp[x][0] == dp[x - 1][1] + costCell[x][y] ) { costCol[x] += costCell[x][y]; x--; side = 1; } } else { if ( dp[x][1] == dp[x - 1][0] - costCol[x] ) { costCol[x] = 0; x--; side = 0; } else if ( dp[x][1] == dp[x - 1][1] - costCol[x] ) { costCol[x] = 0; x--; side = 1; } else if ( dp[x][1] == dp[x - 2][0] + costCell[x - 1][y] - costCol[x] ) { costCol[x] = 0; costCol[x - 1] += costCell[x - 1][y]; x -= 2; side = 0; } else if ( dp[x][1] == dp[x - 2][1] + costCell[x - 1][y] - costCol[x] ) { costCol[x] = 0; costCol[x - 1] += costCell[x - 1][y]; x -= 2; side = 1; } } } /*printf( "%d: \n", y ); printf( "costTotal %d\n", costTotal ); for ( int x = 1; x <= n; x++ ) printf( "%d ", costCol[x] ); printf( "\n" ); for ( int c = 1; c <= n; c++ ) printf( "(%d %d) ", dp[c][0], dp[c][1] ); printf( "\n\n" );*/ } return costTotal; }
#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...