제출 #858383

#제출 시각아이디문제언어결과실행 시간메모리
858383LucaIlie메기 농장 (IOI22_fish)C++17
0 / 100
43 ms18724 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; struct cf { int x, y, w; }; const int MAX_N = 3002; const int MAX_M = 3e5; const long long INF = 1e18; cf catfish[MAX_M]; //vector<int> line[MAX_N]; int costCell[MAX_N][MAX_N]; 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 ) { for ( int i = 0; i < m; i++ ) { X[i]++; catfish[i] = { X[i], Y[i], W[i] }; //line[catfish[i].y].push_back( i ); costCell[X[i]][Y[i]] = W[i]; } long long costTotal = 0; for ( int y = 0; y < n; y++ ) { /*sort( line[l].begin(), line[l].end(), []( int i, int j ) { return catfish[i].x < catfish[j].x; } );*/ 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...