This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
//#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 1000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod = 1000000007 ;
const int mod1 = 998244353 ;
const int N = 4e5 + 10 ;
//mt19937 R(time(0));
map < string , int > ma , ma1 ;
#include "fish.h"
ll sum[ 305 ][ 305 ] ;
ll pos[ 305 ][ 305 ] ;
ll dp_bl[ 305 ][ 305 ] ;
ll dp_dk[ 305 ][ 305 ] ;
//vector < pair < int , int > > v[ 305 ] ;
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W){
int tt = 0 ;
ll sm = 0 ;
FOR( i , M ){
sm = sm + W[ i ] ;
if( X[ i ] % 2 == 1 ) tt =-1 ;
}
if( tt == 0 ) return sm ;
FOR( i , M ){
pos[ X[ i ] ][ Y[ i ] ] = W[ i ] ;
}
FOR( i , N ){
FOR( j , N ){
if( j != 0 ) sum[ i ][ j ] = sum[ i ][ j - 1 ] ;
sum[ i ][ j ] += pos[ i ][ j ] ;
}
}
// dp_bl
// dp_dk
FOR( i , N ){
if( i == 0 ){
FOR( j , N + 1 ){
dp_bl[ i ][ j ] = 0 ;
dp_dk[ i ][ j ] = 0 ;
}
continue ;
}
FOR( j , N + 1 ){
// j ari sadamdec ginda kedeli
// cases
// pirveli ginda ro winas kedeli amaze maxali iyos
for( int wn = j ; wn < N + 1 ; wn ++ ){
ll cur ;
ll sm = 0 ;
if( wn != 0 ) sm = sum[ i ][ wn - 1 ] ;
if( j != 0 ) sm = sm - sum[ i ][ j - 1 ] ;
cur = dp_bl[ i - 1 ][ wn ] + sm ;
dp_bl[ i ][ j ] = max( dp_bl[ i ][ j ] , cur ) ;
dp_dk[ i ][ wn ] = max( dp_dk[ i ][ wn ] , cur ) ;
}
for( int wn = 0 ; wn < j ; wn ++ ){
ll cur ;
ll sm = sum[ i - 1 ][ j - 1 ] ;
if( wn != 0 ) sm = sm - sum[ i - 1 ][ wn - 1 ] ;
cur = sm + dp_dk[ i - 1 ][ wn ] ;
dp_bl[ i ][ j ] = max( dp_bl[ i ][ j ] , cur ) ;
dp_dk[ i ][ j ] = max( dp_dk[ i ][ j ] , cur ) ;
}
}
}
ll ans = 0 ;
FOR( j , N + 1 ){
ans = max( ans , dp_bl[ N - 1 ][ j ] ) ;
ans = max( ans , dp_dk[ N - 1 ][ j ] ) ;
}
return ans ;
}
// int main() {
// int N, M;
// assert(2 == scanf("%d %d", &N, &M));
// std::vector<int> X(M), Y(M), W(M);
// for (int i = 0; i < M; ++i) {
// assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
// }
// long long result = max_weights(N, M, X, Y, W);
// printf("%lld\n", result);
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |