답안 #746092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746092 2023-05-21T12:08:41 Z sofapuden 메기 농장 (IOI22_fish) C++17
100 / 100
549 ms 65144 KB
#include"fish.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mxN = 4e5+5;

vector<array<int,3>> v;
ll dp[mxN][2][2];
int N;
vector<vector<pair<ll,ll>>> pref;

ll pr(int x, ll y1, ll y2){ // [y1, y2[
	auto z1 = prev(lower_bound(pref[x].begin(),pref[x].end(),make_pair(y1,-1ll)));
	auto z2 = prev(lower_bound(pref[x].begin(),pref[x].end(),make_pair(y2,-1ll)));
	return z2->second - z1->second;
}

ll nxt(int x, int y){
	return lower_bound(v.begin(),v.end(),(array<int,3>){x+1,y,-1}) - v.begin();
}

ll f(int ind, int dir, int point){
	if(~dp[ind][dir][point])return dp[ind][dir][point];
	auto &d = dp[ind][dir][point] = 0;
	auto z = nxt(v[ind][0],v[ind][1]);
	if(dir == 1){
		if(ind != N - 1 && v[ind][0] == v[ind+1][0]) 
			d = max(d, f(ind+1,1,point) + point * (v[ind][0] ? pr(v[ind][0]-1, v[ind][1], v[ind+1][1]) : 0));
		if(z != N)
			d = max(d, f(z,1,1) + pr(v[ind][0], v[ind][1], v[z][1]));
	}
	else{
		if(ind != 0 && v[ind][0] == v[ind-1][0]) 
			d = max(d, f(ind-1,0,1) + v[ind-1][2]);
	}
	if(z != N && v[z][0] == v[z-1][0])
		d = max(d, f(z-1,0,1) + v[z-1][2]);
	auto z2 = nxt(v[ind][0]+1,v[ind][1]);
	auto z3 = nxt(v[ind][0]+1,-5);
	if(z3 != N)
		d = max(d, f(z3,1,0) + pr(v[ind][0]+1,-2,v[ind][1]));
	if(z2 != N)
		d = max(d, f(z2,1,1) + pr(v[ind][0]+1,-2,v[z2][1]));
	return d;
}

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
	memset(dp,-1,sizeof dp);
	pref.resize(n,{{-5,0}});
	for(int i = 0; i < m; ++i)v.push_back({x[i],y[i],w[i]});
	for(int i = 0; i < n; ++i)v.push_back({i,n,0});
	sort(v.begin(),v.end());
	N = v.size();
	for(int i = 0; i < N; ++i){
		pref[v[i][0]].emplace_back(v[i][1], pref[v[i][0]].back().second + v[i][2]);
	}
	return f(0,1,1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 45116 KB Output is correct
2 Correct 141 ms 50456 KB Output is correct
3 Correct 73 ms 31936 KB Output is correct
4 Correct 73 ms 32012 KB Output is correct
5 Correct 332 ms 65144 KB Output is correct
6 Correct 444 ms 56272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12756 KB Output is correct
2 Correct 217 ms 50796 KB Output is correct
3 Correct 251 ms 57136 KB Output is correct
4 Correct 120 ms 45216 KB Output is correct
5 Correct 144 ms 50376 KB Output is correct
6 Correct 5 ms 12756 KB Output is correct
7 Correct 6 ms 12716 KB Output is correct
8 Correct 5 ms 12756 KB Output is correct
9 Correct 6 ms 12756 KB Output is correct
10 Correct 70 ms 31908 KB Output is correct
11 Correct 72 ms 31948 KB Output is correct
12 Correct 116 ms 36296 KB Output is correct
13 Correct 130 ms 39360 KB Output is correct
14 Correct 122 ms 40008 KB Output is correct
15 Correct 147 ms 43056 KB Output is correct
16 Correct 130 ms 40124 KB Output is correct
17 Correct 143 ms 43076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 31904 KB Output is correct
2 Correct 71 ms 31912 KB Output is correct
3 Correct 136 ms 34600 KB Output is correct
4 Correct 117 ms 35140 KB Output is correct
5 Correct 196 ms 40268 KB Output is correct
6 Correct 195 ms 39712 KB Output is correct
7 Correct 192 ms 40188 KB Output is correct
8 Correct 196 ms 40204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12720 KB Output is correct
2 Correct 6 ms 12740 KB Output is correct
3 Correct 6 ms 12768 KB Output is correct
4 Correct 5 ms 12760 KB Output is correct
5 Correct 6 ms 12756 KB Output is correct
6 Correct 6 ms 12720 KB Output is correct
7 Correct 7 ms 12720 KB Output is correct
8 Correct 6 ms 12740 KB Output is correct
9 Correct 6 ms 12864 KB Output is correct
10 Correct 9 ms 12964 KB Output is correct
11 Correct 6 ms 12856 KB Output is correct
12 Correct 7 ms 12876 KB Output is correct
13 Correct 6 ms 12848 KB Output is correct
14 Correct 7 ms 12956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12720 KB Output is correct
2 Correct 6 ms 12740 KB Output is correct
3 Correct 6 ms 12768 KB Output is correct
4 Correct 5 ms 12760 KB Output is correct
5 Correct 6 ms 12756 KB Output is correct
6 Correct 6 ms 12720 KB Output is correct
7 Correct 7 ms 12720 KB Output is correct
8 Correct 6 ms 12740 KB Output is correct
9 Correct 6 ms 12864 KB Output is correct
10 Correct 9 ms 12964 KB Output is correct
11 Correct 6 ms 12856 KB Output is correct
12 Correct 7 ms 12876 KB Output is correct
13 Correct 6 ms 12848 KB Output is correct
14 Correct 7 ms 12956 KB Output is correct
15 Correct 7 ms 12792 KB Output is correct
16 Correct 9 ms 13004 KB Output is correct
17 Correct 78 ms 16088 KB Output is correct
18 Correct 76 ms 16564 KB Output is correct
19 Correct 69 ms 16464 KB Output is correct
20 Correct 71 ms 16456 KB Output is correct
21 Correct 68 ms 16328 KB Output is correct
22 Correct 143 ms 19956 KB Output is correct
23 Correct 17 ms 13460 KB Output is correct
24 Correct 50 ms 14976 KB Output is correct
25 Correct 7 ms 12884 KB Output is correct
26 Correct 17 ms 13440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12720 KB Output is correct
2 Correct 6 ms 12740 KB Output is correct
3 Correct 6 ms 12768 KB Output is correct
4 Correct 5 ms 12760 KB Output is correct
5 Correct 6 ms 12756 KB Output is correct
6 Correct 6 ms 12720 KB Output is correct
7 Correct 7 ms 12720 KB Output is correct
8 Correct 6 ms 12740 KB Output is correct
9 Correct 6 ms 12864 KB Output is correct
10 Correct 9 ms 12964 KB Output is correct
11 Correct 6 ms 12856 KB Output is correct
12 Correct 7 ms 12876 KB Output is correct
13 Correct 6 ms 12848 KB Output is correct
14 Correct 7 ms 12956 KB Output is correct
15 Correct 7 ms 12792 KB Output is correct
16 Correct 9 ms 13004 KB Output is correct
17 Correct 78 ms 16088 KB Output is correct
18 Correct 76 ms 16564 KB Output is correct
19 Correct 69 ms 16464 KB Output is correct
20 Correct 71 ms 16456 KB Output is correct
21 Correct 68 ms 16328 KB Output is correct
22 Correct 143 ms 19956 KB Output is correct
23 Correct 17 ms 13460 KB Output is correct
24 Correct 50 ms 14976 KB Output is correct
25 Correct 7 ms 12884 KB Output is correct
26 Correct 17 ms 13440 KB Output is correct
27 Correct 11 ms 13620 KB Output is correct
28 Correct 378 ms 29192 KB Output is correct
29 Correct 457 ms 35276 KB Output is correct
30 Correct 431 ms 35512 KB Output is correct
31 Correct 466 ms 35640 KB Output is correct
32 Correct 487 ms 35696 KB Output is correct
33 Correct 451 ms 35560 KB Output is correct
34 Correct 450 ms 35664 KB Output is correct
35 Correct 171 ms 22144 KB Output is correct
36 Correct 484 ms 37168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 31904 KB Output is correct
2 Correct 71 ms 31912 KB Output is correct
3 Correct 136 ms 34600 KB Output is correct
4 Correct 117 ms 35140 KB Output is correct
5 Correct 196 ms 40268 KB Output is correct
6 Correct 195 ms 39712 KB Output is correct
7 Correct 192 ms 40188 KB Output is correct
8 Correct 196 ms 40204 KB Output is correct
9 Correct 183 ms 39976 KB Output is correct
10 Correct 166 ms 29216 KB Output is correct
11 Correct 321 ms 45764 KB Output is correct
12 Correct 5 ms 12756 KB Output is correct
13 Correct 5 ms 12776 KB Output is correct
14 Correct 5 ms 12756 KB Output is correct
15 Correct 5 ms 12768 KB Output is correct
16 Correct 5 ms 12720 KB Output is correct
17 Correct 6 ms 12756 KB Output is correct
18 Correct 68 ms 31904 KB Output is correct
19 Correct 70 ms 31944 KB Output is correct
20 Correct 73 ms 31940 KB Output is correct
21 Correct 74 ms 31940 KB Output is correct
22 Correct 200 ms 39840 KB Output is correct
23 Correct 335 ms 45768 KB Output is correct
24 Correct 310 ms 46172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 45116 KB Output is correct
2 Correct 141 ms 50456 KB Output is correct
3 Correct 73 ms 31936 KB Output is correct
4 Correct 73 ms 32012 KB Output is correct
5 Correct 332 ms 65144 KB Output is correct
6 Correct 444 ms 56272 KB Output is correct
7 Correct 5 ms 12756 KB Output is correct
8 Correct 217 ms 50796 KB Output is correct
9 Correct 251 ms 57136 KB Output is correct
10 Correct 120 ms 45216 KB Output is correct
11 Correct 144 ms 50376 KB Output is correct
12 Correct 5 ms 12756 KB Output is correct
13 Correct 6 ms 12716 KB Output is correct
14 Correct 5 ms 12756 KB Output is correct
15 Correct 6 ms 12756 KB Output is correct
16 Correct 70 ms 31908 KB Output is correct
17 Correct 72 ms 31948 KB Output is correct
18 Correct 116 ms 36296 KB Output is correct
19 Correct 130 ms 39360 KB Output is correct
20 Correct 122 ms 40008 KB Output is correct
21 Correct 147 ms 43056 KB Output is correct
22 Correct 130 ms 40124 KB Output is correct
23 Correct 143 ms 43076 KB Output is correct
24 Correct 72 ms 31904 KB Output is correct
25 Correct 71 ms 31912 KB Output is correct
26 Correct 136 ms 34600 KB Output is correct
27 Correct 117 ms 35140 KB Output is correct
28 Correct 196 ms 40268 KB Output is correct
29 Correct 195 ms 39712 KB Output is correct
30 Correct 192 ms 40188 KB Output is correct
31 Correct 196 ms 40204 KB Output is correct
32 Correct 5 ms 12720 KB Output is correct
33 Correct 6 ms 12740 KB Output is correct
34 Correct 6 ms 12768 KB Output is correct
35 Correct 5 ms 12760 KB Output is correct
36 Correct 6 ms 12756 KB Output is correct
37 Correct 6 ms 12720 KB Output is correct
38 Correct 7 ms 12720 KB Output is correct
39 Correct 6 ms 12740 KB Output is correct
40 Correct 6 ms 12864 KB Output is correct
41 Correct 9 ms 12964 KB Output is correct
42 Correct 6 ms 12856 KB Output is correct
43 Correct 7 ms 12876 KB Output is correct
44 Correct 6 ms 12848 KB Output is correct
45 Correct 7 ms 12956 KB Output is correct
46 Correct 7 ms 12792 KB Output is correct
47 Correct 9 ms 13004 KB Output is correct
48 Correct 78 ms 16088 KB Output is correct
49 Correct 76 ms 16564 KB Output is correct
50 Correct 69 ms 16464 KB Output is correct
51 Correct 71 ms 16456 KB Output is correct
52 Correct 68 ms 16328 KB Output is correct
53 Correct 143 ms 19956 KB Output is correct
54 Correct 17 ms 13460 KB Output is correct
55 Correct 50 ms 14976 KB Output is correct
56 Correct 7 ms 12884 KB Output is correct
57 Correct 17 ms 13440 KB Output is correct
58 Correct 11 ms 13620 KB Output is correct
59 Correct 378 ms 29192 KB Output is correct
60 Correct 457 ms 35276 KB Output is correct
61 Correct 431 ms 35512 KB Output is correct
62 Correct 466 ms 35640 KB Output is correct
63 Correct 487 ms 35696 KB Output is correct
64 Correct 451 ms 35560 KB Output is correct
65 Correct 450 ms 35664 KB Output is correct
66 Correct 171 ms 22144 KB Output is correct
67 Correct 484 ms 37168 KB Output is correct
68 Correct 183 ms 39976 KB Output is correct
69 Correct 166 ms 29216 KB Output is correct
70 Correct 321 ms 45764 KB Output is correct
71 Correct 5 ms 12756 KB Output is correct
72 Correct 5 ms 12776 KB Output is correct
73 Correct 5 ms 12756 KB Output is correct
74 Correct 5 ms 12768 KB Output is correct
75 Correct 5 ms 12720 KB Output is correct
76 Correct 6 ms 12756 KB Output is correct
77 Correct 68 ms 31904 KB Output is correct
78 Correct 70 ms 31944 KB Output is correct
79 Correct 73 ms 31940 KB Output is correct
80 Correct 74 ms 31940 KB Output is correct
81 Correct 200 ms 39840 KB Output is correct
82 Correct 335 ms 45768 KB Output is correct
83 Correct 310 ms 46172 KB Output is correct
84 Correct 546 ms 51352 KB Output is correct
85 Correct 549 ms 52688 KB Output is correct
86 Correct 461 ms 53680 KB Output is correct
87 Correct 469 ms 56004 KB Output is correct
88 Correct 6 ms 12756 KB Output is correct
89 Correct 462 ms 55944 KB Output is correct
90 Correct 485 ms 54808 KB Output is correct
91 Correct 486 ms 54732 KB Output is correct