제출 #1186703

#제출 시각아이디문제언어결과실행 시간메모리
1186703ByeWorld메기 농장 (IOI22_fish)C++20
0 / 100
622 ms75980 KiB
#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
#define fi first 
#define se second
#define pb push_back
using namespace std;
typedef pair<ll,ll> pii;
typedef pair<ll,pii> ipii;
const int MAXN = 3100;
const ll INF = 2e18+10;
void chmx(auto &a, auto b){ a = max(a, b); }
void chmn(auto &a, auto b){ a = min(a, b); }

int n, m;
ll x[MAXN], y[MAXN], w[MAXN], a[MAXN][MAXN];
ll up[MAXN][MAXN], dw[MAXN][MAXN], pr[MAXN][MAXN];

ll cost(int id, int le, int ri){
	if(le > ri) return 0;
	return pr[id][ri]-pr[id][le-1];
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	n = N; m = M;
	bool ev = 1;
	for(int i=1; i<=m; i++){
		x[i] = X[i-1]+1; y[i] = Y[i-1]+1; w[i] = W[i-1];
		a[x[i]][y[i]] += w[i];
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) pr[i][j] = pr[i][j-1]+a[i][j];
	}

	for(int j=0; j<=n; j++) up[0][j] = dw[0][j] = -INF;
	up[0][0] = dw[0][0] = 0;
	
	// cout << cost(2, 1, 2) << " p\n";
	for(int i=1; i<=n; i++){
		for(int j=0; j<=n; j++){
			up[i][j] = -INF;
			for(int k=0; k<=j; k++){
				chmx(up[i][j], up[i-1][k] + cost(i-1, k+1, j));
			}

			dw[i][j] = -INF;
			for(int k=j; k<=n; k++){
				chmx(dw[i][j], dw[i-1][k] + cost(i, j+1, k));
			}
		}
		// cout << i << " i\n";
		// for(int j=0; j<=n; j++)
		// 	cout << up[i][j] << " \n"[j==n];
		// for(int j=0; j<=n; j++)
		// 	cout << dw[i][j] << " \n"[j==n];
		// cout << "dw\n\n";
		for(int j=0; j<=n; j++)
			dw[i][j] = max(dw[i][j], up[i][j]);
	}

	ll ANS = 0;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=n; j++)
			chmx(ANS, max(up[i][j], dw[i][j]) );
	}
	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...