Submission #629446

# Submission time Handle Problem Language Result Execution time Memory
629446 2022-08-14T13:44:44 Z handlename Catfish Farm (IOI22_fish) C++17
100 / 100
514 ms 65816 KB
#include <bits/stdc++.h>
//#include "fish.h"
using namespace std;
#define pb push_back
#define mp make_pair
 
vector<pair<int,long long> > arr[100005];
long long qry(int col,int height){ //prefixsum of col to height
	if (arr[col].empty()) return 0;
	pair<int,long long> lol=mp(height,1e18);
	int pos=upper_bound(arr[col].begin(),arr[col].end(),lol)-arr[col].begin();
	pos--;
	return arr[col][pos].second;
}
vector<long long> dp1[100005]; //col,height,increasing
vector<long long> dp2[100005]; //col,height,decreasing
vector<long long> whack[100005];
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]++;
		y[i]++;
		arr[x[i]].pb(mp(y[i],w[i]));
	}
	for (int i=1;i<=n;i++){
		arr[i].pb(mp(0,0));
		sort(arr[i].begin(),arr[i].end());
		for (int j=1;j<(int)arr[i].size();j++){
			arr[i][j].second+=arr[i][j-1].second;
		}
		for (auto j:arr[i]){
			whack[i].pb(j.first);
			//if (j.first>0) whack[i].pb(j.first-1);
			whack[i+1].pb(j.first);
			whack[i-1].pb(j.first);
		}
	}
	for (int i=0;i<=n;i++){
		sort(whack[i].begin(),whack[i].end());
		whack[i].erase(unique(whack[i].begin(),whack[i].end()),whack[i].end());
		for (int j=0;j<(int) whack[i].size();j++){
			dp1[i].pb(0);
			dp2[i].pb(0);
		}
	}
	for (int i=1;i<=n;i++){ //col
		long long maxi=0,id=0;
		for (int j=0;j<(int)whack[i].size();j++){
			int k=whack[i][j];
			while (id<(int)whack[i-1].size() && whack[i-1][id]<=k){
				maxi=max(maxi,dp1[i-1][id]-qry(i,whack[i-1][id])-qry(i-1,whack[i-1][id]));
				id++;
			}
			dp1[i][j]=maxi+qry(i-1,k)+qry(i+1,k);
		}
		/*
		for (int j=0;j<=n;j++){
			maxi=max(maxi,dp1[i-1][j]-qry(i,j)-qry(i-1,j));
			if (i>=2){
				maxi=max(maxi,dp2[i-2][j]-qry(i-1,j));
			}
			dp1[i][j]=maxi+qry(i-1,j)+qry(i+1,j);
		}
		*/
		
		if (i>=2){
			maxi=0;
			id=0;
			for (int j=0;j<(int)whack[i].size();j++){
				int k=whack[i][j];
				while (id<(int)whack[i-2].size() && whack[i-2][id]<=k){
					maxi=max(maxi,dp2[i-2][id]-qry(i-1,whack[i-2][id]));
					id++;
				}
				dp1[i][j]=max(dp1[i][j],maxi+qry(i-1,k)+qry(i+1,k));
			}
			maxi=0;
			id=whack[i-2].size()-1;
			for (int j=whack[i].size()-1;j>=0;j--){
				int k=whack[i][j];
				while (id>=0 && whack[i-2][id]>=k){
					maxi=max(maxi,dp2[i-2][id]);
					id--;
				}
				dp1[i][j]=max(dp1[i][j],maxi+qry(i+1,k));
			}
			/*
			for (int j=n;j>=0;j--){
				maxi=max(maxi,dp2[i-2][j]);
				dp1[i][j]=max(dp1[i][j],maxi+qry(i+1,j));
			}
			*/
		}
		
		maxi=0;
		id=whack[i-1].size()-1;
		for (int j=whack[i].size()-1;j>=0;j--){
			int k=whack[i][j];
			while (id>=0 && whack[i-1][id]>=k){
				maxi=max(maxi,dp2[i-1][id]);
				id--;
			}
			dp2[i][j]=maxi+qry(i+1,k)-qry(i,k);
		}
		/*
		for (int j=n;j>=0;j--){
			maxi=max(maxi,dp2[i-1][j]);
			dp2[i][j]=maxi+qry(i+1,j)-qry(i,j);
		}
		*/
		for (int j=0;j<(int)whack[i].size();j++){
			dp2[i][j]=max(dp2[i][j],dp1[i][j]);
		}
	}
	long long ans=0;
	for (int j=0;j<(int)dp2[n].size();j++){
		ans=max(ans,dp2[n][j]);
	}
	return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 168 ms 31628 KB Output is correct
