답안 #1077233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077233 2024-08-27T03:40:15 Z pcc 메기 농장 (IOI22_fish) C++17
100 / 100
879 ms 93328 KB
#include "fish.h"

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

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fs first
#define sc second
#define tiii tuple<int,int,int>
#define tlll tuple<ll,ll,ll>

const ll inf = 1e18;
const int mxn = 1e5+10;
vector<pii> fish[mxn];
vector<pll> dp[mxn][2];
ll big = 0;

ll f(int idx,int s,int e){
	ll re = 0;
	for(auto &[pos,w]:fish[idx]){
		if(pos>s&&pos<=e)re += w;
	}
	return re;
}

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++){
		fish[X[i]].push_back(pii(Y[i],W[i]));
	}
	for(int i = 0;i<N;i++)fish[i].push_back(pii(N,0));
	for(int i = 0;i<N;i++)sort(fish[i].begin(),fish[i].end());

	{
		vector<pii> v;
		for(auto &[pos,w]:fish[0]){
			if(pos)v.push_back(pii(pos-1,-1));
		}
		for(auto &[pos,w]:fish[1]){
			v.push_back(pii(pos,w));
			v.push_back(pii(pos,-1));
		}
		sort(v.begin(),v.end());
		ll sum = 0;
		for(auto &[a,b]:v){
			if(b == -1)dp[0][0].push_back(pll(a,sum));
			else sum += b;
		}
		sort(dp[0][0].begin(),dp[0][0].end());
		dp[0][0].resize(unique(dp[0][0].begin(),dp[0][0].end())-dp[0][0].begin());
	}

	for(int i = 1;i<N;i++){
		ll ls = 0,ms = 0,rs = 0;
		vector<tlll> v;

		//cerr<<"CALC "<<i<<":"<<endl;

		for(auto &[pos,w]:fish[i]){
			if(pos)v.push_back(tlll(pos-1,0,-1));
			v.push_back(tlll(pos,-4,w));
		}
		for(auto &[pos,w]:fish[i-1]){
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-3,w));
		}
		for(auto &[pos,w]:fish[i+1]){
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-5,w));
		}
		sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
		for(auto &[pos,w]:dp[i-1][0])v.push_back(tlll(pos,-2,w));//tp == -2:trans
		if(i-2>=0){
			for(int j = 0;j<2;j++)for(auto &[pos,w]:dp[i-2][j])v.push_back(tlll(pos,-1,w));
		}
		sort(v.begin(),v.end());
		ll mx1 = -inf,mx2 = -inf;
		for(auto &[pos,tp,val]:v){
			//cerr<<"["<<pos<<','<<tp<<','<<val<<','<<ls<<' '<<ms<<' '<<rs<<"]"<<endl;
			if(tp == -5)rs+=val;
			else if(tp == -4)ms+=val;
			else if(tp == -3)ls+=val;
			else if(tp == -2)mx1 = max(mx1,val-ms-ls);
			else if(tp == -1)mx2 = max(mx2,val-ls);
			else{
				val = max({big+ls+rs,mx1+ls+rs,mx2+ls+rs});
			}
		}
		//cerr<<endl;
		mx1 = 0;
		reverse(v.begin(),v.end());
		for(auto &[pos,tp,val]:v){
			if(tp == -5)rs -= val;
			else if(tp == -1){
				mx1 = max(mx1,val);
			}
			else if(tp == 0){
				val = max(val,rs+mx1);
				dp[i][0].push_back(pll(pos,val));
			}
		}

		ls = rs = ms;
		mx1 = mx2 = -inf;
		v.clear();

		for(auto &[pos,w]:fish[i]){
			if(pos)v.push_back(tlll(pos-1,0,-1));
			ms += w;
			v.push_back(tlll(pos,-4,w));
		}
		for(auto &[pos,w]:fish[i-1]){
			ls += w;
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-3,w));
		}
		for(auto &[pos,w]:fish[i+1]){
			rs += w;
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-5,w));
		}
		sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
		for(auto &[pos,w]:dp[i-1][0])v.push_back(tlll(pos,2,w));//tp == 2:trans
		for(auto &[pos,w]:dp[i-1][1])v.push_back(tlll(pos,2,w));//tp == 2:trans
		sort(v.rbegin(),v.rend());
		mx1 = -inf,mx2 = -inf;
		for(auto &[pos,tp,val]:v){
			if(tp == -5)rs-=val;
			else if(tp == -4)ms-=val;
			else if(tp == -3)ls-=val;
			else if(tp == 2)mx1 = max(mx1,val);
			else{
				val = mx1-ms+rs;
				dp[i][1].push_back(pll(pos,val));
			}
		}

		if(i-2>=0){
			for(int j = 0;j<2;j++)for(auto &[a,b]:dp[i-2][j])big = max(big,b);
		}

	}
	ll ans = 0;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<2;j++){
			for(auto [a,b]:dp[i][j])ans = max(ans,b);
			//cerr<<i<<' '<<j<<":";for(auto [a,b]:dp[i][j])cerr<<a<<','<<b<<' ';cerr<<endl;
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 27924 KB Output is correct
2 Correct 216 ms 31528 KB Output is correct
3 Correct 74 ms 19912 KB Output is correct
4 Correct 67 ms 19992 KB Output is correct
5 Correct 879 ms 93328 KB Output is correct
6 Correct 620 ms 78000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 328 ms 42900 KB Output is correct
3 Correct 412 ms 51392 KB Output is correct
4 Correct 213 ms 28436 KB Output is correct
5 Correct 223 ms 31372 KB Output is correct
6 Correct 3 ms 7256 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7336 KB Output is correct
9 Correct 3 ms 7256 KB Output is correct
10 Correct 66 ms 19796 KB Output is correct
11 Correct 69 ms 19796 KB Output is correct
12 Correct 245 ms 38516 KB Output is correct
13 Correct 295 ms 44176 KB Output is correct
14 Correct 221 ms 31296 KB Output is correct
15 Correct 209 ms 30248 KB Output is correct
16 Correct 258 ms 31220 KB Output is correct
17 Correct 232 ms 38364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 19792 KB Output is correct
2 Correct 74 ms 19980 KB Output is correct
3 Correct 93 ms 24404 KB Output is correct
4 Correct 90 ms 23892 KB Output is correct
5 Correct 131 ms 30160 KB Output is correct
6 Correct 126 ms 29520 KB Output is correct
7 Correct 121 ms 29996 KB Output is correct
8 Correct 127 ms 30032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 4 ms 7256 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7256 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 5 ms 7516 KB Output is correct
10 Correct 6 ms 7772 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 5 ms 7444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 4 ms 7256 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7256 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 5 ms 7516 KB Output is correct
10 Correct 6 ms 7772 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 5 ms 7444 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 7 ms 7772 KB Output is correct
17 Correct 73 ms 12720 KB Output is correct
18 Correct 70 ms 12580 KB Output is correct
19 Correct 59 ms 12628 KB Output is correct
20 Correct 58 ms 12368 KB Output is correct
21 Correct 41 ms 12116 KB Output is correct
22 Correct 102 ms 16916 KB Output is correct
23 Correct 20 ms 9048 KB Output is correct
24 Correct 59 ms 11492 KB Output is correct
25 Correct 6 ms 7512 KB Output is correct
26 Correct 18 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 4 ms 7256 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7256 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 5 ms 7516 KB Output is correct
10 Correct 6 ms 7772 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 5 ms 7444 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 7 ms 7772 KB Output is correct
17 Correct 73 ms 12720 KB Output is correct
18 Correct 70 ms 12580 KB Output is correct
19 Correct 59 ms 12628 KB Output is correct
20 Correct 58 ms 12368 KB Output is correct
21 Correct 41 ms 12116 KB Output is correct
22 Correct 102 ms 16916 KB Output is correct
23 Correct 20 ms 9048 KB Output is correct
24 Correct 59 ms 11492 KB Output is correct
25 Correct 6 ms 7512 KB Output is correct
26 Correct 18 ms 9048 KB Output is correct
27 Correct 7 ms 8028 KB Output is correct
28 Correct 377 ms 31480 KB Output is correct
29 Correct 549 ms 47228 KB Output is correct
30 Correct 600 ms 71228 KB Output is correct
31 Correct 616 ms 70964 KB Output is correct
32 Correct 384 ms 42132 KB Output is correct
33 Correct 629 ms 71504 KB Output is correct
34 Correct 621 ms 71212 KB Output is correct
35 Correct 203 ms 25684 KB Output is correct
36 Correct 607 ms 61160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 19792 KB Output is correct
2 Correct 74 ms 19980 KB Output is correct
3 Correct 93 ms 24404 KB Output is correct
4 Correct 90 ms 23892 KB Output is correct
5 Correct 131 ms 30160 KB Output is correct
6 Correct 126 ms 29520 KB Output is correct
7 Correct 121 ms 29996 KB Output is correct
8 Correct 127 ms 30032 KB Output is correct
9 Correct 135 ms 29756 KB Output is correct
10 Correct 101 ms 22100 KB Output is correct
11 Correct 203 ms 36692 KB Output is correct
12 Correct 3 ms 7260 KB Output is correct
13 Correct 4 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 3 ms 7328 KB Output is correct
16 Correct 3 ms 7308 KB Output is correct
17 Correct 4 ms 7260 KB Output is correct
18 Correct 65 ms 19832 KB Output is correct
19 Correct 61 ms 19860 KB Output is correct
20 Correct 72 ms 19740 KB Output is correct
21 Correct 64 ms 19796 KB Output is correct
22 Correct 246 ms 38776 KB Output is correct
23 Correct 288 ms 49744 KB Output is correct
24 Correct 271 ms 50808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 27924 KB Output is correct
2 Correct 216 ms 31528 KB Output is correct
3 Correct 74 ms 19912 KB Output is correct
4 Correct 67 ms 19992 KB Output is correct
5 Correct 879 ms 93328 KB Output is correct
6 Correct 620 ms 78000 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 328 ms 42900 KB Output is correct
9 Correct 412 ms 51392 KB Output is correct
10 Correct 213 ms 28436 KB Output is correct
11 Correct 223 ms 31372 KB Output is correct
12 Correct 3 ms 7256 KB Output is correct
13 Correct 3 ms 7260 KB Output is correct
14 Correct 3 ms 7336 KB Output is correct
15 Correct 3 ms 7256 KB Output is correct
16 Correct 66 ms 19796 KB Output is correct
17 Correct 69 ms 19796 KB Output is correct
18 Correct 245 ms 38516 KB Output is correct
19 Correct 295 ms 44176 KB Output is correct
20 Correct 221 ms 31296 KB Output is correct
21 Correct 209 ms 30248 KB Output is correct
22 Correct 258 ms 31220 KB Output is correct
23 Correct 232 ms 38364 KB Output is correct
24 Correct 66 ms 19792 KB Output is correct
25 Correct 74 ms 19980 KB Output is correct
26 Correct 93 ms 24404 KB Output is correct
27 Correct 90 ms 23892 KB Output is correct
28 Correct 131 ms 30160 KB Output is correct
29 Correct 126 ms 29520 KB Output is correct
30 Correct 121 ms 29996 KB Output is correct
31 Correct 127 ms 30032 KB Output is correct
32 Correct 3 ms 7260 KB Output is correct
33 Correct 3 ms 7260 KB Output is correct
34 Correct 3 ms 7260 KB Output is correct
35 Correct 4 ms 7256 KB Output is correct
36 Correct 3 ms 7260 KB Output is correct
37 Correct 3 ms 7260 KB Output is correct
38 Correct 3 ms 7256 KB Output is correct
39 Correct 3 ms 7260 KB Output is correct
40 Correct 5 ms 7516 KB Output is correct
41 Correct 6 ms 7772 KB Output is correct
42 Correct 5 ms 7516 KB Output is correct
43 Correct 6 ms 7516 KB Output is correct
44 Correct 4 ms 7516 KB Output is correct
45 Correct 5 ms 7444 KB Output is correct
46 Correct 4 ms 7516 KB Output is correct
47 Correct 7 ms 7772 KB Output is correct
48 Correct 73 ms 12720 KB Output is correct
49 Correct 70 ms 12580 KB Output is correct
50 Correct 59 ms 12628 KB Output is correct
51 Correct 58 ms 12368 KB Output is correct
52 Correct 41 ms 12116 KB Output is correct
53 Correct 102 ms 16916 KB Output is correct
54 Correct 20 ms 9048 KB Output is correct
55 Correct 59 ms 11492 KB Output is correct
56 Correct 6 ms 7512 KB Output is correct
57 Correct 18 ms 9048 KB Output is correct
58 Correct 7 ms 8028 KB Output is correct
59 Correct 377 ms 31480 KB Output is correct
60 Correct 549 ms 47228 KB Output is correct
61 Correct 600 ms 71228 KB Output is correct
62 Correct 616 ms 70964 KB Output is correct
63 Correct 384 ms 42132 KB Output is correct
64 Correct 629 ms 71504 KB Output is correct
65 Correct 621 ms 71212 KB Output is correct
66 Correct 203 ms 25684 KB Output is correct
67 Correct 607 ms 61160 KB Output is correct
68 Correct 135 ms 29756 KB Output is correct
69 Correct 101 ms 22100 KB Output is correct
70 Correct 203 ms 36692 KB Output is correct
71 Correct 3 ms 7260 KB Output is correct
72 Correct 4 ms 7260 KB Output is correct
73 Correct 3 ms 7260 KB Output is correct
74 Correct 3 ms 7328 KB Output is correct
75 Correct 3 ms 7308 KB Output is correct
76 Correct 4 ms 7260 KB Output is correct
77 Correct 65 ms 19832 KB Output is correct
78 Correct 61 ms 19860 KB Output is correct
79 Correct 72 ms 19740 KB Output is correct
80 Correct 64 ms 19796 KB Output is correct
81 Correct 246 ms 38776 KB Output is correct
82 Correct 288 ms 49744 KB Output is correct
83 Correct 271 ms 50808 KB Output is correct
84 Correct 812 ms 68256 KB Output is correct
85 Correct 829 ms 71832 KB Output is correct
86 Correct 635 ms 74800 KB Output is correct
87 Correct 679 ms 77228 KB Output is correct
88 Correct 4 ms 7256 KB Output is correct
89 Correct 666 ms 77168 KB Output is correct
90 Correct 602 ms 64336 KB Output is correct
91 Correct 492 ms 53604 KB Output is correct