Submission #778621

# Submission time Handle Problem Language Result Execution time Memory
778621 2023-07-10T13:40:23 Z Tekor Catfish Farm (IOI22_fish) C++17
100 / 100
403 ms 90708 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define en '\n'
#define pii pair <int,int>
#define mp make_pair
#define f first
#define s second
#define all(v) v.begin(),v.end()
const int N = 1e5 + 10;
const ll LLINF = (ll)1e18;
vector <pair <int,ll>> g[N];
vector <ll> dp[N],dp1[N];
map <int,bool> was[N];
ll max_weights(int n, int m, vector <int> X, vector <int> Y, vector <int> W) {
	for(int i = 0;i < m;i++) {
		g[X[i]].pb(mp(Y[i] + 1,W[i]));
		was[X[i]][Y[i] + 1] = 1;
	}
	for(int i = 0;i < n;i++) {
		int k = g[i].size();
		for(int j = 0;j < k;j++) {
			if(g[i][j].f > 1 && !was[i][g[i][j].f - 1]) {
				was[i][g[i][j].f - 1] = 1;
				g[i].pb(mp(g[i][j].f - 1,0));
			}
		}
		g[i].pb(mp(0,0));
		sort(all(g[i]));
		if(g[i].back().f != n)g[i].pb(mp(n,0));
		for(int j = 1;j <= (int)g[i].size();j++) {
			dp[i].pb(0);
			dp1[i].pb(0);
		}
	}
	ll ans = 0;
	for(int i = 1;i < n;i++) {
		ll typ1mx = -LLINF,typ2mx = -LLINF;
		int R = 0;
		ll cur = 0,cur1 = 0;
		for(int j = 0;j < g[i - 1].size();j++) {
			auto to = g[i - 1][j];
			cur1 += to.s;
			while(R < g[i].size() && to.f >= g[i][R].f) {
				cur += g[i][R].s;
				R++;
			}
			typ1mx = max(typ1mx,dp[i - 1][j] + cur);
			typ2mx = max(typ2mx,dp1[i - 1][j] - cur1);
		}
		cur = 0,cur1 = 0;
		R = 0;
		ll tek = 0,sum = 0;
		for(int j = 0;j < g[i].size();j++) {
			auto to = g[i][j];
			while(R < g[i - 1].size() && to.f >= g[i - 1][R].f) {
				if(to.f > g[i - 1][R].f) {
					tek = max(tek,dp[i - 1][R] + sum);
				}else {
					tek = max(tek,dp[i - 1][R] + sum + to.s);
				}
				cur += g[i - 1][R].s;
				R++;
			}
			sum += to.s;
			dp[i][j] = ans;
//			dp1[i][j] = ans;
			dp[i][j] = max(dp[i][j],typ1mx - sum);
			dp[i][j] = max(dp[i][j],typ2mx + cur);
			dp1[i][j] = max(dp1[i][j],typ2mx + cur);
			while(R < g[i - 1].size() && (to.f != n ? g[i][j + 1].f : n + 1) > g[i - 1][R].f) {
				cur += g[i - 1][R].s;
				tek = max(tek,dp[i - 1][R] + sum);
				R++;
			}
			dp1[i][j] = max(dp1[i][j],tek);
		}
//		cout << i << " " << typ1mx << " " << typ2mx << " gooo " << en;
		for(int j = 0;j < g[i].size();j++) {
			ans = max(ans,dp[i][j]);
			ans = max(ans,dp1[i][j]);
//			cout << dp[i][j] << " " << dp1[i][j] << " " << g[i][j].f << en;
		}
//		cout << ans << en;
	}
	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:44: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]
   44 |   for(int j = 0;j < g[i - 1].size();j++) {
      |                 ~~^~~~~~~~~~~~~~~~~
fish.cpp:47: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]
   47 |    while(R < g[i].size() && to.f >= g[i][R].f) {
      |          ~~^~~~~~~~~~~~~
fish.cpp:57: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]
   57 |   for(int j = 0;j < g[i].size();j++) {
      |                 ~~^~~~~~~~~~~~~
fish.cpp:59: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]
   59 |    while(R < g[i - 1].size() && to.f >= g[i - 1][R].f) {
      |          ~~^~~~~~~~~~~~~~~~~
fish.cpp:74: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]
   74 |    while(R < g[i - 1].size() && (to.f != n ? g[i][j + 1].f : n + 1) > g[i - 1][R].f) {
      |          ~~^~~~~~~~~~~~~~~~~
fish.cpp:82: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]
   82 |   for(int j = 0;j < g[i].size();j++) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 97 ms 30780 KB Output is correct
