답안 #640778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640778 2022-09-15T08:09:18 Z wiktorlew 메기 농장 (IOI22_fish) C++17
100 / 100
750 ms 111248 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const int M = 3e5 + 5;
const long long LL = 1e18;
ll ans;
map<ll, ll> dp[N][2];
vector<pair<ll, ll>> pref[N];
vector<int> wys[N];
ll max_weights(int n, int m, vector<int>X, vector<int>Y, vector<int>Z){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		pref[X[i]].pb({Y[i], Z[i]});
		wys[X[i]].pb(Y[i]);
	}
	for(int i = 0; i < n; ++i) {
        wys[i].pb(n);
        wys[i].pb(0);
        sort(wys[i].begin(), wys[i].end());
        wys[i].erase(unique(wys[i].begin(), wys[i].end()), wys[i].end());
    }
	for(int i=0;i<n;i++){
		sort(pref[i].begin(), pref[i].end());
		ll suma=0;
		for(int j=0;j<(int)pref[i].size();j++) {
            suma+=pref[i][j].second;
            pref[i][j].second = suma;
        }
        pref[i].insert(pref[i].begin(), make_pair(-1, 0));
	}
	for(int i=1;i<n;i++){
		vector<pair<ll, ll>> spr1, spr2;
		for(ll pom : wys[i-1]){
			dp[i][0][0]=max({dp[i][0][0], dp[i-1][0][pom], dp[i-1][1][pom]});
			dp[i][1][0]=max({dp[i][1][0], dp[i-1][0][pom], dp[i-1][1][pom]});
			ll res=0;
			if(!spr1.empty()) res=spr1.back().second;
			auto it = upper_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom-1, LL));
			it--;
			res=max(res, dp[i-1][0][pom]-it->second);
			spr1.pb({pom, res});
		}
		reverse(wys[i-1].begin(), wys[i-1].end());
		for(ll pom : wys[i-1]){
			ll res=0;
			if(!spr2.empty()) res=spr2.back().second;
			auto it = upper_bound(pref[i].begin(), pref[i].end(), make_pair(pom-1, LL));
			it--;
			res = max(res, dp[i - 1][0][pom] + it->second);
            res = max(res, dp[i - 1][1][pom] + it->second);
            spr2.pb({pom, res});
		}
		reverse(spr2.begin(), spr2.end());
		for(ll pom : wys[i]){
			auto op1 = upper_bound(spr1.begin(), spr1.end(), make_pair(pom, LL));
			op1--;
			auto op2 = lower_bound(spr2.begin(), spr2.end(), make_pair(pom, -LL));
			auto tmp1 = upper_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom-1, LL));
			tmp1--;
			dp[i][0][pom]=max(dp[i][0][pom], op1->second + tmp1->second);
			auto tmp2 = upper_bound(pref[i].begin(), pref[i].end(), make_pair(pom-1, LL));
			tmp2--;
			dp[i][1][pom]=max(dp[i][1][pom], op2->second - tmp2->second);
		}
	}
	for(int i=0;i<=n;i++){
		ans = max({ans, dp[n-1][0][i], dp[n-1][1][i]});
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 67416 KB Output is correct
2 Correct 272 ms 75024 KB Output is correct
3 Correct 140 ms 58136 KB Output is correct
4 Correct 120 ms 58200 KB Output is correct
5 Correct 750 ms 108836 KB Output is correct
6 Correct 493 ms 110940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 434 ms 81332 KB Output is correct
3 Correct 542 ms 91836 KB Output is correct
4 Correct 257 ms 67412 KB Output is correct
5 Correct 293 ms 75008 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 12 ms 14296 KB Output is correct
8 Correct 9 ms 14292 KB Output is correct
9 Correct 7 ms 14292 KB Output is correct
10 Correct 122 ms 58188 KB Output is correct
11 Correct 120 ms 58100 KB Output is correct
12 Correct 275 ms 67576 KB Output is correct
13 Correct 315 ms 75004 KB Output is correct
14 Correct 232 ms 67384 KB Output is correct
15 Correct 272 ms 73488 KB Output is correct
16 Correct 237 ms 67476 KB Output is correct
17 Correct 271 ms 73268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 58196 KB Output is correct
2 Correct 119 ms 58184 KB Output is correct
3 Correct 141 ms 56468 KB Output is correct
4 Correct 142 ms 59588 KB Output is correct
5 Correct 194 ms 65240 KB Output is correct
6 Correct 189 ms 65228 KB Output is correct
7 Correct 183 ms 65220 KB Output is correct
8 Correct 188 ms 65240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 8 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 9 ms 14804 KB Output is correct
11 Correct 8 ms 14548 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 8 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 9 ms 14804 KB Output is correct
11 Correct 8 ms 14548 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14612 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 9 ms 14676 KB Output is correct
17 Correct 58 ms 22160 KB Output is correct
18 Correct 61 ms 22784 KB Output is correct
19 Correct 55 ms 22732 KB Output is correct
20 Correct 55 ms 22616 KB Output is correct
21 Correct 54 ms 22604 KB Output is correct
22 Correct 110 ms 30812 KB Output is correct
23 Correct 15 ms 16084 KB Output is correct
24 Correct 40 ms 19712 KB Output is correct
25 Correct 8 ms 14716 KB Output is correct
26 Correct 15 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 8 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 9 ms 14804 KB Output is correct
11 Correct 8 ms 14548 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14612 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 9 ms 14676 KB Output is correct
17 Correct 58 ms 22160 KB Output is correct
18 Correct 61 ms 22784 KB Output is correct
19 Correct 55 ms 22732 KB Output is correct
20 Correct 55 ms 22616 KB Output is correct
21 Correct 54 ms 22604 KB Output is correct
22 Correct 110 ms 30812 KB Output is correct
23 Correct 15 ms 16084 KB Output is correct
24 Correct 40 ms 19712 KB Output is correct
25 Correct 8 ms 14716 KB Output is correct
26 Correct 15 ms 15956 KB Output is correct
27 Correct 12 ms 16212 KB Output is correct
28 Correct 276 ms 53144 KB Output is correct
29 Correct 437 ms 68040 KB Output is correct
30 Correct 326 ms 67788 KB Output is correct
31 Correct 328 ms 67824 KB Output is correct
32 Correct 368 ms 68636 KB Output is correct
33 Correct 325 ms 67824 KB Output is correct
34 Correct 323 ms 67824 KB Output is correct
35 Correct 120 ms 36228 KB Output is correct
36 Correct 350 ms 69580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 58196 KB Output is correct
2 Correct 119 ms 58184 KB Output is correct
3 Correct 141 ms 56468 KB Output is correct
4 Correct 142 ms 59588 KB Output is correct
5 Correct 194 ms 65240 KB Output is correct
6 Correct 189 ms 65228 KB Output is correct
7 Correct 183 ms 65220 KB Output is correct
8 Correct 188 ms 65240 KB Output is correct
9 Correct 223 ms 77768 KB Output is correct
10 Correct 135 ms 48076 KB Output is correct
11 Correct 270 ms 81888 KB Output is correct
12 Correct 7 ms 14292 KB Output is correct
13 Correct 7 ms 14292 KB Output is correct
14 Correct 6 ms 14292 KB Output is correct
15 Correct 7 ms 14388 KB Output is correct
16 Correct 7 ms 14356 KB Output is correct
17 Correct 7 ms 14292 KB Output is correct
18 Correct 125 ms 58124 KB Output is correct
19 Correct 125 ms 58184 KB Output is correct
20 Correct 116 ms 58156 KB Output is correct
21 Correct 121 ms 58128 KB Output is correct
22 Correct 220 ms 75028 KB Output is correct
23 Correct 347 ms 93620 KB Output is correct
24 Correct 329 ms 94572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 67416 KB Output is correct
2 Correct 272 ms 75024 KB Output is correct
3 Correct 140 ms 58136 KB Output is correct
4 Correct 120 ms 58200 KB Output is correct
5 Correct 750 ms 108836 KB Output is correct
6 Correct 493 ms 110940 KB Output is correct
7 Correct 8 ms 14360 KB Output is correct
8 Correct 434 ms 81332 KB Output is correct
9 Correct 542 ms 91836 KB Output is correct
10 Correct 257 ms 67412 KB Output is correct
11 Correct 293 ms 75008 KB Output is correct
12 Correct 7 ms 14292 KB Output is correct
13 Correct 12 ms 14296 KB Output is correct
14 Correct 9 ms 14292 KB Output is correct
15 Correct 7 ms 14292 KB Output is correct
16 Correct 122 ms 58188 KB Output is correct
17 Correct 120 ms 58100 KB Output is correct
18 Correct 275 ms 67576 KB Output is correct
19 Correct 315 ms 75004 KB Output is correct
20 Correct 232 ms 67384 KB Output is correct
21 Correct 272 ms 73488 KB Output is correct
22 Correct 237 ms 67476 KB Output is correct
23 Correct 271 ms 73268 KB Output is correct
24 Correct 118 ms 58196 KB Output is correct
25 Correct 119 ms 58184 KB Output is correct
26 Correct 141 ms 56468 KB Output is correct
27 Correct 142 ms 59588 KB Output is correct
28 Correct 194 ms 65240 KB Output is correct
29 Correct 189 ms 65228 KB Output is correct
30 Correct 183 ms 65220 KB Output is correct
31 Correct 188 ms 65240 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 7 ms 14292 KB Output is correct
34 Correct 8 ms 14292 KB Output is correct
35 Correct 7 ms 14292 KB Output is correct
36 Correct 8 ms 14292 KB Output is correct
37 Correct 7 ms 14292 KB Output is correct
38 Correct 7 ms 14292 KB Output is correct
39 Correct 7 ms 14292 KB Output is correct
40 Correct 8 ms 14420 KB Output is correct
41 Correct 9 ms 14804 KB Output is correct
42 Correct 8 ms 14548 KB Output is correct
43 Correct 8 ms 14676 KB Output is correct
44 Correct 8 ms 14420 KB Output is correct
45 Correct 8 ms 14612 KB Output is correct
46 Correct 7 ms 14548 KB Output is correct
47 Correct 9 ms 14676 KB Output is correct
48 Correct 58 ms 22160 KB Output is correct
49 Correct 61 ms 22784 KB Output is correct
50 Correct 55 ms 22732 KB Output is correct
51 Correct 55 ms 22616 KB Output is correct
52 Correct 54 ms 22604 KB Output is correct
53 Correct 110 ms 30812 KB Output is correct
54 Correct 15 ms 16084 KB Output is correct
55 Correct 40 ms 19712 KB Output is correct
56 Correct 8 ms 14716 KB Output is correct
57 Correct 15 ms 15956 KB Output is correct
58 Correct 12 ms 16212 KB Output is correct
59 Correct 276 ms 53144 KB Output is correct
60 Correct 437 ms 68040 KB Output is correct
61 Correct 326 ms 67788 KB Output is correct
62 Correct 328 ms 67824 KB Output is correct
63 Correct 368 ms 68636 KB Output is correct
64 Correct 325 ms 67824 KB Output is correct
65 Correct 323 ms 67824 KB Output is correct
66 Correct 120 ms 36228 KB Output is correct
67 Correct 350 ms 69580 KB Output is correct
68 Correct 223 ms 77768 KB Output is correct
69 Correct 135 ms 48076 KB Output is correct
70 Correct 270 ms 81888 KB Output is correct
71 Correct 7 ms 14292 KB Output is correct
72 Correct 7 ms 14292 KB Output is correct
73 Correct 6 ms 14292 KB Output is correct
74 Correct 7 ms 14388 KB Output is correct
75 Correct 7 ms 14356 KB Output is correct
76 Correct 7 ms 14292 KB Output is correct
77 Correct 125 ms 58124 KB Output is correct
78 Correct 125 ms 58184 KB Output is correct
79 Correct 116 ms 58156 KB Output is correct
80 Correct 121 ms 58128 KB Output is correct
81 Correct 220 ms 75028 KB Output is correct
82 Correct 347 ms 93620 KB Output is correct
83 Correct 329 ms 94572 KB Output is correct
84 Correct 630 ms 104936 KB Output is correct
85 Correct 677 ms 109128 KB Output is correct
86 Correct 431 ms 106464 KB Output is correct
87 Correct 443 ms 111232 KB Output is correct
88 Correct 7 ms 14292 KB Output is correct
89 Correct 452 ms 111248 KB Output is correct
90 Correct 425 ms 108848 KB Output is correct
91 Correct 389 ms 108528 KB Output is correct