답안 #626642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626642 2022-08-11T15:25:37 Z mohammad_kilani 메기 농장 (IOI22_fish) C++17
100 / 100
203 ms 75360 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 300010;

vector< pair< int , int > > grid[N];

vector< long long > dp[N][2] , cur[N][2];

vector< long long > sum[N];

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
	for(int i = 0 ;i < M;i++){
		grid[X[i]].push_back(make_pair(Y[i] , W[i]));
	}
	for(int i = 0 ;i < N;i++){
		sort(grid[i].begin(),grid[i].end());
		for(int j = 0 ;j < (int)grid[i].size();j++){
			sum[i].push_back(grid[i][j].second);
			if(j)
				sum[i][j] += sum[i][j - 1];
		}
		dp[i][0].resize((int)grid[i + 1].size() + 1);
		dp[i][1].resize((int)grid[i + 1].size());
	}
	for(int i = 0 ;i < N;i++){
		cur[i][0].resize((int)grid[i].size());
		cur[i][1].resize((int)grid[i].size());

		for(int j = 0 ;j < (int)grid[i].size();j++){
			cur[i][0][j] = (long long)grid[i][j].second;
			if(i > 0)
				cur[i][0][j] = max(cur[i][0][j] , grid[i][j].second + dp[i - 1][0][j]);
			if(j > 0)
				cur[i][0][j] = max(cur[i][0][j] , grid[i][j].second + cur[i][0][j - 1]);
		}

		for(int j = (int)grid[i].size() - 1;j >= 0;j--){
			if(i == 0){
				cur[i][1][j] = -(long long)1e18;
				continue;
			}
			cur[i][1][j] = sum[i][j] + dp[i - 1][1][j];
			if(j < (int)grid[i].size() - 1)
				cur[i][1][j] = max(cur[i][1][j] , cur[i][1][j + 1]);
		}


		for(int k = -1 , last , j = 0 ;j < (int)dp[i][0].size();j++){
			last = (j == (int)grid[i + 1].size() ? N : grid[i + 1][j].first - 1); 
			while(k + 1 < (int)grid[i].size() && grid[i][k + 1].first <= last) k++;

			dp[i][0][j] = (i == 0 ? 0 : dp[i - 1][0][(int)grid[i].size()]);

			if(k != -1)
				dp[i][0][j] = max(dp[i][0][j] , cur[i][0][k]);
			if(k + 1 < (int)grid[i].size())
				dp[i][0][j] = max(dp[i][0][j] , cur[i][1][k + 1]);

		}



		for(int k = (int)grid[i].size(), last , j = (int)dp[i][1].size() - 1;j >= 0;j--){
			last = grid[i + 1][j].first + 1;
			while(k - 1 >= 0 && grid[i][k - 1].first >= last)
				k--;
			dp[i][1][j] = (i == 0 ? 0 : dp[i - 1][0][(int)grid[i].size()]);
			if(k < (int)grid[i].size())
				dp[i][1][j] = max(dp[i][1][j] , cur[i][1][k] - (k == 0 ? 0 : sum[i][k - 1]));
		}
	}

	long long ans = dp[N - 2][0][(int)grid[N - 1].size()];

	for(int j = 0 ;j < (int)grid[N  - 1].size();j++){
		ans = max(ans , sum[N - 1][j] + dp[N - 2][1][j]);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 49860 KB Output is correct
2 Correct 69 ms 51168 KB Output is correct
3 Correct 28 ms 45604 KB Output is correct
4 Correct 28 ms 45592 KB Output is correct
5 Correct 150 ms 66876 KB Output is correct
6 Correct 185 ms 71156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42448 KB Output is correct
2 Correct 90 ms 55504 KB Output is correct
3 Correct 105 ms 58212 KB Output is correct
4 Correct 65 ms 49780 KB Output is correct
5 Correct 67 ms 51140 KB Output is correct
6 Correct 22 ms 42452 KB Output is correct
7 Correct 22 ms 42456 KB Output is correct
8 Correct 22 ms 42476 KB Output is correct
9 Correct 22 ms 42540 KB Output is correct
10 Correct 27 ms 45648 KB Output is correct
11 Correct 29 ms 45700 KB Output is correct
12 Correct 58 ms 51196 KB Output is correct
13 Correct 66 ms 52692 KB Output is correct
14 Correct 59 ms 50488 KB Output is correct
15 Correct 64 ms 51392 KB Output is correct
16 Correct 59 ms 50424 KB Output is correct
17 Correct 62 ms 51324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 45652 KB Output is correct
2 Correct 29 ms 45612 KB Output is correct
3 Correct 59 ms 54968 KB Output is correct
4 Correct 52 ms 52096 KB Output is correct
5 Correct 98 ms 63580 KB Output is correct
6 Correct 93 ms 63696 KB Output is correct
7 Correct 116 ms 63636 KB Output is correct
8 Correct 93 ms 63704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 23 ms 42572 KB Output is correct
3 Correct 24 ms 42452 KB Output is correct
4 Correct 27 ms 42452 KB Output is correct
5 Correct 23 ms 42452 KB Output is correct
6 Correct 25 ms 42496 KB Output is correct
7 Correct 22 ms 42452 KB Output is correct
8 Correct 22 ms 42464 KB Output is correct
9 Correct 23 ms 42580 KB Output is correct
10 Correct 24 ms 42696 KB Output is correct
11 Correct 24 ms 42540 KB Output is correct
12 Correct 24 ms 42664 KB Output is correct
13 Correct 22 ms 42580 KB Output is correct
14 Correct 24 ms 42644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 23 ms 42572 KB Output is correct
3 Correct 24 ms 42452 KB Output is correct
4 Correct 27 ms 42452 KB Output is correct
5 Correct 23 ms 42452 KB Output is correct
6 Correct 25 ms 42496 KB Output is correct
7 Correct 22 ms 42452 KB Output is correct
8 Correct 22 ms 42464 KB Output is correct
9 Correct 23 ms 42580 KB Output is correct
10 Correct 24 ms 42696 KB Output is correct
11 Correct 24 ms 42540 KB Output is correct
12 Correct 24 ms 42664 KB Output is correct
13 Correct 22 ms 42580 KB Output is correct
14 Correct 24 ms 42644 KB Output is correct
15 Correct 22 ms 42580 KB Output is correct
16 Correct 23 ms 42720 KB Output is correct
17 Correct 37 ms 45936 KB Output is correct
18 Correct 39 ms 46412 KB Output is correct
19 Correct 39 ms 46284 KB Output is correct
20 Correct 39 ms 46292 KB Output is correct
21 Correct 38 ms 46308 KB Output is correct
22 Correct 54 ms 50032 KB Output is correct
23 Correct 26 ms 43284 KB Output is correct
24 Correct 33 ms 44780 KB Output is correct
25 Correct 23 ms 42568 KB Output is correct
26 Correct 25 ms 43244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 23 ms 42572 KB Output is correct
3 Correct 24 ms 42452 KB Output is correct
4 Correct 27 ms 42452 KB Output is correct
5 Correct 23 ms 42452 KB Output is correct
6 Correct 25 ms 42496 KB Output is correct
7 Correct 22 ms 42452 KB Output is correct
8 Correct 22 ms 42464 KB Output is correct
9 Correct 23 ms 42580 KB Output is correct
10 Correct 24 ms 42696 KB Output is correct
11 Correct 24 ms 42540 KB Output is correct
12 Correct 24 ms 42664 KB Output is correct
13 Correct 22 ms 42580 KB Output is correct
14 Correct 24 ms 42644 KB Output is correct
15 Correct 22 ms 42580 KB Output is correct
16 Correct 23 ms 42720 KB Output is correct
17 Correct 37 ms 45936 KB Output is correct
18 Correct 39 ms 46412 KB Output is correct
19 Correct 39 ms 46284 KB Output is correct
20 Correct 39 ms 46292 KB Output is correct
21 Correct 38 ms 46308 KB Output is correct
22 Correct 54 ms 50032 KB Output is correct
23 Correct 26 ms 43284 KB Output is correct
24 Correct 33 ms 44780 KB Output is correct
25 Correct 23 ms 42568 KB Output is correct
26 Correct 25 ms 43244 KB Output is correct
27 Correct 28 ms 43116 KB Output is correct
28 Correct 98 ms 60468 KB Output is correct
29 Correct 138 ms 70976 KB Output is correct
30 Correct 140 ms 70928 KB Output is correct
31 Correct 147 ms 70896 KB Output is correct
32 Correct 135 ms 73160 KB Output is correct
33 Correct 137 ms 70532 KB Output is correct
34 Correct 141 ms 70240 KB Output is correct
35 Correct 82 ms 53376 KB Output is correct
36 Correct 148 ms 69212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 45652 KB Output is correct
2 Correct 29 ms 45612 KB Output is correct
3 Correct 59 ms 54968 KB Output is correct
4 Correct 52 ms 52096 KB Output is correct
5 Correct 98 ms 63580 KB Output is correct
6 Correct 93 ms 63696 KB Output is correct
7 Correct 116 ms 63636 KB Output is correct
8 Correct 93 ms 63704 KB Output is correct
9 Correct 107 ms 63588 KB Output is correct
10 Correct 76 ms 54236 KB Output is correct
11 Correct 163 ms 65988 KB Output is correct
12 Correct 22 ms 42452 KB Output is correct
13 Correct 22 ms 42452 KB Output is correct
14 Correct 22 ms 42476 KB Output is correct
15 Correct 22 ms 42452 KB Output is correct
16 Correct 24 ms 42628 KB Output is correct
17 Correct 23 ms 42488 KB Output is correct
18 Correct 28 ms 45672 KB Output is correct
19 Correct 29 ms 45652 KB Output is correct
20 Correct 28 ms 45644 KB Output is correct
21 Correct 31 ms 45652 KB Output is correct
22 Correct 116 ms 58424 KB Output is correct
23 Correct 146 ms 66040 KB Output is correct
24 Correct 131 ms 65980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 49860 KB Output is correct
2 Correct 69 ms 51168 KB Output is correct
3 Correct 28 ms 45604 KB Output is correct
4 Correct 28 ms 45592 KB Output is correct
5 Correct 150 ms 66876 KB Output is correct
6 Correct 185 ms 71156 KB Output is correct
7 Correct 22 ms 42448 KB Output is correct
8 Correct 90 ms 55504 KB Output is correct
9 Correct 105 ms 58212 KB Output is correct
10 Correct 65 ms 49780 KB Output is correct
11 Correct 67 ms 51140 KB Output is correct
12 Correct 22 ms 42452 KB Output is correct
13 Correct 22 ms 42456 KB Output is correct
14 Correct 22 ms 42476 KB Output is correct
15 Correct 22 ms 42540 KB Output is correct
16 Correct 27 ms 45648 KB Output is correct
17 Correct 29 ms 45700 KB Output is correct
18 Correct 58 ms 51196 KB Output is correct
19 Correct 66 ms 52692 KB Output is correct
20 Correct 59 ms 50488 KB Output is correct
21 Correct 64 ms 51392 KB Output is correct
22 Correct 59 ms 50424 KB Output is correct
23 Correct 62 ms 51324 KB Output is correct
24 Correct 29 ms 45652 KB Output is correct
25 Correct 29 ms 45612 KB Output is correct
26 Correct 59 ms 54968 KB Output is correct
27 Correct 52 ms 52096 KB Output is correct
28 Correct 98 ms 63580 KB Output is correct
29 Correct 93 ms 63696 KB Output is correct
30 Correct 116 ms 63636 KB Output is correct
31 Correct 93 ms 63704 KB Output is correct
32 Correct 22 ms 42572 KB Output is correct
33 Correct 23 ms 42572 KB Output is correct
34 Correct 24 ms 42452 KB Output is correct
35 Correct 27 ms 42452 KB Output is correct
36 Correct 23 ms 42452 KB Output is correct
37 Correct 25 ms 42496 KB Output is correct
38 Correct 22 ms 42452 KB Output is correct
39 Correct 22 ms 42464 KB Output is correct
40 Correct 23 ms 42580 KB Output is correct
41 Correct 24 ms 42696 KB Output is correct
42 Correct 24 ms 42540 KB Output is correct
43 Correct 24 ms 42664 KB Output is correct
44 Correct 22 ms 42580 KB Output is correct
45 Correct 24 ms 42644 KB Output is correct
46 Correct 22 ms 42580 KB Output is correct
47 Correct 23 ms 42720 KB Output is correct
48 Correct 37 ms 45936 KB Output is correct
49 Correct 39 ms 46412 KB Output is correct
50 Correct 39 ms 46284 KB Output is correct
51 Correct 39 ms 46292 KB Output is correct
52 Correct 38 ms 46308 KB Output is correct
53 Correct 54 ms 50032 KB Output is correct
54 Correct 26 ms 43284 KB Output is correct
55 Correct 33 ms 44780 KB Output is correct
56 Correct 23 ms 42568 KB Output is correct
57 Correct 25 ms 43244 KB Output is correct
58 Correct 28 ms 43116 KB Output is correct
59 Correct 98 ms 60468 KB Output is correct
60 Correct 138 ms 70976 KB Output is correct
61 Correct 140 ms 70928 KB Output is correct
62 Correct 147 ms 70896 KB Output is correct
63 Correct 135 ms 73160 KB Output is correct
64 Correct 137 ms 70532 KB Output is correct
65 Correct 141 ms 70240 KB Output is correct
66 Correct 82 ms 53376 KB Output is correct
67 Correct 148 ms 69212 KB Output is correct
68 Correct 107 ms 63588 KB Output is correct
69 Correct 76 ms 54236 KB Output is correct
70 Correct 163 ms 65988 KB Output is correct
71 Correct 22 ms 42452 KB Output is correct
72 Correct 22 ms 42452 KB Output is correct
73 Correct 22 ms 42476 KB Output is correct
74 Correct 22 ms 42452 KB Output is correct
75 Correct 24 ms 42628 KB Output is correct
76 Correct 23 ms 42488 KB Output is correct
77 Correct 28 ms 45672 KB Output is correct
78 Correct 29 ms 45652 KB Output is correct
79 Correct 28 ms 45644 KB Output is correct
80 Correct 31 ms 45652 KB Output is correct
81 Correct 116 ms 58424 KB Output is correct
82 Correct 146 ms 66040 KB Output is correct
83 Correct 131 ms 65980 KB Output is correct
84 Correct 154 ms 70108 KB Output is correct
85 Correct 151 ms 69924 KB Output is correct
86 Correct 188 ms 74180 KB Output is correct
87 Correct 190 ms 74592 KB Output is correct
88 Correct 23 ms 42568 KB Output is correct
89 Correct 203 ms 75360 KB Output is correct
90 Correct 175 ms 71456 KB Output is correct
91 Correct 171 ms 70492 KB Output is correct