답안 #1056215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056215 2024-08-13T08:17:15 Z AmirAli_H1 메기 농장 (IOI22_fish) C++17
100 / 100
190 ms 68692 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "fish.h"
using namespace std;

typedef			long long				ll;
typedef			pair<int, int>			pii;
typedef			pair<ll, ll>			pll;

#define			F						first
#define			S						second
#define			all(x)					(x).begin(),(x).end()
#define			len(x)					((ll) (x).size())
#define			Mp						make_pair
#define			pb						push_back
#define			endl					'\n'
#define			sep						' '

const int maxn = 3e5 + 7;

int n, m;
vector<pll> arr[maxn]; vector<ll> dp[2][maxn];
vector<ll> sm[maxn]; ll mx1[maxn], mx2[maxn];

void calx(int i, int T1) {
	ll mx = 0;
	fill(mx1, mx1 + len(arr[i + 1]), 0);
	fill(mx2, mx2 + len(arr[i + 1]), 0);
	for (int j = 0; j < len(arr[i]); j++) {
		ll x = dp[T1][i][j]; mx = max(mx, x);
		int j1 = lower_bound(all(arr[i + 1]), (pll) Mp(arr[i][j].F + 1, -1)) - arr[i + 1].begin();
		int j2 = j1 - 1;
		if (j1 < len(arr[i + 1])) {
			if (T1 == 0) {
				mx1[j1] = max(mx1[j1], x + sm[i][j]);
			}
			
		}
		if (j2 >= 0) {
			int r = lower_bound(all(arr[i + 1]), (pll) Mp(arr[i][j].F, -1)) - arr[i + 1].begin();
			mx2[j2] = max(mx2[j2], x - sm[i + 1][r]);
		}
	}
	
	for (int j = len(arr[i + 1]) - 2; j >= 0; j--) {
		mx2[j] = max(mx2[j], mx2[j + 1]);
	}
	for (int j = 1; j < len(arr[i + 1]); j++) {
		mx1[j] = max(mx1[j], mx1[j - 1]);
	}
	for (int j = 0; j < len(arr[i + 1]); j++) {
		int r = lower_bound(all(arr[i]), (pll) Mp(arr[i + 1][j].F, -1)) - arr[i].begin();
		mx1[j] -= sm[i][r]; mx2[j] += sm[i + 1][j];
	}
	
	for (int j = 0; j < len(arr[i + 1]); j++) {
		for (int T2 : {0, 1}) {
			dp[T2][i + 1][j] = max(dp[T2][i + 1][j], mx);
			dp[T2][i + 1][j] = max(dp[T2][i + 1][j], mx1[j]);
			if (T2 == 1) dp[T2][i + 1][j] = max(dp[T2][i + 1][j], mx2[j]);
		}
	}
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
	n = N; m = M;
	for (int i = 0; i < m; i++) {
		arr[X[i]].pb(Mp(Y[i], W[i]));
	}
	for (int i = 0; i < n; i++) {
		arr[i].pb(Mp(n, 0));
		sort(all(arr[i])); sm[i].resize(len(arr[i]));
		for (int j = len(arr[i]) - 2; j >= 0; j--) sm[i][j] = sm[i][j + 1] + arr[i][j].S;
		
		dp[0][i].resize(len(arr[i])); dp[1][i].resize(len(arr[i]));
	}
	
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (i + 1 < n) {
			calx(i, 0); calx(i, 1);
		}
		for (int T : {0, 1}) {
			for (ll x : dp[T][i]) ans = max(ans, x);
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 47412 KB Output is correct
2 Correct 54 ms 49736 KB Output is correct
3 Correct 23 ms 43608 KB Output is correct
4 Correct 22 ms 43400 KB Output is correct
5 Correct 102 ms 64396 KB Output is correct
6 Correct 126 ms 62632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 74 ms 54544 KB Output is correct
3 Correct 95 ms 61688 KB Output is correct
4 Correct 47 ms 48620 KB Output is correct
5 Correct 85 ms 51612 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 7 ms 31068 KB Output is correct
8 Correct 5 ms 31088 KB Output is correct
9 Correct 5 ms 31064 KB Output is correct
10 Correct 39 ms 43432 KB Output is correct
11 Correct 22 ms 43608 KB Output is correct
12 Correct 46 ms 50920 KB Output is correct
13 Correct 65 ms 53832 KB Output is correct
14 Correct 67 ms 51000 KB Output is correct
15 Correct 71 ms 52936 KB Output is correct
16 Correct 44 ms 50888 KB Output is correct
17 Correct 61 ms 53016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 43608 KB Output is correct
2 Correct 25 ms 43612 KB Output is correct
3 Correct 34 ms 44280 KB Output is correct
4 Correct 55 ms 44964 KB Output is correct
5 Correct 52 ms 47460 KB Output is correct
6 Correct 53 ms 47368 KB Output is correct
7 Correct 45 ms 47460 KB Output is correct
8 Correct 55 ms 47524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31068 KB Output is correct
2 Correct 7 ms 31064 KB Output is correct
3 Correct 4 ms 31068 KB Output is correct
4 Correct 5 ms 31068 KB Output is correct
5 Correct 7 ms 31032 KB Output is correct
6 Correct 7 ms 31068 KB Output is correct
7 Correct 4 ms 31072 KB Output is correct
8 Correct 7 ms 31068 KB Output is correct
9 Correct 6 ms 31068 KB Output is correct
10 Correct 6 ms 31320 KB Output is correct
11 Correct 4 ms 31036 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 7 ms 31156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31068 KB Output is correct
2 Correct 7 ms 31064 KB Output is correct
3 Correct 4 ms 31068 KB Output is correct
4 Correct 5 ms 31068 KB Output is correct
5 Correct 7 ms 31032 KB Output is correct
6 Correct 7 ms 31068 KB Output is correct
7 Correct 4 ms 31072 KB Output is correct
8 Correct 7 ms 31068 KB Output is correct
9 Correct 6 ms 31068 KB Output is correct
10 Correct 6 ms 31320 KB Output is correct
11 Correct 4 ms 31036 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 7 ms 31156 KB Output is correct
15 Correct 7 ms 31068 KB Output is correct
16 Correct 8 ms 31068 KB Output is correct
17 Correct 25 ms 34648 KB Output is correct
18 Correct 27 ms 35420 KB Output is correct
19 Correct 26 ms 35064 KB Output is correct
20 Correct 26 ms 35164 KB Output is correct
21 Correct 17 ms 35164 KB Output is correct
22 Correct 30 ms 39252 KB Output is correct
23 Correct 8 ms 31832 KB Output is correct
24 Correct 17 ms 33672 KB Output is correct
25 Correct 8 ms 31068 KB Output is correct
26 Correct 7 ms 31616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31068 KB Output is correct
2 Correct 7 ms 31064 KB Output is correct
3 Correct 4 ms 31068 KB Output is correct
4 Correct 5 ms 31068 KB Output is correct
5 Correct 7 ms 31032 KB Output is correct
6 Correct 7 ms 31068 KB Output is correct
7 Correct 4 ms 31072 KB Output is correct
8 Correct 7 ms 31068 KB Output is correct
9 Correct 6 ms 31068 KB Output is correct
10 Correct 6 ms 31320 KB Output is correct
11 Correct 4 ms 31036 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 7 ms 31156 KB Output is correct
15 Correct 7 ms 31068 KB Output is correct
16 Correct 8 ms 31068 KB Output is correct
17 Correct 25 ms 34648 KB Output is correct
18 Correct 27 ms 35420 KB Output is correct
19 Correct 26 ms 35064 KB Output is correct
20 Correct 26 ms 35164 KB Output is correct
21 Correct 17 ms 35164 KB Output is correct
22 Correct 30 ms 39252 KB Output is correct
23 Correct 8 ms 31832 KB Output is correct
24 Correct 17 ms 33672 KB Output is correct
25 Correct 8 ms 31068 KB Output is correct
26 Correct 7 ms 31616 KB Output is correct
27 Correct 9 ms 31580 KB Output is correct
28 Correct 127 ms 50360 KB Output is correct
29 Correct 123 ms 57428 KB Output is correct
30 Correct 101 ms 57116 KB Output is correct
31 Correct 109 ms 57100 KB Output is correct
32 Correct 92 ms 58280 KB Output is correct
33 Correct 103 ms 57172 KB Output is correct
34 Correct 114 ms 56912 KB Output is correct
35 Correct 38 ms 41300 KB Output is correct
36 Correct 108 ms 58448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 43608 KB Output is correct
2 Correct 25 ms 43612 KB Output is correct
3 Correct 34 ms 44280 KB Output is correct
4 Correct 55 ms 44964 KB Output is correct
5 Correct 52 ms 47460 KB Output is correct
6 Correct 53 ms 47368 KB Output is correct
7 Correct 45 ms 47460 KB Output is correct
8 Correct 55 ms 47524 KB Output is correct
9 Correct 42 ms 47448 KB Output is correct
10 Correct 85 ms 44460 KB Output is correct
11 Correct 78 ms 57684 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 4 ms 31068 KB Output is correct
14 Correct 4 ms 31064 KB Output is correct
15 Correct 4 ms 31068 KB Output is correct
16 Correct 4 ms 31064 KB Output is correct
17 Correct 7 ms 31068 KB Output is correct
18 Correct 21 ms 43532 KB Output is correct
19 Correct 25 ms 43616 KB Output is correct
20 Correct 22 ms 43596 KB Output is correct
21 Correct 38 ms 43572 KB Output is correct
22 Correct 60 ms 50044 KB Output is correct
23 Correct 89 ms 57832 KB Output is correct
24 Correct 94 ms 58196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 47412 KB Output is correct
2 Correct 54 ms 49736 KB Output is correct
3 Correct 23 ms 43608 KB Output is correct
4 Correct 22 ms 43400 KB Output is correct
5 Correct 102 ms 64396 KB Output is correct
6 Correct 126 ms 62632 KB Output is correct
7 Correct 5 ms 31068 KB Output is correct
8 Correct 74 ms 54544 KB Output is correct
9 Correct 95 ms 61688 KB Output is correct
10 Correct 47 ms 48620 KB Output is correct
11 Correct 85 ms 51612 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 7 ms 31068 KB Output is correct
14 Correct 5 ms 31088 KB Output is correct
15 Correct 5 ms 31064 KB Output is correct
16 Correct 39 ms 43432 KB Output is correct
17 Correct 22 ms 43608 KB Output is correct
18 Correct 46 ms 50920 KB Output is correct
19 Correct 65 ms 53832 KB Output is correct
20 Correct 67 ms 51000 KB Output is correct
21 Correct 71 ms 52936 KB Output is correct
22 Correct 44 ms 50888 KB Output is correct
23 Correct 61 ms 53016 KB Output is correct
24 Correct 25 ms 43608 KB Output is correct
25 Correct 25 ms 43612 KB Output is correct
26 Correct 34 ms 44280 KB Output is correct
27 Correct 55 ms 44964 KB Output is correct
28 Correct 52 ms 47460 KB Output is correct
29 Correct 53 ms 47368 KB Output is correct
30 Correct 45 ms 47460 KB Output is correct
31 Correct 55 ms 47524 KB Output is correct
32 Correct 4 ms 31068 KB Output is correct
33 Correct 7 ms 31064 KB Output is correct
34 Correct 4 ms 31068 KB Output is correct
35 Correct 5 ms 31068 KB Output is correct
36 Correct 7 ms 31032 KB Output is correct
37 Correct 7 ms 31068 KB Output is correct
38 Correct 4 ms 31072 KB Output is correct
39 Correct 7 ms 31068 KB Output is correct
40 Correct 6 ms 31068 KB Output is correct
41 Correct 6 ms 31320 KB Output is correct
42 Correct 4 ms 31036 KB Output is correct
43 Correct 8 ms 31068 KB Output is correct
44 Correct 5 ms 31068 KB Output is correct
45 Correct 7 ms 31156 KB Output is correct
46 Correct 7 ms 31068 KB Output is correct
47 Correct 8 ms 31068 KB Output is correct
48 Correct 25 ms 34648 KB Output is correct
49 Correct 27 ms 35420 KB Output is correct
50 Correct 26 ms 35064 KB Output is correct
51 Correct 26 ms 35164 KB Output is correct
52 Correct 17 ms 35164 KB Output is correct
53 Correct 30 ms 39252 KB Output is correct
54 Correct 8 ms 31832 KB Output is correct
55 Correct 17 ms 33672 KB Output is correct
56 Correct 8 ms 31068 KB Output is correct
57 Correct 7 ms 31616 KB Output is correct
58 Correct 9 ms 31580 KB Output is correct
59 Correct 127 ms 50360 KB Output is correct
60 Correct 123 ms 57428 KB Output is correct
61 Correct 101 ms 57116 KB Output is correct
62 Correct 109 ms 57100 KB Output is correct
63 Correct 92 ms 58280 KB Output is correct
64 Correct 103 ms 57172 KB Output is correct
65 Correct 114 ms 56912 KB Output is correct
66 Correct 38 ms 41300 KB Output is correct
67 Correct 108 ms 58448 KB Output is correct
68 Correct 42 ms 47448 KB Output is correct
69 Correct 85 ms 44460 KB Output is correct
70 Correct 78 ms 57684 KB Output is correct
71 Correct 5 ms 31068 KB Output is correct
72 Correct 4 ms 31068 KB Output is correct
73 Correct 4 ms 31064 KB Output is correct
74 Correct 4 ms 31068 KB Output is correct
75 Correct 4 ms 31064 KB Output is correct
76 Correct 7 ms 31068 KB Output is correct
77 Correct 21 ms 43532 KB Output is correct
78 Correct 25 ms 43616 KB Output is correct
79 Correct 22 ms 43596 KB Output is correct
80 Correct 38 ms 43572 KB Output is correct
81 Correct 60 ms 50044 KB Output is correct
82 Correct 89 ms 57832 KB Output is correct
83 Correct 94 ms 58196 KB Output is correct
84 Correct 188 ms 67328 KB Output is correct
85 Correct 190 ms 68160 KB Output is correct
86 Correct 134 ms 65916 KB Output is correct
87 Correct 132 ms 67092 KB Output is correct
88 Correct 5 ms 31068 KB Output is correct
89 Correct 133 ms 67092 KB Output is correct
90 Correct 123 ms 67992 KB Output is correct
91 Correct 118 ms 68692 KB Output is correct