2 Correct 141 ms 35028 KB Output is correct
3 Correct 42 ms 23696 KB Output is correct
4 Correct 62 ms 23888 KB Output is correct
5 Correct 418 ms 59152 KB Output is correct
6 Correct 424 ms 65584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 238 ms 38316 KB Output is correct
3 Correct 254 ms 42864 KB Output is correct
4 Correct 122 ms 31644 KB Output is correct
5 Correct 157 ms 35092 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 43 ms 23764 KB Output is correct
11 Correct 44 ms 23704 KB Output is correct
12 Correct 129 ms 31668 KB Output is correct
13 Correct 183 ms 34964 KB Output is correct
14 Correct 123 ms 32416 KB Output is correct
15 Correct 147 ms 32800 KB Output is correct
16 Correct 163 ms 32440 KB Output is correct
17 Correct 161 ms 34532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 23764 KB Output is correct
2 Correct 41 ms 23720 KB Output is correct
3 Correct 85 ms 26324 KB Output is correct
4 Correct 67 ms 26256 KB Output is correct
5 Correct 134 ms 31400 KB Output is correct
6 Correct 106 ms 31428 KB Output is correct
7 Correct 105 ms 31424 KB Output is correct
8 Correct 122 ms 31424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9696 KB Output is correct
2 Correct 6 ms 9652 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 9 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9696 KB Output is correct
2 Correct 6 ms 9652 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 9 ms 9812 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 8 ms 9960 KB Output is correct
17 Correct 53 ms 14992 KB Output is correct
18 Correct 50 ms 15272 KB Output is correct
19 Correct 41 ms 15016 KB Output is correct
20 Correct 37 ms 14756 KB Output is correct
21 Correct 42 ms 14780 KB Output is correct
22 Correct 76 ms 19568 KB Output is correct
23 Correct 19 ms 11220 KB Output is correct
24 Correct 46 ms 13940 KB Output is correct
25 Correct 7 ms 9840 KB Output is correct
26 Correct 17 ms 10984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9696 KB Output is correct
2 Correct 6 ms 9652 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 9 ms 9812 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 8 ms 9960 KB Output is correct
17 Correct 53 ms 14992 KB Output is correct
18 Correct 50 ms 15272 KB Output is correct
19 Correct 41 ms 15016 KB Output is correct
20 Correct 37 ms 14756 KB Output is correct
21 Correct 42 ms 14780 KB Output is correct
22 Correct 76 ms 19568 KB Output is correct
23 Correct 19 ms 11220 KB Output is correct
24 Correct 46 ms 13940 KB Output is correct
25 Correct 7 ms 9840 KB Output is correct
26 Correct 17 ms 10984 KB Output is correct
27 Correct 9 ms 10404 KB Output is correct
28 Correct 214 ms 32268 KB Output is correct
29 Correct 353 ms 41144 KB Output is correct
30 Correct 437 ms 59772 KB Output is correct
31 Correct 509 ms 59448 KB Output is correct
32 Correct 247 ms 42828 KB Output is correct
33 Correct 492 ms 59928 KB Output is correct
34 Correct 472 ms 59872 KB Output is correct
35 Correct 163 ms 25900 KB Output is correct
36 Correct 437 ms 53436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 23764 KB Output is correct
2 Correct 41 ms 23720 KB Output is correct
3 Correct 85 ms 26324 KB Output is correct
4 Correct 67 ms 26256 KB Output is correct
5 Correct 134 ms 31400 KB Output is correct
6 Correct 106 ms 31428 KB Output is correct
7 Correct 105 ms 31424 KB Output is correct
8 Correct 122 ms 31424 KB Output is correct
9 Correct 120 ms 34904 KB Output is correct
10 Correct 106 ms 27856 KB Output is correct
11 Correct 196 ms 46220 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 9608 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9688 KB Output is correct
17 Correct 5 ms 9576 KB Output is correct
18 Correct 41 ms 23692 KB Output is correct
19 Correct 41 ms 23692 KB Output is correct
20 Correct 44 ms 23808 KB Output is correct
21 Correct 41 ms 23764 KB Output is correct
22 Correct 168 ms 36020 KB Output is correct
23 Correct 224 ms 50544 KB Output is correct
24 Correct 212 ms 51272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 31628 KB Output is correct
2 Correct 141 ms 35028 KB Output is correct
3 Correct 42 ms 23696 KB Output is correct
4 Correct 62 ms 23888 KB Output is correct
5 Correct 418 ms 59152 KB Output is correct
6 Correct 424 ms 65584 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 238 ms 38316 KB Output is correct
9 Correct 254 ms 42864 KB Output is correct
10 Correct 122 ms 31644 KB Output is correct
11 Correct 157 ms 35092 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 7 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 43 ms 23764 KB Output is correct
17 Correct 44 ms 23704 KB Output is correct
18 Correct 129 ms 31668 KB Output is correct
19 Correct 183 ms 34964 KB Output is correct
20 Correct 123 ms 32416 KB Output is correct
21 Correct 147 ms 32800 KB Output is correct
22 Correct 163 ms 32440 KB Output is correct
23 Correct 161 ms 34532 KB Output is correct
24 Correct 42 ms 23764 KB Output is correct
25 Correct 41 ms 23720 KB Output is correct
26 Correct 85 ms 26324 KB Output is correct
27 Correct 67 ms 26256 KB Output is correct
28 Correct 134 ms 31400 KB Output is correct
29 Correct 106 ms 31428 KB Output is correct
30 Correct 105 ms 31424 KB Output is correct
31 Correct 122 ms 31424 KB Output is correct
32 Correct 6 ms 9696 KB Output is correct
33 Correct 6 ms 9652 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 7 ms 9684 KB Output is correct
39 Correct 5 ms 9684 KB Output is correct
40 Correct 5 ms 9684 KB Output is correct
41 Correct 6 ms 9940 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 7 ms 9812 KB Output is correct
44 Correct 6 ms 9684 KB Output is correct
45 Correct 9 ms 9812 KB Output is correct
46 Correct 6 ms 9684 KB Output is correct
47 Correct 8 ms 9960 KB Output is correct
48 Correct 53 ms 14992 KB Output is correct
49 Correct 50 ms 15272 KB Output is correct
50 Correct 41 ms 15016 KB Output is correct
51 Correct 37 ms 14756 KB Output is correct
52 Correct 42 ms 14780 KB Output is correct
53 Correct 76 ms 19568 KB Output is correct
54 Correct 19 ms 11220 KB Output is correct
55 Correct 46 ms 13940 KB Output is correct
56 Correct 7 ms 9840 KB Output is correct
57 Correct 17 ms 10984 KB Output is correct
58 Correct 9 ms 10404 KB Output is correct
59 Correct 214 ms 32268 KB Output is correct
60 Correct 353 ms 41144 KB Output is correct
61 Correct 437 ms 59772 KB Output is correct
62 Correct 509 ms 59448 KB Output is correct
63 Correct 247 ms 42828 KB Output is correct
64 Correct 492 ms 59928 KB Output is correct
65 Correct 472 ms 59872 KB Output is correct
66 Correct 163 ms 25900 KB Output is correct
67 Correct 437 ms 53436 KB Output is correct
68 Correct 120 ms 34904 KB Output is correct
69 Correct 106 ms 27856 KB Output is correct
70 Correct 196 ms 46220 KB Output is correct
71 Correct 5 ms 9684 KB Output is correct
72 Correct 5 ms 9684 KB Output is correct
73 Correct 5 ms 9608 KB Output is correct
74 Correct 5 ms 9684 KB Output is correct
75 Correct 5 ms 9688 KB Output is correct
76 Correct 5 ms 9576 KB Output is correct
77 Correct 41 ms 23692 KB Output is correct
78 Correct 41 ms 23692 KB Output is correct
79 Correct 44 ms 23808 KB Output is correct
80 Correct 41 ms 23764 KB Output is correct
81 Correct 168 ms 36020 KB Output is correct
82 Correct 224 ms 50544 KB Output is correct
83 Correct 212 ms 51272 KB Output is correct
84 Correct 513 ms 54960 KB Output is correct
85 Correct 514 ms 55780 KB Output is correct
86 Correct 429 ms 64012 KB Output is correct
87 Correct 481 ms 65804 KB Output is correct
88 Correct 5 ms 9684 KB Output is correct
89 Correct 472 ms 65816 KB Output is correct
90 Correct 392 ms 61600 KB Output is correct
91 Correct 322 ms 56336 KB Output is correct