답안 #639772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639772 2022-09-11T15:07:50 Z study 메기 농장 (IOI22_fish) C++17
100 / 100
296 ms 84064 KB
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;

const int MAXN = 1e5+1;

vector<long long> dp[3][MAXN];
vector<pair<int,long long>> grid[MAXN],init[MAXN];

long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W){
	for (int i=0; i<N; ++i) grid[i].emplace_back(0,0);
	for (int i=0; i<M; ++i){
		Y[i]++;
		init[X[i]].emplace_back(Y[i],W[i]);
		if (X[i]-1 >= 0) init[X[i]-1].emplace_back(Y[i],0);
		if (X[i]+1 < N) init[X[i]+1].emplace_back(Y[i],0);
	}
	for (int i=0; i<N; ++i){
		sort(init[i].begin(),init[i].end());
		for (auto k:init[i]){
			if (grid[i].back().first == k.first) grid[i].back().second += k.second;
			else grid[i].emplace_back(k);
		}
	}
	dp[0][0] = vector<long long>(grid[0].size());
	dp[1][0] = vector<long long>(grid[0].size());
	dp[2][0].emplace_back(0);
	long long ans = 0;
	for (int x=1; x<N; ++x){
		int siz = grid[x].size();
		dp[0][x] = vector<long long>(siz);
		dp[1][x] = vector<long long>(siz);
		dp[2][x].emplace_back(0);
		long long sum = 0, best = 0, sum2 = 0, sum3 = 0, idx2 = 0;
		for (int idx=0; idx<grid[x].size(); ++idx){
			while (idx2 < grid[x-1].size() and grid[x-1][idx2].first <= grid[x][idx].first){
				sum += grid[x-1][idx2].second;
				sum = max(sum,dp[1][x-1][idx2]);
				idx2++;
			}
			if (idx == 0) sum = max(sum,dp[2][x-1][0]);
			if (idx == 0) best = max(best,dp[0][x-1][0]);
			dp[1][x][idx] = max(best,sum);
			ans = max({best,sum,ans});
		}
		idx2 = grid[x-1].size()-1;
		for (int idx=grid[x].size()-1; idx>=0; --idx){
			while (idx2 >= 0 and grid[x-1][idx2].first >= grid[x][idx].first){
				sum2 = max({sum2,dp[1][x-1][idx2],dp[0][x-1][idx2]});
				sum3 = max({sum3,dp[1][x-1][idx2],dp[0][x-1][idx2]});
				idx2--;
			}
			dp[0][x][idx] = sum2;
			dp[2][x][0] = max(dp[2][x][0],sum3);
			ans = max({ans,sum2,dp[2][x][0]});
			sum2 += grid[x][idx].second;
		}
	}
	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:35:22: 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]
   35 |   for (int idx=0; idx<grid[x].size(); ++idx){
      |                   ~~~^~~~~~~~~~~~~~~
fish.cpp:36:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    while (idx2 < grid[x-1].size() and grid[x-1][idx2].first <= grid[x][idx].first){
      |           ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 32732 KB Output is correct
2 Correct 84 ms 36220 KB Output is correct
3 Correct 34 ms 24496 KB Output is correct
4 Correct 28 ms 24452 KB Output is correct
5 Correct 228 ms 74120 KB Output is correct
6 Correct 296 ms 83656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 121 ms 41540 KB Output is correct
3 Correct 142 ms 46420 KB Output is correct
4 Correct 69 ms 32716 KB Output is correct
5 Correct 94 ms 36328 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 12048 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 25 ms 24532 KB Output is correct
11 Correct 27 ms 24568 KB Output is correct
12 Correct 85 ms 36640 KB Output is correct
13 Correct 94 ms 40964 KB Output is correct
14 Correct 77 ms 34656 KB Output is correct
15 Correct 80 ms 34704 KB Output is correct
16 Correct 70 ms 35120 KB Output is correct
17 Correct 99 ms 37204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24436 KB Output is correct
2 Correct 24 ms 24564 KB Output is correct
3 Correct 61 ms 29700 KB Output is correct
4 Correct 49 ms 28948 KB Output is correct
5 Correct 97 ms 36616 KB Output is correct
6 Correct 98 ms 36608 KB Output is correct
7 Correct 97 ms 36524 KB Output is correct
8 Correct 97 ms 36540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12036 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 11996 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 9 ms 12068 KB Output is correct
8 Correct 8 ms 12040 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12372 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 8 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12036 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 11996 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 9 ms 12068 KB Output is correct
8 Correct 8 ms 12040 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12372 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 8 ms 12116 KB Output is correct
15 Correct 6 ms 12116 KB Output is correct
16 Correct 7 ms 12372 KB Output is correct
17 Correct 29 ms 18476 KB Output is correct
18 Correct 32 ms 18048 KB Output is correct
19 Correct 28 ms 17740 KB Output is correct
20 Correct 28 ms 17428 KB Output is correct
21 Correct 29 ms 17444 KB Output is correct
22 Correct 56 ms 22892 KB Output is correct
23 Correct 12 ms 13780 KB Output is correct
24 Correct 26 ms 17404 KB Output is correct
25 Correct 8 ms 12244 KB Output is correct
26 Correct 11 ms 13652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12036 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 11996 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 9 ms 12068 KB Output is correct
8 Correct 8 ms 12040 KB Output is correct
9 Correct 6 ms 12116 KB Output is correct
10 Correct 7 ms 12372 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12244 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 8 ms 12116 KB Output is correct
15 Correct 6 ms 12116 KB Output is correct
16 Correct 7 ms 12372 KB Output is correct
17 Correct 29 ms 18476 KB Output is correct
18 Correct 32 ms 18048 KB Output is correct
19 Correct 28 ms 17740 KB Output is correct
20 Correct 28 ms 17428 KB Output is correct
21 Correct 29 ms 17444 KB Output is correct
22 Correct 56 ms 22892 KB Output is correct
23 Correct 12 ms 13780 KB Output is correct
24 Correct 26 ms 17404 KB Output is correct
25 Correct 8 ms 12244 KB Output is correct
26 Correct 11 ms 13652 KB Output is correct
27 Correct 9 ms 12948 KB Output is correct
28 Correct 120 ms 38772 KB Output is correct
29 Correct 168 ms 52392 KB Output is correct
30 Correct 180 ms 80964 KB Output is correct
31 Correct 179 ms 80328 KB Output is correct
32 Correct 159 ms 47956 KB Output is correct
33 Correct 176 ms 81344 KB Output is correct
34 Correct 180 ms 81228 KB Output is correct
35 Correct 72 ms 32588 KB Output is correct
36 Correct 180 ms 65760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24436 KB Output is correct
2 Correct 24 ms 24564 KB Output is correct
3 Correct 61 ms 29700 KB Output is correct
4 Correct 49 ms 28948 KB Output is correct
5 Correct 97 ms 36616 KB Output is correct
6 Correct 98 ms 36608 KB Output is correct
7 Correct 97 ms 36524 KB Output is correct
8 Correct 97 ms 36540 KB Output is correct
9 Correct 108 ms 42760 KB Output is correct
10 Correct 90 ms 30116 KB Output is correct
11 Correct 181 ms 48320 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 7 ms 12040 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 12040 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 26 ms 24536 KB Output is correct
19 Correct 29 ms 24460 KB Output is correct
20 Correct 26 ms 24516 KB Output is correct
21 Correct 25 ms 24532 KB Output is correct
22 Correct 115 ms 43040 KB Output is correct
23 Correct 178 ms 55996 KB Output is correct
24 Correct 200 ms 56828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 32732 KB Output is correct
2 Correct 84 ms 36220 KB Output is correct
3 Correct 34 ms 24496 KB Output is correct
4 Correct 28 ms 24452 KB Output is correct
5 Correct 228 ms 74120 KB Output is correct
6 Correct 296 ms 83656 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 121 ms 41540 KB Output is correct
9 Correct 142 ms 46420 KB Output is correct
10 Correct 69 ms 32716 KB Output is correct
11 Correct 94 ms 36328 KB Output is correct
12 Correct 7 ms 11988 KB Output is correct
13 Correct 7 ms 12048 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 25 ms 24532 KB Output is correct
17 Correct 27 ms 24568 KB Output is correct
18 Correct 85 ms 36640 KB Output is correct
19 Correct 94 ms 40964 KB Output is correct
20 Correct 77 ms 34656 KB Output is correct
21 Correct 80 ms 34704 KB Output is correct
22 Correct 70 ms 35120 KB Output is correct
23 Correct 99 ms 37204 KB Output is correct
24 Correct 26 ms 24436 KB Output is correct
25 Correct 24 ms 24564 KB Output is correct
26 Correct 61 ms 29700 KB Output is correct
27 Correct 49 ms 28948 KB Output is correct
28 Correct 97 ms 36616 KB Output is correct
29 Correct 98 ms 36608 KB Output is correct
30 Correct 97 ms 36524 KB Output is correct
31 Correct 97 ms 36540 KB Output is correct
32 Correct 6 ms 11988 KB Output is correct
33 Correct 6 ms 12036 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 6 ms 11996 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 9 ms 12068 KB Output is correct
39 Correct 8 ms 12040 KB Output is correct
40 Correct 6 ms 12116 KB Output is correct
41 Correct 7 ms 12372 KB Output is correct
42 Correct 7 ms 12116 KB Output is correct
43 Correct 7 ms 12244 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 8 ms 12116 KB Output is correct
46 Correct 6 ms 12116 KB Output is correct
47 Correct 7 ms 12372 KB Output is correct
48 Correct 29 ms 18476 KB Output is correct
49 Correct 32 ms 18048 KB Output is correct
50 Correct 28 ms 17740 KB Output is correct
51 Correct 28 ms 17428 KB Output is correct
52 Correct 29 ms 17444 KB Output is correct
53 Correct 56 ms 22892 KB Output is correct
54 Correct 12 ms 13780 KB Output is correct
55 Correct 26 ms 17404 KB Output is correct
56 Correct 8 ms 12244 KB Output is correct
57 Correct 11 ms 13652 KB Output is correct
58 Correct 9 ms 12948 KB Output is correct
59 Correct 120 ms 38772 KB Output is correct
60 Correct 168 ms 52392 KB Output is correct
61 Correct 180 ms 80964 KB Output is correct
62 Correct 179 ms 80328 KB Output is correct
63 Correct 159 ms 47956 KB Output is correct
64 Correct 176 ms 81344 KB Output is correct
65 Correct 180 ms 81228 KB Output is correct
66 Correct 72 ms 32588 KB Output is correct
67 Correct 180 ms 65760 KB Output is correct
68 Correct 108 ms 42760 KB Output is correct
69 Correct 90 ms 30116 KB Output is correct
70 Correct 181 ms 48320 KB Output is correct
71 Correct 6 ms 11988 KB Output is correct
72 Correct 7 ms 12040 KB Output is correct
73 Correct 6 ms 11988 KB Output is correct
74 Correct 6 ms 11988 KB Output is correct
75 Correct 7 ms 12040 KB Output is correct
76 Correct 6 ms 11988 KB Output is correct
77 Correct 26 ms 24536 KB Output is correct
78 Correct 29 ms 24460 KB Output is correct
79 Correct 26 ms 24516 KB Output is correct
80 Correct 25 ms 24532 KB Output is correct
81 Correct 115 ms 43040 KB Output is correct
82 Correct 178 ms 55996 KB Output is correct
83 Correct 200 ms 56828 KB Output is correct
84 Correct 214 ms 69948 KB Output is correct
85 Correct 207 ms 71172 KB Output is correct
86 Correct 284 ms 82348 KB Output is correct
87 Correct 295 ms 84064 KB Output is correct
88 Correct 6 ms 11988 KB Output is correct
89 Correct 283 ms 84044 KB Output is correct
90 Correct 221 ms 76020 KB Output is correct
91 Correct 214 ms 66628 KB Output is correct