Submission #785156

# Submission time Handle Problem Language Result Execution time Memory
785156 2023-07-17T06:22:11 Z vjudge1 Catfish Farm (IOI22_fish) C++17
100 / 100
121 ms 25444 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>
void mxx(T &a, T b) {
	if(a < b) a = b;
}

long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {
	vector<vector<pair<int, long long>>> pos(n);
	for(int i = 0; i < m; i++) {
		pos[X[i]].eb(Y[i], W[i]);
	}
	vector<vector<pair<long long, long long>>> dp(n);
	for(int i = 0; i < n; i++) {
		sort(all(pos[i]));
		dp[i].resize(pos[i].size(), make_pair(0, 0));
	}
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		int sz = (int)pos[i].size();

		int r = (int)pos[i - 1].size() - 1;
		for(int j = sz - 1; j >= 0; j--) {
			dp[i][j].ss = ans + pos[i][j].ss;
			if(j + 1 < sz) mxx(dp[i][j].ss, dp[i][j + 1].ss + pos[i][j].ss);
			while(r >= 0 && pos[i - 1][r].ff > pos[i][j].ff) {
				mxx(dp[i][j].ss, max(dp[i - 1][r].ff, dp[i - 1][r].ss) + pos[i][j].ss);
				r--;
			}
		}

		for(int j = 0; j < (int)pos[i - 1].size(); j++) {
			mxx(ans, dp[i - 1][j].ss);
		}

		int l = 0;
		for(int j = 0; j < sz; j++) {
			if(j) dp[i][j].ff = dp[i][j - 1].ff;
			while(l < pos[i - 1].size() && pos[i - 1][l].ff < pos[i][j].ff) {
				dp[i][j].ff += pos[i - 1][l].ss;
				mxx(dp[i][j].ff, dp[i - 1][l].ff + pos[i - 1][l].ss);
				l++;
			}
		}

		for(int j = 0; j < sz; j++) {
			mxx(dp[i][j].ff, ans);
		}

		long long sum = 0;
		for(int j = (int)pos[i - 1].size() - 1; j >= 0; j--) {
			sum += pos[i - 1][j].ss;
			mxx(ans, dp[i - 1][j].ff + sum);
		}
	}
	for(int j = 0; j < pos.back().size(); j++) {
		mxx(ans, dp.back()[j].ss);
	}
	return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:57:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |    while(l < pos[i - 1].size() && pos[i - 1][l].ff < pos[i][j].ff) {
      |          ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(int j = 0; j < pos.back().size(); j++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 9028 KB Output is correct
2 Correct 32 ms 10536 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 98 ms 21444 KB Output is correct
6 Correct 104 ms 24560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 61 ms 13452 KB Output is correct
3 Correct 63 ms 16168 KB Output is correct
4 Correct 26 ms 9080 KB Output is correct
5 Correct 32 ms 10592 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 26 ms 9032 KB Output is correct
13 Correct 33 ms 10596 KB Output is correct
14 Correct 26 ms 9080 KB Output is correct
15 Correct 30 ms 10092 KB Output is correct
16 Correct 27 ms 9188 KB Output is correct
17 Correct 29 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 22 ms 9156 KB Output is correct
4 Correct 17 ms 8036 KB Output is correct
5 Correct 50 ms 13556 KB Output is correct
6 Correct 42 ms 13624 KB Output is correct
7 Correct 39 ms 13512 KB Output is correct
8 Correct 38 ms 13516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 12 ms 3024 KB Output is correct
18 Correct 13 ms 3476 KB Output is correct
19 Correct 13 ms 3396 KB Output is correct
20 Correct 12 ms 3396 KB Output is correct
21 Correct 12 ms 3360 KB Output is correct
22 Correct 24 ms 6484 KB Output is correct
23 Correct 3 ms 788 KB Output is correct
24 Correct 9 ms 2132 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 12 ms 3024 KB Output is correct
18 Correct 13 ms 3476 KB Output is correct
19 Correct 13 ms 3396 KB Output is correct
20 Correct 12 ms 3396 KB Output is correct
21 Correct 12 ms 3360 KB Output is correct
22 Correct 24 ms 6484 KB Output is correct
23 Correct 3 ms 788 KB Output is correct
24 Correct 9 ms 2132 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 60 ms 14228 KB Output is correct
29 Correct 87 ms 19296 KB Output is correct
30 Correct 91 ms 18672 KB Output is correct
31 Correct 90 ms 18656 KB Output is correct
32 Correct 82 ms 20464 KB Output is correct
33 Correct 91 ms 18660 KB Output is correct
34 Correct 88 ms 18672 KB Output is correct
35 Correct 34 ms 7812 KB Output is correct
36 Correct 86 ms 19820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 22 ms 9156 KB Output is correct
4 Correct 17 ms 8036 KB Output is correct
5 Correct 50 ms 13556 KB Output is correct
6 Correct 42 ms 13624 KB Output is correct
7 Correct 39 ms 13512 KB Output is correct
8 Correct 38 ms 13516 KB Output is correct
9 Correct 39 ms 13516 KB Output is correct
10 Correct 46 ms 9928 KB Output is correct
11 Correct 78 ms 19504 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 39 ms 12488 KB Output is correct
23 Correct 72 ms 19548 KB Output is correct
24 Correct 79 ms 19536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 9028 KB Output is correct
2 Correct 32 ms 10536 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 98 ms 21444 KB Output is correct
6 Correct 104 ms 24560 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 61 ms 13452 KB Output is correct
9 Correct 63 ms 16168 KB Output is correct
10 Correct 26 ms 9080 KB Output is correct
11 Correct 32 ms 10592 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 26 ms 9032 KB Output is correct
19 Correct 33 ms 10596 KB Output is correct
20 Correct 26 ms 9080 KB Output is correct
21 Correct 30 ms 10092 KB Output is correct
22 Correct 27 ms 9188 KB Output is correct
23 Correct 29 ms 10076 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 22 ms 9156 KB Output is correct
27 Correct 17 ms 8036 KB Output is correct
28 Correct 50 ms 13556 KB Output is correct
29 Correct 42 ms 13624 KB Output is correct
30 Correct 39 ms 13512 KB Output is correct
31 Correct 38 ms 13516 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 12 ms 3024 KB Output is correct
49 Correct 13 ms 3476 KB Output is correct
50 Correct 13 ms 3396 KB Output is correct
51 Correct 12 ms 3396 KB Output is correct
52 Correct 12 ms 3360 KB Output is correct
53 Correct 24 ms 6484 KB Output is correct
54 Correct 3 ms 788 KB Output is correct
55 Correct 9 ms 2132 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 1 ms 588 KB Output is correct
59 Correct 60 ms 14228 KB Output is correct
60 Correct 87 ms 19296 KB Output is correct
61 Correct 91 ms 18672 KB Output is correct
62 Correct 90 ms 18656 KB Output is correct
63 Correct 82 ms 20464 KB Output is correct
64 Correct 91 ms 18660 KB Output is correct
65 Correct 88 ms 18672 KB Output is correct
66 Correct 34 ms 7812 KB Output is correct
67 Correct 86 ms 19820 KB Output is correct
68 Correct 39 ms 13516 KB Output is correct
69 Correct 46 ms 9928 KB Output is correct
70 Correct 78 ms 19504 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 3 ms 4948 KB Output is correct
80 Correct 3 ms 4948 KB Output is correct
81 Correct 39 ms 12488 KB Output is correct
82 Correct 72 ms 19548 KB Output is correct
83 Correct 79 ms 19536 KB Output is correct
84 Correct 95 ms 21476 KB Output is correct
85 Correct 94 ms 22028 KB Output is correct
86 Correct 114 ms 24660 KB Output is correct
87 Correct 116 ms 25420 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 121 ms 25444 KB Output is correct
90 Correct 102 ms 24428 KB Output is correct
91 Correct 97 ms 24036 KB Output is correct