Submission #828305

# Submission time Handle Problem Language Result Execution time Memory
828305 2023-08-17T08:01:48 Z peteza Catfish Farm (IOI22_fish) C++17
0 / 100
999 ms 69728 KB
#include "fish.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <climits>
#include <map>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int n, m;
vector<pll> pts[100005];
vector<int> dppoints[100005];
long long getsum(int col, int row) {
	if(col == -1 || col == n) return 0;
	auto it = upper_bound(pts[col].begin(), pts[col].end(), pll(row, LLONG_MAX));
	if(it == pts[col].begin()) return 0;
	return (--it)->second;
}

ll f1[100005], f2[100005];
map<int, ll> DP[100005];

vector<int> used;

void upd(ll*fwk, int idx, ll val) {
	for(;idx<=100000;idx+=idx&-idx) {
		fwk[idx] = max(fwk[idx], val);
		used.push_back(idx);
	}
}

ll qr(ll* fwk, int idx) {
	ll cmax = 0;
	for(;idx;idx-=idx&-idx)
		cmax = max(cmax, fwk[idx]);
	return cmax;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
	n = N; m = M;
	for(int i=0;i<X.size();i++) {
		pts[X[i]].emplace_back(Y[i], i);
		if(X[i] != 0)  dppoints[X[i]-1].push_back(Y[i]);
		if(X[i] != N-1)dppoints[X[i]+1].push_back(Y[i]);
	}
	for(int i=0;i<N;i++) {
		if(pts[i].empty()) continue;
		sort(pts[i].begin(), pts[i].end());
		pts[i][0].second = W[pts[i][0].second];
		for(int j=1;j<pts[i].size();j++) {
			pts[i][j].second = pts[i][j-1].second + W[pts[i][j].second];
		}
	}
	long long best = 0, cur_im1y = 0;
	for(int col=0;col<N;col++) {
		for(int row:dppoints[col]) {
			ll Wij = getsum(col, row), Wipj=getsum(col+1,row), Wimj=getsum(col-1,row);
			DP[col][row] = cur_im1y + Wipj + Wimj;
			if(col != 0) {
				//max{k <= j}(DP[i-1][k]) - sum{m<=k}(w[i][m])
				//max{k >  j}(DP[i-1][k]) - sum{m<=j}(w[i][m])
				long long cbest = max(qr(f1, row+1), qr(f2, n-row) - Wij);
				//cout << qr(f1, row+1) << ' ' << qr(f2, n-row) << '\n';
				DP[col][row] = max(cbest+Wipj, DP[col][row]);
			}
			best = max(best, DP[col][row]);
		}
		if(col!=0) {
			for(int e:used)
				f1[e] = f2[e] = 0;
			used.clear();
			
		}
		if(col >= 1)
			for(int row:dppoints[col-1])
				cur_im1y = max(cur_im1y, DP[col-1][row]);
		//cout << "-----\n" << col << '\n';
		for(int row:dppoints[col]) {
			//cout << row << ": " << DP[col][row] << ' ';
			//cout << '\n';
			upd(f1, row+1, DP[col][row] - getsum(col+1, row));
			upd(f2, n-row, DP[col][row]);
		} //buildfwk
	}
	return best;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=0;i<X.size();i++) {
      |              ~^~~~~~~~~
fish.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int j=1;j<pts[i].size();j++) {
      |               ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 138 ms 27956 KB Output is correct
2 Correct 194 ms 30104 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Incorrect 999 ms 69728 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '299628921470958'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 460 ms 42392 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80958394776886'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 45 ms 18204 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 4 ms 9700 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9704 KB Output is correct
9 Incorrect 6 ms 9812 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '326664473535'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 4 ms 9700 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9704 KB Output is correct
9 Incorrect 6 ms 9812 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '326664473535'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 4 ms 9700 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9704 KB Output is correct
9 Incorrect 6 ms 9812 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '326664473535'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 45 ms 18204 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 138 ms 27956 KB Output is correct
2 Correct 194 ms 30104 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Incorrect 999 ms 69728 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '299628921470958'
6 Halted 0 ms 0 KB -