2 Correct 111 ms 33080 KB Output is correct
3 Correct 30 ms 22996 KB Output is correct
4 Correct 30 ms 22996 KB Output is correct
5 Correct 347 ms 56864 KB Output is correct
6 Correct 371 ms 84556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 174 ms 40120 KB Output is correct
3 Correct 212 ms 46856 KB Output is correct
4 Correct 94 ms 32164 KB Output is correct
5 Correct 109 ms 34868 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12044 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 30 ms 22860 KB Output is correct
11 Correct 30 ms 22964 KB Output is correct
12 Correct 97 ms 32096 KB Output is correct
13 Correct 111 ms 34812 KB Output is correct
14 Correct 94 ms 32432 KB Output is correct
15 Correct 120 ms 34648 KB Output is correct
16 Correct 92 ms 32300 KB Output is correct
17 Correct 103 ms 34620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 22984 KB Output is correct
2 Correct 30 ms 22956 KB Output is correct
3 Correct 64 ms 29452 KB Output is correct
4 Correct 52 ms 27988 KB Output is correct
5 Correct 99 ms 39836 KB Output is correct
6 Correct 92 ms 39692 KB Output is correct
7 Correct 98 ms 39884 KB Output is correct
8 Correct 93 ms 39888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12048 KB Output is correct
8 Correct 6 ms 11928 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12360 KB Output is correct
11 Correct 6 ms 12116 KB Output is correct
12 Correct 6 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 6 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12048 KB Output is correct
8 Correct 6 ms 11928 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12360 KB Output is correct
11 Correct 6 ms 12116 KB Output is correct
12 Correct 6 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 6 ms 12116 KB Output is correct
15 Correct 6 ms 12116 KB Output is correct
16 Correct 7 ms 12312 KB Output is correct
17 Correct 35 ms 19440 KB Output is correct
18 Correct 33 ms 18828 KB Output is correct
19 Correct 31 ms 18324 KB Output is correct
20 Correct 32 ms 18328 KB Output is correct
21 Correct 31 ms 18348 KB Output is correct
22 Correct 60 ms 24716 KB Output is correct
23 Correct 12 ms 13972 KB Output is correct
24 Correct 27 ms 18004 KB Output is correct
25 Correct 7 ms 12244 KB Output is correct
26 Correct 11 ms 13652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12048 KB Output is correct
8 Correct 6 ms 11928 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12360 KB Output is correct
11 Correct 6 ms 12116 KB Output is correct
12 Correct 6 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 6 ms 12116 KB Output is correct
15 Correct 6 ms 12116 KB Output is correct
16 Correct 7 ms 12312 KB Output is correct
17 Correct 35 ms 19440 KB Output is correct
18 Correct 33 ms 18828 KB Output is correct
19 Correct 31 ms 18324 KB Output is correct
20 Correct 32 ms 18328 KB Output is correct
21 Correct 31 ms 18348 KB Output is correct
22 Correct 60 ms 24716 KB Output is correct
23 Correct 12 ms 13972 KB Output is correct
24 Correct 27 ms 18004 KB Output is correct
25 Correct 7 ms 12244 KB Output is correct
26 Correct 11 ms 13652 KB Output is correct
27 Correct 7 ms 13012 KB Output is correct
28 Correct 184 ms 44288 KB Output is correct
29 Correct 272 ms 55732 KB Output is correct
30 Correct 288 ms 76472 KB Output is correct
31 Correct 289 ms 76220 KB Output is correct
32 Correct 230 ms 54604 KB Output is correct
33 Correct 272 ms 76724 KB Output is correct
34 Correct 266 ms 76728 KB Output is correct
35 Correct 89 ms 35664 KB Output is correct
36 Correct 306 ms 69812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 22984 KB Output is correct
2 Correct 30 ms 22956 KB Output is correct
3 Correct 64 ms 29452 KB Output is correct
4 Correct 52 ms 27988 KB Output is correct
5 Correct 99 ms 39836 KB Output is correct
6 Correct 92 ms 39692 KB Output is correct
7 Correct 98 ms 39884 KB Output is correct
8 Correct 93 ms 39888 KB Output is correct
9 Correct 95 ms 44584 KB Output is correct
10 Correct 67 ms 30084 KB Output is correct
11 Correct 164 ms 48288 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 11972 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 5 ms 12044 KB Output is correct
16 Correct 5 ms 11988 KB Output is correct
17 Correct 9 ms 12036 KB Output is correct
18 Correct 27 ms 22972 KB Output is correct
19 Correct 30 ms 23000 KB Output is correct
20 Correct 29 ms 22992 KB Output is correct
21 Correct 29 ms 22892 KB Output is correct
22 Correct 119 ms 45072 KB Output is correct
23 Correct 182 ms 64564 KB Output is correct
24 Correct 165 ms 66084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 30780 KB Output is correct
2 Correct 111 ms 33080 KB Output is correct
3 Correct 30 ms 22996 KB Output is correct
4 Correct 30 ms 22996 KB Output is correct
5 Correct 347 ms 56864 KB Output is correct
6 Correct 371 ms 84556 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 174 ms 40120 KB Output is correct
9 Correct 212 ms 46856 KB Output is correct
10 Correct 94 ms 32164 KB Output is correct
11 Correct 109 ms 34868 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12044 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 30 ms 22860 KB Output is correct
17 Correct 30 ms 22964 KB Output is correct
18 Correct 97 ms 32096 KB Output is correct
19 Correct 111 ms 34812 KB Output is correct
20 Correct 94 ms 32432 KB Output is correct
21 Correct 120 ms 34648 KB Output is correct
22 Correct 92 ms 32300 KB Output is correct
23 Correct 103 ms 34620 KB Output is correct
24 Correct 29 ms 22984 KB Output is correct
25 Correct 30 ms 22956 KB Output is correct
26 Correct 64 ms 29452 KB Output is correct
27 Correct 52 ms 27988 KB Output is correct
28 Correct 99 ms 39836 KB Output is correct
29 Correct 92 ms 39692 KB Output is correct
30 Correct 98 ms 39884 KB Output is correct
31 Correct 93 ms 39888 KB Output is correct
32 Correct 6 ms 11988 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 7 ms 12044 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 6 ms 12048 KB Output is correct
39 Correct 6 ms 11928 KB Output is correct
40 Correct 6 ms 12116 KB Output is correct
41 Correct 7 ms 12360 KB Output is correct
42 Correct 6 ms 12116 KB Output is correct
43 Correct 6 ms 12244 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 6 ms 12116 KB Output is correct
46 Correct 6 ms 12116 KB Output is correct
47 Correct 7 ms 12312 KB Output is correct
48 Correct 35 ms 19440 KB Output is correct
49 Correct 33 ms 18828 KB Output is correct
50 Correct 31 ms 18324 KB Output is correct
51 Correct 32 ms 18328 KB Output is correct
52 Correct 31 ms 18348 KB Output is correct
53 Correct 60 ms 24716 KB Output is correct
54 Correct 12 ms 13972 KB Output is correct
55 Correct 27 ms 18004 KB Output is correct
56 Correct 7 ms 12244 KB Output is correct
57 Correct 11 ms 13652 KB Output is correct
58 Correct 7 ms 13012 KB Output is correct
59 Correct 184 ms 44288 KB Output is correct
60 Correct 272 ms 55732 KB Output is correct
61 Correct 288 ms 76472 KB Output is correct
62 Correct 289 ms 76220 KB Output is correct
63 Correct 230 ms 54604 KB Output is correct
64 Correct 272 ms 76724 KB Output is correct
65 Correct 266 ms 76728 KB Output is correct
66 Correct 89 ms 35664 KB Output is correct
67 Correct 306 ms 69812 KB Output is correct
68 Correct 95 ms 44584 KB Output is correct
69 Correct 67 ms 30084 KB Output is correct
70 Correct 164 ms 48288 KB Output is correct
71 Correct 6 ms 11988 KB Output is correct
72 Correct 6 ms 11972 KB Output is correct
73 Correct 5 ms 11988 KB Output is correct
74 Correct 5 ms 12044 KB Output is correct
75 Correct 5 ms 11988 KB Output is correct
76 Correct 9 ms 12036 KB Output is correct
77 Correct 27 ms 22972 KB Output is correct
78 Correct 30 ms 23000 KB Output is correct
79 Correct 29 ms 22992 KB Output is correct
80 Correct 29 ms 22892 KB Output is correct
81 Correct 119 ms 45072 KB Output is correct
82 Correct 182 ms 64564 KB Output is correct
83 Correct 165 ms 66084 KB Output is correct
84 Correct 402 ms 77376 KB Output is correct
85 Correct 403 ms 81196 KB Output is correct
86 Correct 324 ms 89368 KB Output is correct
87 Correct 315 ms 90700 KB Output is correct
88 Correct 6 ms 11988 KB Output is correct
89 Correct 325 ms 90708 KB Output is correct
90 Correct 311 ms 81760 KB Output is correct
91 Correct 247 ms 68996 KB Output is correct