Submission #1056004

# Submission time Handle Problem Language Result Execution time Memory
1056004 2024-08-13T07:05:15 Z parsadox2 Catfish Farm (IOI22_fish) C++17
100 / 100
109 ms 38364 KB
#include "fish.h"
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

const int N = 1e5 + 10;
int n , m , sz[N];
vector <pair<int , int>> all[N];
vector <long long> dp[2][N];

long long max_weights(int nn , int mm , vector <int> X , vector <int> Y , vector <int> W)
{
	n = nn;
	m = mm;
	for(int i = 0 ; i < n ; i++)
		all[i].push_back({0 , 0});
	for(int i = 0 ; i < m ; i++)
		all[X[i]].push_back(make_pair(Y[i] , W[i]));
	for(int i = 0 ; i < n ; i++)
		all[i].push_back({n , 0});
	for(int i = 0 ; i < n ; i++)
	{
		sort(all[i].begin() , all[i].end());
		sz[i] = all[i].size();
		dp[0][i].resize(sz[i] , 0);
		dp[1][i].resize(sz[i] , 0);
	}
	long long ans = 0;
	for(int i = 1 ; i < n ; i++)
	{
		long long mx = 0;
		for(auto u : dp[0][i - 1])
			mx = max(mx , u);
		for(auto u : dp[1][i - 1])
			mx = max(mx , u);
		int pos = 0;
		long long val_down = 0;
		for(int j = 0 ; j < sz[i] ; j++)
		{
			while(pos != sz[i - 1] && all[i - 1][pos].F < all[i][j].F)
			{
				val_down = max(val_down , dp[0][i - 1][pos]);
				val_down += all[i - 1][pos].S;
				pos++;
			}
			dp[0][i][j] = max(dp[0][i][j] , (max(mx , val_down)));
			dp[1][i][j] = max(dp[1][i][j] , (max(mx , val_down)));
		}
		long long val_up = 0;
		pos = sz[i - 1] - 1;
		for(int j = sz[i] - 1 ; j >= 0 ; j--)
		{
			while(pos >= 0 && all[i - 1][pos].F > all[i][j].F)
			{
				val_up = max(val_up , dp[1][i - 1][pos]);
				pos--;
			}
			val_up += all[i][j].S;
			dp[1][i][j] = max(dp[1][i][j] , val_up);
			ans = max(ans , dp[1][i][j]);
			ans = max(ans , dp[0][i][j]);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 20872 KB Output is correct
2 Correct 38 ms 22992 KB Output is correct
3 Correct 15 ms 17244 KB Output is correct
4 Correct 14 ms 17060 KB Output is correct
5 Correct 85 ms 34592 KB Output is correct
6 Correct 109 ms 35664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 49 ms 25448 KB Output is correct
3 Correct 59 ms 30144 KB Output is correct
4 Correct 31 ms 21448 KB Output is correct
5 Correct 36 ms 23500 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 2 ms 7488 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 15 ms 17240 KB Output is correct
11 Correct 15 ms 17244 KB Output is correct
12 Correct 35 ms 21444 KB Output is correct
13 Correct 42 ms 23504 KB Output is correct
14 Correct 36 ms 21448 KB Output is correct
15 Correct 36 ms 22984 KB Output is correct
16 Correct 40 ms 21376 KB Output is correct
17 Correct 34 ms 22968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17244 KB Output is correct
2 Correct 14 ms 17244 KB Output is correct
3 Correct 25 ms 19292 KB Output is correct
4 Correct 24 ms 19288 KB Output is correct
5 Correct 40 ms 22704 KB Output is correct
6 Correct 37 ms 22228 KB Output is correct
7 Correct 43 ms 22520 KB Output is correct
8 Correct 37 ms 22608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7488 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7492 KB Output is correct
8 Correct 3 ms 7304 KB Output is correct
9 Correct 3 ms 7512 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7256 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7488 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7492 KB Output is correct
8 Correct 3 ms 7304 KB Output is correct
9 Correct 3 ms 7512 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7256 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 11 ms 10324 KB Output is correct
18 Correct 11 ms 10712 KB Output is correct
19 Correct 12 ms 10588 KB Output is correct
20 Correct 11 ms 10588 KB Output is correct
21 Correct 11 ms 10588 KB Output is correct
22 Correct 20 ms 13660 KB Output is correct
23 Correct 4 ms 8024 KB Output is correct
24 Correct 11 ms 9308 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 4 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7488 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7492 KB Output is correct
8 Correct 3 ms 7304 KB Output is correct
9 Correct 3 ms 7512 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7256 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 11 ms 10324 KB Output is correct
18 Correct 11 ms 10712 KB Output is correct
19 Correct 12 ms 10588 KB Output is correct
20 Correct 11 ms 10588 KB Output is correct
21 Correct 11 ms 10588 KB Output is correct
22 Correct 20 ms 13660 KB Output is correct
23 Correct 4 ms 8024 KB Output is correct
24 Correct 11 ms 9308 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 4 ms 8024 KB Output is correct
27 Correct 3 ms 7772 KB Output is correct
28 Correct 57 ms 22680 KB Output is correct
29 Correct 66 ms 28244 KB Output is correct
30 Correct 85 ms 28132 KB Output is correct
31 Correct 67 ms 28244 KB Output is correct
32 Correct 60 ms 29040 KB Output is correct
33 Correct 66 ms 28244 KB Output is correct
34 Correct 66 ms 28252 KB Output is correct
35 Correct 28 ms 15708 KB Output is correct
36 Correct 65 ms 28796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17244 KB Output is correct
2 Correct 14 ms 17244 KB Output is correct
3 Correct 25 ms 19292 KB Output is correct
4 Correct 24 ms 19288 KB Output is correct
5 Correct 40 ms 22704 KB Output is correct
6 Correct 37 ms 22228 KB Output is correct
7 Correct 43 ms 22520 KB Output is correct
8 Correct 37 ms 22608 KB Output is correct
9 Correct 40 ms 22720 KB Output is correct
10 Correct 30 ms 18356 KB Output is correct
11 Correct 60 ms 30824 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7256 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 4 ms 7312 KB Output is correct
17 Correct 2 ms 7260 KB Output is correct
18 Correct 19 ms 17244 KB Output is correct
19 Correct 14 ms 17244 KB Output is correct
20 Correct 15 ms 17244 KB Output is correct
21 Correct 14 ms 17216 KB Output is correct
22 Correct 39 ms 23900 KB Output is correct
23 Correct 66 ms 30800 KB Output is correct
24 Correct 74 ms 31312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 20872 KB Output is correct
2 Correct 38 ms 22992 KB Output is correct
3 Correct 15 ms 17244 KB Output is correct
4 Correct 14 ms 17060 KB Output is correct
5 Correct 85 ms 34592 KB Output is correct
6 Correct 109 ms 35664 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 49 ms 25448 KB Output is correct
9 Correct 59 ms 30144 KB Output is correct
10 Correct 31 ms 21448 KB Output is correct
11 Correct 36 ms 23500 KB Output is correct
12 Correct 3 ms 7260 KB Output is correct
13 Correct 2 ms 7488 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 15 ms 17240 KB Output is correct
17 Correct 15 ms 17244 KB Output is correct
18 Correct 35 ms 21444 KB Output is correct
19 Correct 42 ms 23504 KB Output is correct
20 Correct 36 ms 21448 KB Output is correct
21 Correct 36 ms 22984 KB Output is correct
22 Correct 40 ms 21376 KB Output is correct
23 Correct 34 ms 22968 KB Output is correct
24 Correct 15 ms 17244 KB Output is correct
25 Correct 14 ms 17244 KB Output is correct
26 Correct 25 ms 19292 KB Output is correct
27 Correct 24 ms 19288 KB Output is correct
28 Correct 40 ms 22704 KB Output is correct
29 Correct 37 ms 22228 KB Output is correct
30 Correct 43 ms 22520 KB Output is correct
31 Correct 37 ms 22608 KB Output is correct
32 Correct 3 ms 7260 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 3 ms 7260 KB Output is correct
35 Correct 3 ms 7488 KB Output is correct
36 Correct 3 ms 7256 KB Output is correct
37 Correct 3 ms 7260 KB Output is correct
38 Correct 3 ms 7492 KB Output is correct
39 Correct 3 ms 7304 KB Output is correct
40 Correct 3 ms 7512 KB Output is correct
41 Correct 3 ms 7516 KB Output is correct
42 Correct 2 ms 7516 KB Output is correct
43 Correct 3 ms 7512 KB Output is correct
44 Correct 3 ms 7256 KB Output is correct
45 Correct 3 ms 7512 KB Output is correct
46 Correct 3 ms 7516 KB Output is correct
47 Correct 3 ms 7516 KB Output is correct
48 Correct 11 ms 10324 KB Output is correct
49 Correct 11 ms 10712 KB Output is correct
50 Correct 12 ms 10588 KB Output is correct
51 Correct 11 ms 10588 KB Output is correct
52 Correct 11 ms 10588 KB Output is correct
53 Correct 20 ms 13660 KB Output is correct
54 Correct 4 ms 8024 KB Output is correct
55 Correct 11 ms 9308 KB Output is correct
56 Correct 3 ms 7516 KB Output is correct
57 Correct 4 ms 8024 KB Output is correct
58 Correct 3 ms 7772 KB Output is correct
59 Correct 57 ms 22680 KB Output is correct
60 Correct 66 ms 28244 KB Output is correct
61 Correct 85 ms 28132 KB Output is correct
62 Correct 67 ms 28244 KB Output is correct
63 Correct 60 ms 29040 KB Output is correct
64 Correct 66 ms 28244 KB Output is correct
65 Correct 66 ms 28252 KB Output is correct
66 Correct 28 ms 15708 KB Output is correct
67 Correct 65 ms 28796 KB Output is correct
68 Correct 40 ms 22720 KB Output is correct
69 Correct 30 ms 18356 KB Output is correct
70 Correct 60 ms 30824 KB Output is correct
71 Correct 2 ms 7260 KB Output is correct
72 Correct 2 ms 7256 KB Output is correct
73 Correct 2 ms 7260 KB Output is correct
74 Correct 2 ms 7260 KB Output is correct
75 Correct 4 ms 7312 KB Output is correct
76 Correct 2 ms 7260 KB Output is correct
77 Correct 19 ms 17244 KB Output is correct
78 Correct 14 ms 17244 KB Output is correct
79 Correct 15 ms 17244 KB Output is correct
80 Correct 14 ms 17216 KB Output is correct
81 Correct 39 ms 23900 KB Output is correct
82 Correct 66 ms 30800 KB Output is correct
83 Correct 74 ms 31312 KB Output is correct
84 Correct 81 ms 36528 KB Output is correct
85 Correct 88 ms 37124 KB Output is correct
86 Correct 84 ms 37196 KB Output is correct
87 Correct 96 ms 38260 KB Output is correct
88 Correct 2 ms 7260 KB Output is correct
89 Correct 108 ms 38364 KB Output is correct
90 Correct 85 ms 37200 KB Output is correct
91 Correct 80 ms 37460 KB Output is correct