Submission #832494

# Submission time Handle Problem Language Result Execution time Memory
832494 2023-08-21T10:53:52 Z NothingXD Catfish Farm (IOI22_fish) C++17
100 / 100
260 ms 87104 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 3e5 + 10;

int n, m, x[maxn], y[maxn], w[maxn];
vector<int> num[maxn];
vector<int> val[maxn];
vector<ll> dp1[maxn], dp2[maxn], sum[maxn];
ll gole[maxn];

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
	n = N, m = M;
	for (int i = 0; i < m; i++){
		x[i] = X[i];
		y[i] = Y[i];
		w[i] = W[i];
		num[x[i]].push_back(y[i]-1);
		num[x[i]].push_back(y[i]);
	}
//	debug(0);
	for (int i = 0; i < n; i++){
		num[i].push_back(-1);
		num[i].push_back(n-1);
		sort(all(num[i]));
		num[i].resize(distance(num[i].begin(), unique(all(num[i]))));
		for (auto x: num[i]){
			val[i].push_back(0);
		}
	}
	for (int i = 0; i < m; i++){
		int idx = lower_bound(all(num[x[i]]), y[i]) - num[x[i]].begin();
		val[x[i]][idx] = w[i];
	}
//	debug(1);
	dp1[0].resize(val[0].size(), 0);
	dp2[0].resize(val[0].size(), 0);
	sum[0].resize(val[0].size(), 0);
	for (int i = 1; i < val[0].size(); i++){
		dp1[0][i] = dp1[0][i-1] + val[0][i];
		sum[0][i] = sum[0][i-1] + val[0][i];
	}
	//gole[0] = 0;
