Submission #832212

# Submission time Handle Problem Language Result Execution time Memory
832212 2023-08-21T06:50:44 Z ymm Catfish Farm (IOI22_fish) C++17
100 / 100
154 ms 34044 KB
#include "fish.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= l; --x)
typedef long long ll;
using namespace std;

const int N = 100'032;

struct fish {
	int pos = 0;
	int weight = 0;
	ll dpu = 0;
	ll dpd = 0;

	fish() {}
	fish(int x) : pos(x) {}
	fish(int x, int w) : pos(x), weight(w) {}
	bool operator<(const fish &f) const { return pos < f.pos; }
};

vector<fish> a[N];

fish &nxt_up(vector<fish> &vec, fish &cur) { return *upper_bound(vec.begin(), vec.end(), cur); }
fish &nxt_do(vector<fish> &vec, fish &cur) { return *--lower_bound(vec.begin(), vec.end(), cur); }

long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	Loop (i,0,m)
		a[X[i]].push_back(fish(Y[i], W[i]));
	Loop (i,0,n) {
		a[i].push_back(fish(-1));
		a[i].push_back(fish(n));
		sort(a[i].begin(), a[i].end());
	}
	LoopR (i,0,n) {
		a[i].front().dpd = (i+1 < n? a[i+1].front().dpu: 0);
		if (i+2 < n)
			a[i].front().dpd = max(a[i].front().dpd, a[i+2].back().dpd);
		Loop (j,1,a[i].size()) {
			a[i][j].dpd = nxt_do(a[i], a[i][j]).dpd;
			if (i+1 < n)
				a[i][j].dpd = max(a[i][j].dpd, nxt_do(a[i+1], a[i][j]).dpd);
			a[i][j].dpd += a[i][j].weight;
		}
		if (i == n-1)
			continue;
		a[i].back().dpu = (i+2 < n? a[i+2].back().dpd: 0);
		LoopR (j,0,a[i].size()-1) {
			a[i][j].dpu = nxt_up(a[i], a[i][j]).dpu;
			if (i+1 < n)
				a[i][j].dpu = max(a[i][j].dpu, nxt_up(a[i+1], a[i][j]).dpu);
			a[i][j].dpu += a[i][j].weight;
		}
	}
	return max(a[0].front().dpu, a[1].back().dpd);
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<fish>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:40:3: note: in expansion of macro 'Loop'
   40 |   Loop (j,1,a[i].size()) {
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 13424 KB Output is correct
2 Correct 54 ms 15312 KB Output is correct
3 Correct 11 ms 8928 KB Output is correct
4 Correct 11 ms 8800 KB Output is correct
5 Correct 137 ms 29400 KB Output is correct
6 Correct 121 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 86 ms 18716 KB Output is correct
3 Correct 101 ms 21800 KB Output is correct
4 Correct 43 ms 13420 KB Output is correct
5 Correct 52 ms 15304 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 14 ms 8860 KB Output is correct
11 Correct 11 ms 8916 KB Output is correct
12 Correct 43 ms 13400 KB Output is correct
13 Correct 52 ms 15356 KB Output is correct
14 Correct 51 ms 13492 KB Output is correct
15 Correct 53 ms 14744 KB Output is correct
16 Correct 45 ms 13480 KB Output is correct
17 Correct 51 ms 14580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8916 KB Output is correct
2 Correct 11 ms 8916 KB Output is correct
3 Correct 28 ms 13128 KB Output is correct
4 Correct 23 ms 12236 KB Output is correct
5 Correct 46 ms 18252 KB Output is correct
6 Correct 42 ms 17584 KB Output is correct
7 Correct 46 ms 18152 KB Output is correct
8 Correct 47 ms 18140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2656 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2656 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 23 ms 5820 KB Output is correct
18 Correct 21 ms 6628 KB Output is correct
19 Correct 18 ms 6500 KB Output is correct
20 Correct 16 ms 6484 KB Output is correct
21 Correct 16 ms 6372 KB Output is correct
22 Correct 36 ms 9964 KB Output is correct
23 Correct 5 ms 3376 KB Output is correct
24 Correct 14 ms 4784 KB Output is correct
25 Correct 2 ms 2680 KB Output is correct
26 Correct 5 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2656 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 23 ms 5820 KB Output is correct
18 Correct 21 ms 6628 KB Output is correct
19 Correct 18 ms 6500 KB Output is correct
20 Correct 16 ms 6484 KB Output is correct
21 Correct 16 ms 6372 KB Output is correct
22 Correct 36 ms 9964 KB Output is correct
23 Correct 5 ms 3376 KB Output is correct
24 Correct 14 ms 4784 KB Output is correct
25 Correct 2 ms 2680 KB Output is correct
26 Correct 5 ms 3284 KB Output is correct
27 Correct 2 ms 3092 KB Output is correct
28 Correct 96 ms 20044 KB Output is correct
29 Correct 130 ms 26000 KB Output is correct
30 Correct 139 ms 25300 KB Output is correct
31 Correct 123 ms 25232 KB Output is correct
32 Correct 136 ms 27012 KB Output is correct
33 Correct 126 ms 25300 KB Output is correct
34 Correct 129 ms 25360 KB Output is correct
35 Correct 54 ms 12072 KB Output is correct
36 Correct 132 ms 27536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8916 KB Output is correct
2 Correct 11 ms 8916 KB Output is correct
3 Correct 28 ms 13128 KB Output is correct
4 Correct 23 ms 12236 KB Output is correct
5 Correct 46 ms 18252 KB Output is correct
6 Correct 42 ms 17584 KB Output is correct
7 Correct 46 ms 18152 KB Output is correct
8 Correct 47 ms 18140 KB Output is correct
9 Correct 42 ms 17984 KB Output is correct
10 Correct 39 ms 12812 KB Output is correct
11 Correct 76 ms 23172 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 11 ms 8916 KB Output is correct
19 Correct 11 ms 8916 KB Output is correct
20 Correct 11 ms 8916 KB Output is correct
21 Correct 11 ms 8916 KB Output is correct
22 Correct 44 ms 16972 KB Output is correct
23 Correct 79 ms 23156 KB Output is correct
24 Correct 81 ms 23636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 13424 KB Output is correct
2 Correct 54 ms 15312 KB Output is correct
3 Correct 11 ms 8928 KB Output is correct
4 Correct 11 ms 8800 KB Output is correct
5 Correct 137 ms 29400 KB Output is correct
6 Correct 121 ms 33484 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 86 ms 18716 KB Output is correct
9 Correct 101 ms 21800 KB Output is correct
10 Correct 43 ms 13420 KB Output is correct
11 Correct 52 ms 15304 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 14 ms 8860 KB Output is correct
17 Correct 11 ms 8916 KB Output is correct
18 Correct 43 ms 13400 KB Output is correct
19 Correct 52 ms 15356 KB Output is correct
20 Correct 51 ms 13492 KB Output is correct
21 Correct 53 ms 14744 KB Output is correct
22 Correct 45 ms 13480 KB Output is correct
23 Correct 51 ms 14580 KB Output is correct
24 Correct 11 ms 8916 KB Output is correct
25 Correct 11 ms 8916 KB Output is correct
26 Correct 28 ms 13128 KB Output is correct
27 Correct 23 ms 12236 KB Output is correct
28 Correct 46 ms 18252 KB Output is correct
29 Correct 42 ms 17584 KB Output is correct
30 Correct 46 ms 18152 KB Output is correct
31 Correct 47 ms 18140 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 1 ms 2656 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2656 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2772 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2772 KB Output is correct
48 Correct 23 ms 5820 KB Output is correct
49 Correct 21 ms 6628 KB Output is correct
50 Correct 18 ms 6500 KB Output is correct
51 Correct 16 ms 6484 KB Output is correct
52 Correct 16 ms 6372 KB Output is correct
53 Correct 36 ms 9964 KB Output is correct
54 Correct 5 ms 3376 KB Output is correct
55 Correct 14 ms 4784 KB Output is correct
56 Correct 2 ms 2680 KB Output is correct
57 Correct 5 ms 3284 KB Output is correct
58 Correct 2 ms 3092 KB Output is correct
59 Correct 96 ms 20044 KB Output is correct
60 Correct 130 ms 26000 KB Output is correct
61 Correct 139 ms 25300 KB Output is correct
62 Correct 123 ms 25232 KB Output is correct
63 Correct 136 ms 27012 KB Output is correct
64 Correct 126 ms 25300 KB Output is correct
65 Correct 129 ms 25360 KB Output is correct
66 Correct 54 ms 12072 KB Output is correct
67 Correct 132 ms 27536 KB Output is correct
68 Correct 42 ms 17984 KB Output is correct
69 Correct 39 ms 12812 KB Output is correct
70 Correct 76 ms 23172 KB Output is correct
71 Correct 2 ms 2652 KB Output is correct
72 Correct 2 ms 2644 KB Output is correct
73 Correct 1 ms 2644 KB Output is correct
74 Correct 1 ms 2644 KB Output is correct
75 Correct 1 ms 2652 KB Output is correct
76 Correct 2 ms 2652 KB Output is correct
77 Correct 11 ms 8916 KB Output is correct
78 Correct 11 ms 8916 KB Output is correct
79 Correct 11 ms 8916 KB Output is correct
80 Correct 11 ms 8916 KB Output is correct
81 Correct 44 ms 16972 KB Output is correct
82 Correct 79 ms 23156 KB Output is correct
83 Correct 81 ms 23636 KB Output is correct
84 Correct 154 ms 28620 KB Output is correct
85 Correct 153 ms 28752 KB Output is correct
86 Correct 136 ms 33392 KB Output is correct
87 Correct 142 ms 33932 KB Output is correct
88 Correct 2 ms 2644 KB Output is correct
89 Correct 137 ms 34044 KB Output is correct
90 Correct 130 ms 31568 KB Output is correct
91 Correct 119 ms 31876 KB Output is correct