Submission #785155

# Submission time Handle Problem Language Result Execution time Memory
785155 2023-07-17T06:21:42 Z ono_de206 Catfish Farm (IOI22_fish) C++17
100 / 100
130 ms 31828 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 9024 KB Output is correct
2 Correct 33 ms 10556 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 105 ms 21436 KB Output is correct
6 Correct 104 ms 24444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 16308 KB Output is correct
3 Correct 66 ms 19616 KB Output is correct
4 Correct 28 ms 10428 KB Output is correct
5 Correct 35 ms 12312 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 4908 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 31 ms 10404 KB Output is correct
13 Correct 34 ms 12324 KB Output is correct
14 Correct 31 ms 10480 KB Output is correct
15 Correct 31 ms 11724 KB Output is correct
16 Correct 27 ms 10520 KB Output is correct
17 Correct 31 ms 11688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 22 ms 9044 KB Output is correct
4 Correct 15 ms 8020 KB Output is correct
5 Correct 39 ms 13524 KB Output is correct
6 Correct 38 ms 13492 KB Output is correct
7 Correct 38 ms 13516 KB Output is correct
8 Correct 39 ms 13524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 13 ms 3668 KB Output is correct
18 Correct 13 ms 4308 KB Output is correct
19 Correct 14 ms 4144 KB Output is correct
20 Correct 15 ms 4152 KB Output is correct
21 Correct 13 ms 4084 KB Output is correct
22 Correct 27 ms 8000 KB Output is correct
23 Correct 3 ms 924 KB Output is correct
24 Correct 9 ms 2644 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 13 ms 3668 KB Output is correct
18 Correct 13 ms 4308 KB Output is correct
19 Correct 14 ms 4144 KB Output is correct
20 Correct 15 ms 4152 KB Output is correct
21 Correct 13 ms 4084 KB Output is correct
22 Correct 27 ms 8000 KB Output is correct
23 Correct 3 ms 924 KB Output is correct
24 Correct 9 ms 2644 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 888 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 61 ms 18036 KB Output is correct
29 Correct 95 ms 24920 KB Output is correct
30 Correct 91 ms 24268 KB Output is correct
31 Correct 101 ms 24268 KB Output is correct
32 Correct 84 ms 25552 KB Output is correct
33 Correct 92 ms 24268 KB Output is correct
34 Correct 102 ms 24276 KB Output is correct
35 Correct 35 ms 9716 KB Output is correct
36 Correct 92 ms 25432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 22 ms 9044 KB Output is correct
4 Correct 15 ms 8020 KB Output is correct
5 Correct 39 ms 13524 KB Output is correct
6 Correct 38 ms 13492 KB Output is correct
7 Correct 38 ms 13516 KB Output is correct
8 Correct 39 ms 13524 KB Output is correct
9 Correct 37 ms 13544 KB Output is correct
10 Correct 35 ms 11576 KB Output is correct
11 Correct 75 ms 22988 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4904 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 40 ms 14636 KB Output is correct
23 Correct 77 ms 22988 KB Output is correct
24 Correct 87 ms 23492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 9024 KB Output is correct
2 Correct 33 ms 10556 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 105 ms 21436 KB Output is correct
6 Correct 104 ms 24444 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 53 ms 16308 KB Output is correct
9 Correct 66 ms 19616 KB Output is correct
10 Correct 28 ms 10428 KB Output is correct
11 Correct 35 ms 12312 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 4908 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 31 ms 10404 KB Output is correct
19 Correct 34 ms 12324 KB Output is correct
20 Correct 31 ms 10480 KB Output is correct
21 Correct 31 ms 11724 KB Output is correct
22 Correct 27 ms 10520 KB Output is correct
23 Correct 31 ms 11688 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 5004 KB Output is correct
26 Correct 22 ms 9044 KB Output is correct
27 Correct 15 ms 8020 KB Output is correct
28 Correct 39 ms 13524 KB Output is correct
29 Correct 38 ms 13492 KB Output is correct
30 Correct 38 ms 13516 KB Output is correct
31 Correct 39 ms 13524 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 304 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 312 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 13 ms 3668 KB Output is correct
49 Correct 13 ms 4308 KB Output is correct
50 Correct 14 ms 4144 KB Output is correct
51 Correct 15 ms 4152 KB Output is correct
52 Correct 13 ms 4084 KB Output is correct
53 Correct 27 ms 8000 KB Output is correct
54 Correct 3 ms 924 KB Output is correct
55 Correct 9 ms 2644 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 3 ms 888 KB Output is correct
58 Correct 1 ms 724 KB Output is correct
59 Correct 61 ms 18036 KB Output is correct
60 Correct 95 ms 24920 KB Output is correct
61 Correct 91 ms 24268 KB Output is correct
62 Correct 101 ms 24268 KB Output is correct
63 Correct 84 ms 25552 KB Output is correct
64 Correct 92 ms 24268 KB Output is correct
65 Correct 102 ms 24276 KB Output is correct
66 Correct 35 ms 9716 KB Output is correct
67 Correct 92 ms 25432 KB Output is correct
68 Correct 37 ms 13544 KB Output is correct
69 Correct 35 ms 11576 KB Output is correct
70 Correct 75 ms 22988 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 300 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 296 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4904 KB Output is correct
79 Correct 3 ms 4948 KB Output is correct
80 Correct 3 ms 4948 KB Output is correct
81 Correct 40 ms 14636 KB Output is correct
82 Correct 77 ms 22988 KB Output is correct
83 Correct 87 ms 23492 KB Output is correct
84 Correct 98 ms 27308 KB Output is correct
85 Correct 101 ms 27392 KB Output is correct
86 Correct 130 ms 30912 KB Output is correct
87 Correct 123 ms 31824 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 124 ms 31828 KB Output is correct
90 Correct 109 ms 29772 KB Output is correct
91 Correct 101 ms 29220 KB Output is correct