답안 #799032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799032 2023-07-31T08:51:17 Z MadokaMagicaFan 메기 농장 (IOI22_fish) C++17
100 / 100
222 ms 25424 KB
#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define sz(v)	((int) v.size())

const int N = 1e5;

int dp1[N+5], dp2[N+5];

struct aint {
	int n;
	vector<ll> f;

	aint (int _n) {
		n = _n;
		f.assign(n<<1, 0);
	}

	ll query(int l, int r) {
		l += n; r += n+1;
		ll res = 0;
		for (;l < r; l>>=1, r>>=1) {
			if (l&1) res = max(res, f[l++]);
			if (r&1) res = max(res, f[--r]);
		}
		return res;
	}

	void upd(int x, ll v) {
		x += n;
		for (f[x] = max(f[x], v); x > 1; x>>=1) {
			f[x>>1] = max(f[x], f[x^1]);
		}
	}
};
ll mv1[N+5], mv2[N+5];

ll
max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
	vector<array<int, 3>> u(m), d(m);

	for (int i = 0; i < m; ++i) {
		u[i] = {x[i], y[i], i};
		d[i] = {x[i], -y[i], i};
	}

	sort(u.begin(), u.end());
	sort(d.begin(), d.end());
	reverse(u.begin(), u.end());
	reverse(d.begin(), d.end());

	int up, dp;
	up = dp = 0;
	aint t1(n+5), t2(n+5);
	ll t, v, i;

	for (int x = n-1; x >= 0; --x) {
		while (up < sz(u) && u[up][0] == x) {
			if (x < n-1) {
				i = u[up][2];
				v = w[i];
				t = t1.query(y[i]+1, n+2);
				t = max({t, mv2[x+2], mv1[x+3]});
				t1.upd(y[i], t+v);
			}
			++up;
		}

		while (dp < sz(d) && d[dp][0] == x) {
			if (x > 0) {
				i = d[dp][2];
				v = w[i]; t = 0;
				if (y[i])
					t = t2.query(0, y[i]-1);

				t = max({t, mv1[x+1], mv2[x+2]}) + v;
				t2.upd(y[i], t);
			}
			++dp;
		}

		mv1[x] = mv1[x+1];
		mv2[x] = mv2[x+1];

		mv1[x] =t1.query(0, n+1);
		mv2[x] =t2.query(0, n+1);
	}

	return max(t1.query(0, n+1), t2.query(0, n+1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8280 KB Output is correct
2 Correct 61 ms 11312 KB Output is correct
3 Correct 6 ms 4948 KB Output is correct
4 Correct 9 ms 4916 KB Output is correct
5 Correct 204 ms 21368 KB Output is correct
6 Correct 221 ms 21300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 127 ms 14472 KB Output is correct
3 Correct 157 ms 16600 KB Output is correct
4 Correct 69 ms 9692 KB Output is correct
5 Correct 60 ms 11440 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 8 ms 4948 KB Output is correct
11 Correct 6 ms 4920 KB Output is correct
12 Correct 57 ms 9700 KB Output is correct
13 Correct 88 ms 11436 KB Output is correct
14 Correct 52 ms 9708 KB Output is correct
15 Correct 59 ms 10748 KB Output is correct
16 Correct 56 ms 9760 KB Output is correct
17 Correct 59 ms 10704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4948 KB Output is correct
2 Correct 6 ms 4948 KB Output is correct
3 Correct 30 ms 7872 KB Output is correct
4 Correct 27 ms 7252 KB Output is correct
5 Correct 64 ms 11328 KB Output is correct
6 Correct 52 ms 10576 KB Output is correct
7 Correct 57 ms 11160 KB Output is correct
8 Correct 52 ms 11248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 25 ms 3228 KB Output is correct
18 Correct 23 ms 3184 KB Output is correct
19 Correct 22 ms 3188 KB Output is correct
20 Correct 22 ms 3172 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 46 ms 5928 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 16 ms 2236 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 25 ms 3228 KB Output is correct
18 Correct 23 ms 3184 KB Output is correct
19 Correct 22 ms 3188 KB Output is correct
20 Correct 22 ms 3172 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 46 ms 5928 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 16 ms 2236 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 828 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 146 ms 14184 KB Output is correct
29 Correct 222 ms 20108 KB Output is correct
30 Correct 180 ms 20068 KB Output is correct
31 Correct 181 ms 20060 KB Output is correct
32 Correct 167 ms 19512 KB Output is correct
33 Correct 197 ms 20116 KB Output is correct
34 Correct 183 ms 20112 KB Output is correct
35 Correct 77 ms 7944 KB Output is correct
36 Correct 206 ms 20088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4948 KB Output is correct
2 Correct 6 ms 4948 KB Output is correct
3 Correct 30 ms 7872 KB Output is correct
4 Correct 27 ms 7252 KB Output is correct
5 Correct 64 ms 11328 KB Output is correct
6 Correct 52 ms 10576 KB Output is correct
7 Correct 57 ms 11160 KB Output is correct
8 Correct 52 ms 11248 KB Output is correct
9 Correct 63 ms 10952 KB Output is correct
10 Correct 51 ms 9044 KB Output is correct
11 Correct 104 ms 17836 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 284 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 6 ms 4912 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 9 ms 4980 KB Output is correct
21 Correct 6 ms 4936 KB Output is correct
22 Correct 73 ms 11752 KB Output is correct
23 Correct 106 ms 17864 KB Output is correct
24 Correct 123 ms 18416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8280 KB Output is correct
2 Correct 61 ms 11312 KB Output is correct
3 Correct 6 ms 4948 KB Output is correct
4 Correct 9 ms 4916 KB Output is correct
5 Correct 204 ms 21368 KB Output is correct
6 Correct 221 ms 21300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 127 ms 14472 KB Output is correct
9 Correct 157 ms 16600 KB Output is correct
10 Correct 69 ms 9692 KB Output is correct
11 Correct 60 ms 11440 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 8 ms 4948 KB Output is correct
17 Correct 6 ms 4920 KB Output is correct
18 Correct 57 ms 9700 KB Output is correct
19 Correct 88 ms 11436 KB Output is correct
20 Correct 52 ms 9708 KB Output is correct
21 Correct 59 ms 10748 KB Output is correct
22 Correct 56 ms 9760 KB Output is correct
23 Correct 59 ms 10704 KB Output is correct
24 Correct 6 ms 4948 KB Output is correct
25 Correct 6 ms 4948 KB Output is correct
26 Correct 30 ms 7872 KB Output is correct
27 Correct 27 ms 7252 KB Output is correct
28 Correct 64 ms 11328 KB Output is correct
29 Correct 52 ms 10576 KB Output is correct
30 Correct 57 ms 11160 KB Output is correct
31 Correct 52 ms 11248 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 308 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 308 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 452 KB Output is correct
42 Correct 1 ms 312 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 320 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 25 ms 3228 KB Output is correct
49 Correct 23 ms 3184 KB Output is correct
50 Correct 22 ms 3188 KB Output is correct
51 Correct 22 ms 3172 KB Output is correct
52 Correct 22 ms 3164 KB Output is correct
53 Correct 46 ms 5928 KB Output is correct
54 Correct 5 ms 852 KB Output is correct
55 Correct 16 ms 2236 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 5 ms 828 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 146 ms 14184 KB Output is correct
60 Correct 222 ms 20108 KB Output is correct
61 Correct 180 ms 20068 KB Output is correct
62 Correct 181 ms 20060 KB Output is correct
63 Correct 167 ms 19512 KB Output is correct
64 Correct 197 ms 20116 KB Output is correct
65 Correct 183 ms 20112 KB Output is correct
66 Correct 77 ms 7944 KB Output is correct
67 Correct 206 ms 20088 KB Output is correct
68 Correct 63 ms 10952 KB Output is correct
69 Correct 51 ms 9044 KB Output is correct
70 Correct 104 ms 17836 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 284 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 6 ms 4912 KB Output is correct
78 Correct 6 ms 4948 KB Output is correct
79 Correct 9 ms 4980 KB Output is correct
80 Correct 6 ms 4936 KB Output is correct
81 Correct 73 ms 11752 KB Output is correct
82 Correct 106 ms 17864 KB Output is correct
83 Correct 123 ms 18416 KB Output is correct
84 Correct 207 ms 24400 KB Output is correct
85 Correct 205 ms 24488 KB Output is correct
86 Correct 216 ms 24708 KB Output is correct
87 Correct 213 ms 25408 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 209 ms 25424 KB Output is correct
90 Correct 174 ms 24336 KB Output is correct
91 Correct 166 ms 24268 KB Output is correct