//	for (int i = 0; i < val[0].size(); i++) debug(0, i, num[0][i], dp1[0][i], dp2[0][i], sum[0][i]);
	for (int i = 1; i < n; i++){
		dp1[i].resize(val[i].size());
		dp2[i].resize(val[i].size());
		sum[i].resize(val[i].size());
		for (int j = 0; j < val[i].size(); j++){
			int idx = upper_bound(all(num[i-1]), num[i][j]) - num[i-1].begin() - 1;
			dp1[i][j] = dp1[i-1][idx];
			if (j){
				dp1[i][j] = max(dp1[i][j], dp1[i][j-1] + val[i][j]);
			}
			if (i > 1){
				dp1[i][j] = max(dp1[i][j], dp2[i-1][0]);
				dp1[i][j] = max(dp1[i][j], dp2[i-2][0] + sum[i-1][idx]);
			}
		}
		for (int j = val[i].size()-1; ~j; j--){
		//	debug(i, j);
			int idx = lower_bound(all(num[i-1]), num[i][j]) - num[i-1].begin();
			dp2[i][j] = dp2[i-1][idx];
			if (j + 1 != val[i].size()) dp2[i][j] = max(dp2[i][j], dp2[i][j+1] + val[i][j+1]);
			if (i > 1){
			//	debug(1, dp1[i-2][val[i-2].size()-1]);
				dp2[i][j] = max(dp2[i][j], dp1[i-2][val[i-2].size()-1]);
			}
			if (i > 2){
				dp2[i][j] = max(dp2[i][j], dp2[i-2][0]);
				dp2[i][j] = max(dp2[i][j], dp2[i-3][0] + sum[i-2][val[i-2].size()-1]);
			}
		}
		for (int j = 1; j < val[i].size(); j++){
			sum[i][j] = sum[i][j-1] + val[i][j];
		}
	//	for (int j = 0; j < val[i].size(); j++) debug(i, j, num[i][j], dp1[i][j], dp2[i][j], sum[i][j]);
	}
	ll ans = max(dp2[n-1][0], dp1[n-2][val[n-2].size()-1]);
	return ans;
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:46:13: warning: unused variable 'x' [-Wunused-variable]
   46 |   for (auto x: num[i]){
      |             ^
fish.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 1; i < val[0].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~
fish.cpp:68:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int j = 0; j < val[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~
fish.cpp:83:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    if (j + 1 != val[i].size()) dp2[i][j] = max(dp2[i][j], dp2[i][j+1] + val[i][j+1]);
      |        ~~~~~~^~~~~~~~~~~~~~~~
fish.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (int j = 1; j < val[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 88 ms 55544 KB Output is correct
2 Correct 101 ms 58196 KB Output is correct
3 Correct 49 ms 51112 KB Output is correct
4 Correct 47 ms 51144 KB Output is correct
5 Correct 205 ms 73108 KB Output is correct
6 Correct 260 ms 81684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 35512 KB Output is correct
2 Correct 144 ms 61512 KB Output is correct
3 Correct 162 ms 65276 KB Output is correct
4 Correct 97 ms 55480 KB Output is correct
5 Correct 101 ms 58160 KB Output is correct
6 Correct 19 ms 35500 KB Output is correct
7 Correct 22 ms 35452 KB Output is correct
8 Correct 20 ms 35452 KB Output is correct
9 Correct 20 ms 35668 KB Output is correct
10 Correct 46 ms 51180 KB Output is correct
11 Correct 52 ms 51080 KB Output is correct
12 Correct 104 ms 55564 KB Output is correct
13 Correct 103 ms 58196 KB Output is correct
14 Correct 94 ms 55496 KB Output is correct
15 Correct 99 ms 57824 KB Output is correct
16 Correct 92 ms 55608 KB Output is correct
17 Correct 102 ms 57704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 51180 KB Output is correct
2 Correct 48 ms 51140 KB Output is correct
3 Correct 65 ms 51404 KB Output is correct
4 Correct 61 ms 53000 KB Output is correct
5 Correct 90 ms 56288 KB Output is correct
6 Correct 91 ms 55632 KB Output is correct
7 Correct 106 ms 56260 KB Output is correct
8 Correct 87 ms 56276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 35552 KB Output is correct
2 Correct 18 ms 35524 KB Output is correct
3 Correct 20 ms 35548 KB Output is correct
4 Correct 18 ms 35520 KB Output is correct
5 Correct 17 ms 35548 KB Output is correct
6 Correct 18 ms 35500 KB Output is correct
7 Correct 17 ms 35532 KB Output is correct
8 Correct 17 ms 35476 KB Output is correct
9 Correct 18 ms 35572 KB Output is correct
10 Correct 20 ms 35808 KB Output is correct
11 Correct 19 ms 35544 KB Output is correct
12 Correct 18 ms 35604 KB Output is correct
13 Correct 19 ms 35532 KB Output is correct
14 Correct 18 ms 35552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 35552 KB Output is correct
2 Correct 18 ms 35524 KB Output is correct
3 Correct 20 ms 35548 KB Output is correct
4 Correct 18 ms 35520 KB Output is correct
5 Correct 17 ms 35548 KB Output is correct
6 Correct 18 ms 35500 KB Output is correct
7 Correct 17 ms 35532 KB Output is correct
8 Correct 17 ms 35476 KB Output is correct
9 Correct 18 ms 35572 KB Output is correct
10 Correct 20 ms 35808 KB Output is correct
11 Correct 19 ms 35544 KB Output is correct
12 Correct 18 ms 35604 KB Output is correct
13 Correct 19 ms 35532 KB Output is correct
14 Correct 18 ms 35552 KB Output is correct
15 Correct 22 ms 35600 KB Output is correct
16 Correct 24 ms 35668 KB Output is correct
17 Correct 50 ms 40024 KB Output is correct
18 Correct 34 ms 40012 KB Output is correct
19 Correct 46 ms 39884 KB Output is correct
20 Correct 34 ms 39888 KB Output is correct
21 Correct 36 ms 39876 KB Output is correct
22 Correct 52 ms 44240 KB Output is correct
23 Correct 23 ms 36572 KB Output is correct
24 Correct 34 ms 38876 KB Output is correct
25 Correct 19 ms 35720 KB Output is correct
26 Correct 26 ms 36436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 35552 KB Output is correct
2 Correct 18 ms 35524 KB Output is correct
3 Correct 20 ms 35548 KB Output is correct
4 Correct 18 ms 35520 KB Output is correct
5 Correct 17 ms 35548 KB Output is correct
6 Correct 18 ms 35500 KB Output is correct
7 Correct 17 ms 35532 KB Output is correct
8 Correct 17 ms 35476 KB Output is correct
9 Correct 18 ms 35572 KB Output is correct
10 Correct 20 ms 35808 KB Output is correct
11 Correct 19 ms 35544 KB Output is correct
12 Correct 18 ms 35604 KB Output is correct
13 Correct 19 ms 35532 KB Output is correct
14 Correct 18 ms 35552 KB Output is correct
15 Correct 22 ms 35600 KB Output is correct
16 Correct 24 ms 35668 KB Output is correct
17 Correct 50 ms 40024 KB Output is correct
18 Correct 34 ms 40012 KB Output is correct
19 Correct 46 ms 39884 KB Output is correct
20 Correct 34 ms 39888 KB Output is correct
21 Correct 36 ms 39876 KB Output is correct
22 Correct 52 ms 44240 KB Output is correct
23 Correct 23 ms 36572 KB Output is correct
24 Correct 34 ms 38876 KB Output is correct
25 Correct 19 ms 35720 KB Output is correct
26 Correct 26 ms 36436 KB Output is correct
27 Correct 20 ms 36180 KB Output is correct
28 Correct 130 ms 57384 KB Output is correct
29 Correct 199 ms 65784 KB Output is correct
30 Correct 170 ms 71944 KB Output is correct
31 Correct 174 ms 71876 KB Output is correct
32 Correct 155 ms 65024 KB Output is correct
33 Correct 170 ms 72208 KB Output is correct
34 Correct 166 ms 72212 KB Output is correct
35 Correct 87 ms 49172 KB Output is correct
36 Correct 200 ms 70968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 51180 KB Output is correct
2 Correct 48 ms 51140 KB Output is correct
3 Correct 65 ms 51404 KB Output is correct
4 Correct 61 ms 53000 KB Output is correct
5 Correct 90 ms 56288 KB Output is correct
6 Correct 91 ms 55632 KB Output is correct
7 Correct 106 ms 56260 KB Output is correct
8 Correct 87 ms 56276 KB Output is correct
9 Correct 92 ms 60764 KB Output is correct
10 Correct 69 ms 51668 KB Output is correct
11 Correct 140 ms 67944 KB Output is correct
12 Correct 19 ms 35540 KB Output is correct
13 Correct 18 ms 35544 KB Output is correct
14 Correct 27 ms 35448 KB Output is correct
15 Correct 20 ms 35672 KB Output is correct
16 Correct 18 ms 35412 KB Output is correct
17 Correct 19 ms 35552 KB Output is correct
18 Correct 58 ms 51104 KB Output is correct
19 Correct 49 ms 51184 KB Output is correct
20 Correct 51 ms 51144 KB Output is correct
21 Correct 51 ms 51180 KB Output is correct
22 Correct 98 ms 62432 KB Output is correct
23 Correct 139 ms 70264 KB Output is correct
24 Correct 143 ms 70980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 55544 KB Output is correct
2 Correct 101 ms 58196 KB Output is correct
3 Correct 49 ms 51112 KB Output is correct
4 Correct 47 ms 51144 KB Output is correct
5 Correct 205 ms 73108 KB Output is correct
6 Correct 260 ms 81684 KB Output is correct
7 Correct 19 ms 35512 KB Output is correct
8 Correct 144 ms 61512 KB Output is correct
9 Correct 162 ms 65276 KB Output is correct
10 Correct 97 ms 55480 KB Output is correct
11 Correct 101 ms 58160 KB Output is correct
12 Correct 19 ms 35500 KB Output is correct
13 Correct 22 ms 35452 KB Output is correct
14 Correct 20 ms 35452 KB Output is correct
15 Correct 20 ms 35668 KB Output is correct
16 Correct 46 ms 51180 KB Output is correct
17 Correct 52 ms 51080 KB Output is correct
18 Correct 104 ms 55564 KB Output is correct
19 Correct 103 ms 58196 KB Output is correct
20 Correct 94 ms 55496 KB Output is correct
21 Correct 99 ms 57824 KB Output is correct
22 Correct 92 ms 55608 KB Output is correct
23 Correct 102 ms 57704 KB Output is correct
24 Correct 59 ms 51180 KB Output is correct
25 Correct 48 ms 51140 KB Output is correct
26 Correct 65 ms 51404 KB Output is correct
27 Correct 61 ms 53000 KB Output is correct
28 Correct 90 ms 56288 KB Output is correct
29 Correct 91 ms 55632 KB Output is correct
30 Correct 106 ms 56260 KB Output is correct
31 Correct 87 ms 56276 KB Output is correct
32 Correct 19 ms 35552 KB Output is correct
33 Correct 18 ms 35524 KB Output is correct
34 Correct 20 ms 35548 KB Output is correct
35 Correct 18 ms 35520 KB Output is correct
36 Correct 17 ms 35548 KB Output is correct
37 Correct 18 ms 35500 KB Output is correct
38 Correct 17 ms 35532 KB Output is correct
39 Correct 17 ms 35476 KB Output is correct
40 Correct 18 ms 35572 KB Output is correct
41 Correct 20 ms 35808 KB Output is correct
42 Correct 19 ms 35544 KB Output is correct
43 Correct 18 ms 35604 KB Output is correct
44 Correct 19 ms 35532 KB Output is correct
45 Correct 18 ms 35552 KB Output is correct
46 Correct 22 ms 35600 KB Output is correct
47 Correct 24 ms 35668 KB Output is correct
48 Correct 50 ms 40024 KB Output is correct
49 Correct 34 ms 40012 KB Output is correct
50 Correct 46 ms 39884 KB Output is correct
51 Correct 34 ms 39888 KB Output is correct
52 Correct 36 ms 39876 KB Output is correct
53 Correct 52 ms 44240 KB Output is correct
54 Correct 23 ms 36572 KB Output is correct
55 Correct 34 ms 38876 KB Output is correct
56 Correct 19 ms 35720 KB Output is correct
57 Correct 26 ms 36436 KB Output is correct
58 Correct 20 ms 36180 KB Output is correct
59 Correct 130 ms 57384 KB Output is correct
60 Correct 199 ms 65784 KB Output is correct
61 Correct 170 ms 71944 KB Output is correct
62 Correct 174 ms 71876 KB Output is correct
63 Correct 155 ms 65024 KB Output is correct
64 Correct 170 ms 72208 KB Output is correct
65 Correct 166 ms 72212 KB Output is correct
66 Correct 87 ms 49172 KB Output is correct
67 Correct 200 ms 70968 KB Output is correct
68 Correct 92 ms 60764 KB Output is correct
69 Correct 69 ms 51668 KB Output is correct
70 Correct 140 ms 67944 KB Output is correct
71 Correct 19 ms 35540 KB Output is correct
72 Correct 18 ms 35544 KB Output is correct
73 Correct 27 ms 35448 KB Output is correct
74 Correct 20 ms 35672 KB Output is correct
75 Correct 18 ms 35412 KB Output is correct
76 Correct 19 ms 35552 KB Output is correct
77 Correct 58 ms 51104 KB Output is correct
78 Correct 49 ms 51184 KB Output is correct
79 Correct 51 ms 51144 KB Output is correct
80 Correct 51 ms 51180 KB Output is correct
81 Correct 98 ms 62432 KB Output is correct
82 Correct 139 ms 70264 KB Output is correct
83 Correct 143 ms 70980 KB Output is correct
84 Correct 248 ms 83812 KB Output is correct
85 Correct 249 ms 84756 KB Output is correct
86 Correct 203 ms 85356 KB Output is correct
87 Correct 236 ms 87104 KB Output is correct
88 Correct 19 ms 35476 KB Output is correct
89 Correct 221 ms 87032 KB Output is correct
90 Correct 202 ms 83708 KB Output is correct
91 Correct 182 ms 80024 KB Output is correct