Submission #967298

# Submission time Handle Problem Language Result Execution time Memory
967298 2024-04-21T18:23:01 Z ZeroCool Catfish Farm (IOI22_fish) C++17
100 / 100
242 ms 47992 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using ll = long long;

const ll N = 3e5 + 10;
const ll INF = 1e17;

ll n, m;

vector<pair<ll,ll> > fish[N];



ll get(ll x,ll y){
	return (upper_bound(all(fish[x]), make_pair(y, INF)) - 1)->second;
}

vector<ll> A[N];

ll max_weights(int nn, int mm, vector<int> X, vector<int> Y,vector<int> W) {
	n = nn;
	m = mm;
	
	for(ll i =0 ;i<m;i++){
		fish[X[i] + 1].pb({Y[i], W[i]});
	}
	
	fish[0] = {make_pair(-1, 0)};
	
	for(ll i = 1;i<=n;i++){
		fish[i].pb({-1, 0});
		sort(all(fish[i]));
		
		for(ll j = 1;j< fish[i].size();j++)fish[i][j].second += fish[i][j-1].second;
	}
	
	fish[n + 1] = {make_pair(-1, 0)};
	
	A[0] = {-1};
	
	for(ll i = 1;i<=n;i++){
		for(auto u : fish[i-1]){
			A[i].pb({u.first});
		}
		for(auto u : fish[i+1]){
			A[i].pb({u.first});
		}
		
		sort(all(A[i]));
		A[i].erase(unique(all(A[i])), A[i].end());
	}
	
	A[n+1] = {-1};
	
	vector<ll>dpu = {0}, dpd = {0};
	//assert(0);
	for(ll i = 1;i<=n+1;i++){
		vector<ll> ndpu(A[i].size());
		
		ll pref = 0;
		ll ind = 0;
		//cout<<i<<endl;
		for(ll j = 0;j < A[i].size();j++){
			//cout<<j<<endl;
			ll x = A[i][j];
			
			while(ind < A[i-1].size() && A[i-1][ind] <= x){
				pref = max(pref, dpu[ind] - get(i-1, A[i-1][ind]));
				++ind;
			}
			
			ndpu[j] = max(pref + get(i-1, x), dpd[0]);
		}
		
		vector<ll> ndpd(A[i].size());
		ll suff = 0;
		ind = A[i-1].size();
		
		for(ll j = A[i].size() - 1;j >= 0; j--){
			ll x = A[i][j];
			
			while(ind && A[i-1][ind - 1] >= x){
				--ind;
				suff = max(suff, max(dpu[ind], dpd[ind]) + get(i, A[i-1][ind]));
			}
			
			ndpd[j] = suff - get(i, x);
		}
		
		swap(dpu, ndpu);
		swap(dpd, ndpd);
	}
	
	return max(dpu[0], dpd[0]);
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(ll j = 1;j< fish[i].size();j++)fish[i][j].second += fish[i][j-1].second;
      |                ~^~~~~~~~~~~~~~~~
fish.cpp:70:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(ll j = 0;j < A[i].size();j++){
      |                ~~^~~~~~~~~~~~~
fish.cpp:74:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    while(ind < A[i-1].size() && A[i-1][ind] <= x){
      |          ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 25032 KB Output is correct
2 Correct 70 ms 28800 KB Output is correct
3 Correct 21 ms 20572 KB Output is correct
4 Correct 26 ms 20792 KB Output is correct
5 Correct 186 ms 45644 KB Output is correct
6 Correct 184 ms 47864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 117 ms 30808 KB Output is correct
3 Correct 139 ms 37552 KB Output is correct
4 Correct 57 ms 26532 KB Output is correct
5 Correct 67 ms 28728 KB Output is correct
6 Correct 4 ms 14628 KB Output is correct
7 Correct 4 ms 14428 KB Output is correct
8 Correct 4 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 22 ms 20692 KB Output is correct
11 Correct 22 ms 20788 KB Output is correct
12 Correct 67 ms 27308 KB Output is correct
13 Correct 76 ms 29376 KB Output is correct
14 Correct 63 ms 26752 KB Output is correct
15 Correct 74 ms 28232 KB Output is correct
16 Correct 61 ms 26996 KB Output is correct
17 Correct 69 ms 28288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 20572 KB Output is correct
2 Correct 22 ms 20572 KB Output is correct
3 Correct 42 ms 23100 KB Output is correct
4 Correct 41 ms 22876 KB Output is correct
5 Correct 70 ms 27212 KB Output is correct
6 Correct 59 ms 27064 KB Output is correct
7 Correct 62 ms 26948 KB Output is correct
8 Correct 61 ms 27076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 4 ms 14472 KB Output is correct
4 Correct 3 ms 14424 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 4 ms 14528 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 4 ms 14428 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 4 ms 14528 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 4 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 4 ms 14472 KB Output is correct
4 Correct 3 ms 14424 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 4 ms 14528 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 4 ms 14428 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 4 ms 14528 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 4 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 4 ms 14428 KB Output is correct
16 Correct 5 ms 14684 KB Output is correct
17 Correct 28 ms 17756 KB Output is correct
18 Correct 26 ms 19036 KB Output is correct
19 Correct 23 ms 18780 KB Output is correct
20 Correct 22 ms 18740 KB Output is correct
21 Correct 22 ms 18760 KB Output is correct
22 Correct 44 ms 23120 KB Output is correct
23 Correct 8 ms 15196 KB Output is correct
24 Correct 21 ms 16988 KB Output is correct
25 Correct 4 ms 14428 KB Output is correct
26 Correct 8 ms 15192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 4 ms 14472 KB Output is correct
4 Correct 3 ms 14424 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 4 ms 14528 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 4 ms 14428 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 4 ms 14528 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 4 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 4 ms 14428 KB Output is correct
16 Correct 5 ms 14684 KB Output is correct
17 Correct 28 ms 17756 KB Output is correct
18 Correct 26 ms 19036 KB Output is correct
19 Correct 23 ms 18780 KB Output is correct
20 Correct 22 ms 18740 KB Output is correct
21 Correct 22 ms 18760 KB Output is correct
22 Correct 44 ms 23120 KB Output is correct
23 Correct 8 ms 15196 KB Output is correct
24 Correct 21 ms 16988 KB Output is correct
25 Correct 4 ms 14428 KB Output is correct
26 Correct 8 ms 15192 KB Output is correct
27 Correct 6 ms 14684 KB Output is correct
28 Correct 132 ms 33908 KB Output is correct
29 Correct 180 ms 39728 KB Output is correct
30 Correct 190 ms 39764 KB Output is correct
31 Correct 192 ms 39936 KB Output is correct
32 Correct 152 ms 42068 KB Output is correct
33 Correct 189 ms 39760 KB Output is correct
34 Correct 206 ms 40036 KB Output is correct
35 Correct 68 ms 24800 KB Output is correct
36 Correct 198 ms 42604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 20572 KB Output is correct
2 Correct 22 ms 20572 KB Output is correct
3 Correct 42 ms 23100 KB Output is correct
4 Correct 41 ms 22876 KB Output is correct
5 Correct 70 ms 27212 KB Output is correct
6 Correct 59 ms 27064 KB Output is correct
7 Correct 62 ms 26948 KB Output is correct
8 Correct 61 ms 27076 KB Output is correct
9 Correct 62 ms 27144 KB Output is correct
10 Correct 59 ms 25168 KB Output is correct
11 Correct 105 ms 39508 KB Output is correct
12 Correct 3 ms 14680 KB Output is correct
13 Correct 3 ms 14428 KB Output is correct
14 Correct 4 ms 14520 KB Output is correct
15 Correct 4 ms 14428 KB Output is correct
16 Correct 4 ms 14428 KB Output is correct
17 Correct 4 ms 14428 KB Output is correct
18 Correct 25 ms 20568 KB Output is correct
19 Correct 23 ms 20828 KB Output is correct
20 Correct 22 ms 20572 KB Output is correct
21 Correct 22 ms 20756 KB Output is correct
22 Correct 70 ms 29584 KB Output is correct
23 Correct 107 ms 39400 KB Output is correct
24 Correct 119 ms 39948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 25032 KB Output is correct
2 Correct 70 ms 28800 KB Output is correct
3 Correct 21 ms 20572 KB Output is correct
4 Correct 26 ms 20792 KB Output is correct
5 Correct 186 ms 45644 KB Output is correct
6 Correct 184 ms 47864 KB Output is correct
7 Correct 4 ms 14428 KB Output is correct
8 Correct 117 ms 30808 KB Output is correct
9 Correct 139 ms 37552 KB Output is correct
10 Correct 57 ms 26532 KB Output is correct
11 Correct 67 ms 28728 KB Output is correct
12 Correct 4 ms 14628 KB Output is correct
13 Correct 4 ms 14428 KB Output is correct
14 Correct 4 ms 14428 KB Output is correct
15 Correct 3 ms 14424 KB Output is correct
16 Correct 22 ms 20692 KB Output is correct
17 Correct 22 ms 20788 KB Output is correct
18 Correct 67 ms 27308 KB Output is correct
19 Correct 76 ms 29376 KB Output is correct
20 Correct 63 ms 26752 KB Output is correct
21 Correct 74 ms 28232 KB Output is correct
22 Correct 61 ms 26996 KB Output is correct
23 Correct 69 ms 28288 KB Output is correct
24 Correct 22 ms 20572 KB Output is correct
25 Correct 22 ms 20572 KB Output is correct
26 Correct 42 ms 23100 KB Output is correct
27 Correct 41 ms 22876 KB Output is correct
28 Correct 70 ms 27212 KB Output is correct
29 Correct 59 ms 27064 KB Output is correct
30 Correct 62 ms 26948 KB Output is correct
31 Correct 61 ms 27076 KB Output is correct
32 Correct 3 ms 14428 KB Output is correct
33 Correct 3 ms 14428 KB Output is correct
34 Correct 4 ms 14472 KB Output is correct
35 Correct 3 ms 14424 KB Output is correct
36 Correct 4 ms 14428 KB Output is correct
37 Correct 4 ms 14528 KB Output is correct
38 Correct 3 ms 14428 KB Output is correct
39 Correct 4 ms 14428 KB Output is correct
40 Correct 4 ms 14428 KB Output is correct
41 Correct 4 ms 14684 KB Output is correct
42 Correct 4 ms 14528 KB Output is correct
43 Correct 5 ms 14428 KB Output is correct
44 Correct 4 ms 14428 KB Output is correct
45 Correct 5 ms 14428 KB Output is correct
46 Correct 4 ms 14428 KB Output is correct
47 Correct 5 ms 14684 KB Output is correct
48 Correct 28 ms 17756 KB Output is correct
49 Correct 26 ms 19036 KB Output is correct
50 Correct 23 ms 18780 KB Output is correct
51 Correct 22 ms 18740 KB Output is correct
52 Correct 22 ms 18760 KB Output is correct
53 Correct 44 ms 23120 KB Output is correct
54 Correct 8 ms 15196 KB Output is correct
55 Correct 21 ms 16988 KB Output is correct
56 Correct 4 ms 14428 KB Output is correct
57 Correct 8 ms 15192 KB Output is correct
58 Correct 6 ms 14684 KB Output is correct
59 Correct 132 ms 33908 KB Output is correct
60 Correct 180 ms 39728 KB Output is correct
61 Correct 190 ms 39764 KB Output is correct
62 Correct 192 ms 39936 KB Output is correct
63 Correct 152 ms 42068 KB Output is correct
64 Correct 189 ms 39760 KB Output is correct
65 Correct 206 ms 40036 KB Output is correct
66 Correct 68 ms 24800 KB Output is correct
67 Correct 198 ms 42604 KB Output is correct
68 Correct 62 ms 27144 KB Output is correct
69 Correct 59 ms 25168 KB Output is correct
70 Correct 105 ms 39508 KB Output is correct
71 Correct 3 ms 14680 KB Output is correct
72 Correct 3 ms 14428 KB Output is correct
73 Correct 4 ms 14520 KB Output is correct
74 Correct 4 ms 14428 KB Output is correct
75 Correct 4 ms 14428 KB Output is correct
76 Correct 4 ms 14428 KB Output is correct
77 Correct 25 ms 20568 KB Output is correct
78 Correct 23 ms 20828 KB Output is correct
79 Correct 22 ms 20572 KB Output is correct
80 Correct 22 ms 20756 KB Output is correct
81 Correct 70 ms 29584 KB Output is correct
82 Correct 107 ms 39400 KB Output is correct
83 Correct 119 ms 39948 KB Output is correct
84 Correct 225 ms 44420 KB Output is correct
85 Correct 242 ms 44664 KB Output is correct
86 Correct 184 ms 47144 KB Output is correct
87 Correct 178 ms 47992 KB Output is correct
88 Correct 3 ms 14428 KB Output is correct
89 Correct 183 ms 47740 KB Output is correct
90 Correct 172 ms 46568 KB Output is correct
91 Correct 153 ms 46676 KB Output is correct