Submission #625915

# Submission time Handle Problem Language Result Execution time Memory
625915 2022-08-11T02:07:39 Z oolimry Catfish Farm (IOI22_fish) C++17
18 / 100
272 ms 55888 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
typedef long long lint;
typedef pair<lint,lint> ii;

struct state{
	lint h, P, D, I;
	bool operator < (state &b){
		return this->h < b.h;
	}
	bool operator == (state &b){
		return this->h == b.h;
	}
};

vector<state> dp[200005];
vector<ii> sum[200005];

///get the sum of values in column x, up to height H
inline lint getsum(int x, lint H){
	if(x == -1) return 0;
	auto it = upper_bound(all(sum[x]), ii(H, 1023456678901234LL));
	if(it == sum[x].begin()) return 0;
	
	it--;
	return it->second;
}


long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> C){
	if(n == 1) return 0;
	
	///setting up sum counts
	for(int i = 0;i < m;i++){
		sum[X[i]].push_back(ii(Y[i], C[i]));
	}
	
	for(int i = 0;i < n;i++){
		sort(all(sum[i]));
		for(int j = 1;j < sz(sum[i]);j++){
			sum[i][j].second += sum[i][j-1].second;
		}
	}
	
	
	
	///set up the important values in the dp table
	for(int i = 0;i < m;i++){
		if(X[i] != 0) dp[X[i]-1].push_back({Y[i], 0, 0, 0});
		if(X[i] != n-1) dp[X[i]+1].push_back({Y[i], 0, 0, 0});
	}
	
	for(int i = 0;i < n;i++){
		dp[i].push_back({-1,0,0,0}); ///represent not taking anything
		sort(all(dp[i]));
		dp[i].erase(unique(all(dp[i])), dp[i].end());		
	}
	
	///now do dp
	for(auto &s : dp[0]){
		s.P = getsum(1, s.h);
		s.I = -getsum(0, s.h);
		s.D = getsum(1, s.h) - getsum(0, s.h);
	}
	
	for(int i = 1;i < n;i++){
		
		///I to I and I to P
		lint bestI = -1023232322323LL;
		auto it = dp[i-1].begin();
		for(auto &s : dp[i]){
			while(it != dp[i-1].end()){
				if(it->h >= s.h){
					bestI = max(bestI, it->I);
					it++;
				}
				else break;
			}
			
			///I to I
			s.I = max(s.I, bestI + getsum(i-1, s.h) - getsum(i, s.h));
			
			///I to P
			s.P = max(s.P, bestI + getsum(i-1, s.h) + getsum(i+1, s.h));
		}
		
		///D to D and P to D
		reverse(all(dp[i]));
		reverse(all(dp[i-1]));
		
		lint bestPD = -1023232322323LL;
		it = dp[i-1].begin();
		for(auto &s : dp[i]){
			while(it != dp[i-1].end()){
				if(it->h <= s.h){
					bestPD = max(bestPD, it->P);
					bestPD = max(bestPD, it->D);
					it++;
				}
				else break;
			}
			
			///D to D and P to D
			s.D = max(s.D, bestPD + getsum(i+1, s.h) - getsum(i, s.h));
		}
		
		reverse(all(dp[i]));
		reverse(all(dp[i-1]));
		
		///D -1 to I -1
		dp[i][0].I = max(dp[i][0].I, dp[i-1][0].D);
		
		///P to P 2 spaces away
		if(i >= 2){
			lint bestP = 0;
			for(auto &s : dp[i-2]) bestP = max(bestP, s.P);
			
			for(auto &s : dp[i]){
				s.P = max(s.P, bestP + getsum(i+1, s.h));
			}
		}
	}
	
	lint ans = 0;
	
	for(int i = 0;i < n;i++){

		for(auto &s : dp[i]){
			ans = max(ans, s.P);
			ans = max(ans, s.I);
			ans = max(ans, s.D);
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 19512 KB Output is correct
2 Correct 74 ms 21348 KB Output is correct
3 Correct 14 ms 14292 KB Output is correct
4 Correct 13 ms 14396 KB Output is correct
5 Correct 268 ms 47168 KB Output is correct
6 Correct 272 ms 55888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 143 ms 27900 KB Output is correct
3 Correct 178 ms 31640 KB Output is correct
4 Correct 73 ms 19536 KB Output is correct
5 Correct 72 ms 21436 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9700 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 16 ms 14312 KB Output is correct
11 Correct 14 ms 14392 KB Output is correct
12 Correct 87 ms 22152 KB Output is correct
13 Correct 91 ms 24504 KB Output is correct
14 Correct 69 ms 20820 KB Output is correct
15 Correct 86 ms 22124 KB Output is correct
16 Correct 70 ms 20836 KB Output is correct
17 Correct 79 ms 22152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14396 KB Output is correct
2 Correct 14 ms 14292 KB Output is correct
3 Correct 55 ms 22368 KB Output is correct
4 Correct 46 ms 19788 KB Output is correct
5 Correct 97 ms 30780 KB Output is correct
6 Correct 98 ms 30864 KB Output is correct
7 Correct 99 ms 30828 KB Output is correct
8 Correct 104 ms 30924 KB Output is correct
# 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 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 9 ms 9688 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Incorrect 5 ms 9684 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 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 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 9 ms 9688 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Incorrect 5 ms 9684 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 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 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 9 ms 9688 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Incorrect 5 ms 9684 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14396 KB Output is correct
2 Correct 14 ms 14292 KB Output is correct
3 Correct 55 ms 22368 KB Output is correct
4 Correct 46 ms 19788 KB Output is correct
5 Correct 97 ms 30780 KB Output is correct
6 Correct 98 ms 30864 KB Output is correct
7 Correct 99 ms 30828 KB Output is correct
8 Correct 104 ms 30924 KB Output is correct
9 Correct 102 ms 30852 KB Output is correct
10 Correct 90 ms 29284 KB Output is correct
11 Correct 193 ms 48900 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 4 ms 9684 KB Output is correct
17 Incorrect 5 ms 9684 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 19512 KB Output is correct
2 Correct 74 ms 21348 KB Output is correct
3 Correct 14 ms 14292 KB Output is correct
4 Correct 13 ms 14396 KB Output is correct
5 Correct 268 ms 47168 KB Output is correct
6 Correct 272 ms 55888 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 143 ms 27900 KB Output is correct
9 Correct 178 ms 31640 KB Output is correct
10 Correct 73 ms 19536 KB Output is correct
11 Correct 72 ms 21436 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9700 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 16 ms 14312 KB Output is correct
17 Correct 14 ms 14392 KB Output is correct
18 Correct 87 ms 22152 KB Output is correct
19 Correct 91 ms 24504 KB Output is correct
20 Correct 69 ms 20820 KB Output is correct
21 Correct 86 ms 22124 KB Output is correct
22 Correct 70 ms 20836 KB Output is correct
23 Correct 79 ms 22152 KB Output is correct
24 Correct 14 ms 14396 KB Output is correct
25 Correct 14 ms 14292 KB Output is correct
26 Correct 55 ms 22368 KB Output is correct
27 Correct 46 ms 19788 KB Output is correct
28 Correct 97 ms 30780 KB Output is correct
29 Correct 98 ms 30864 KB Output is correct
30 Correct 99 ms 30828 KB Output is correct
31 Correct 104 ms 30924 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 9 ms 9688 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 7 ms 9684 KB Output is correct
39 Incorrect 5 ms 9684 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
40 Halted 0 ms 0 KB -