답안 #626859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626859 2022-08-11T21:53:47 Z Noam527 메기 농장 (IOI22_fish) C++17
18 / 100
131 ms 25348 KB
#include "fish.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int N = 100005;
vector<pair<int, int>> Y[N];
int c[N];
vector<ll> D[N], F[N];
ll E[N];

ll max_weights(int n, int m, vector<int> x, vector<int> y,
                      vector<int> w) {
	for (int i = 0; i < m; i++)
		Y[x[i]].emplace_back(y[i], w[i]);
	for (int i = 0; i < n; i++)
		sort(Y[i].begin(), Y[i].end()), c[i] = Y[i].size();

	// initialize column 0:
	E[0] = 0;
	F[0].resize(c[0], -(ll)1e18);
	D[0].resize(c[0]);
	if (c[0]) {
		D[0][0] = Y[0][0].second;
		for (int j = 1; j < c[0]; j++) {
			D[0][j] = D[0][j - 1] + Y[0][j].second;
		}
	}
	// begin dp:
	for (int i = 1; i < n; i++) {
		//cout << "begin " << i << '\n';
		E[i] = E[i - 1];
		for (int j = 0; j < c[i - 1]; j++)
			E[i] = max(max(E[i], D[i - 1][j]), F[i - 1][j]);
		//cout << "E[i] " << E[i] << '\n';
		if (!c[i]) continue;

		D[i].resize(c[i]);
		F[i].resize(c[i]);

		vector<ll> below(c[i]), above(c[i]);
		// compute below
		int z = 0;
		ll bestfound = -(ll)1e18;
		for (int k = 0; k < c[i]; k++) {
			while (z < c[i - 1] && Y[i - 1][z].first < Y[i][k].first) {
				bestfound = max(bestfound, D[i - 1][z]);
				z++;
			}
			below[k] = bestfound;
		}
		// compute above
		z = c[i - 1] - 1;
		bestfound = -(ll)1e18;
		for (int k = c[i] - 1; k >= 0; k--) {
			while (z >= 0 && Y[i - 1][z].first > Y[i][k].first) {
				bestfound = max(bestfound, F[i - 1][z]);
				z--;
			}
			above[k] = bestfound;
		}
		// compute D:
		ll bestF = -(ll)1e18;
		if (c[i - 1])
			bestF = *max_element(F[i - 1].begin(), F[i - 1].end());
		D[i][0] = max(max(below[0], E[i - 1]), bestF) + Y[i][0].second;
		for (int j = 1; j < c[i]; j++) {
			D[i][j] = max(below[j], D[i][j - 1]) + Y[i][j].second;
		}
		// compute F:
		F[i][c[i] - 1] = max(E[i - 1], above[c[i] - 1]) + Y[i][c[i] - 1].second;
		for (int j = c[i] - 2; j >= 0; j--) {
			F[i][j] = max(above[j], F[i][j - 1]) + Y[i][j].second;
		}
		/*
		for (int j = 0; j < c[i]; j++) {
			cout << "D[i][" << j << "] " << D[i][j] << '\n';
		}
		for (int j = 0; j < c[i]; j++) {
			cout << "F[i][" << j << "] " << F[i][j] << '\n';
		}
		*/
	}
	ll result = E[n - 1];
	for (int j = 0; j < c[n - 1]; j++) {
		result = max(result, F[n - 1][j]);
	}
	return result;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12224 KB Output is correct
2 Correct 41 ms 13256 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 5 ms 8404 KB Output is correct
5 Correct 127 ms 23900 KB Output is correct
6 Correct 131 ms 25348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 67 ms 16696 KB Output is correct
3 Correct 76 ms 18872 KB Output is correct
4 Correct 36 ms 12264 KB Output is correct
5 Correct 50 ms 13248 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 5 ms 8404 KB Output is correct
12 Correct 33 ms 12864 KB Output is correct
13 Correct 42 ms 14128 KB Output is correct
14 Correct 33 ms 12300 KB Output is correct
15 Correct 48 ms 12956 KB Output is correct
16 Correct 41 ms 12352 KB Output is correct
17 Correct 43 ms 12948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8404 KB Output is correct
2 Correct 6 ms 8404 KB Output is correct
3 Correct 30 ms 14656 KB Output is correct
4 Correct 22 ms 12688 KB Output is correct
5 Correct 55 ms 20232 KB Output is correct
6 Correct 55 ms 20132 KB Output is correct
7 Correct 54 ms 20188 KB Output is correct
8 Correct 55 ms 20180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7264 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7256 KB Output is correct
6 Correct 4 ms 7256 KB Output is correct
7 Correct 4 ms 7256 KB Output is correct
8 Correct 4 ms 7300 KB Output is correct
9 Incorrect 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165804989716'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7264 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7256 KB Output is correct
6 Correct 4 ms 7256 KB Output is correct
7 Correct 4 ms 7256 KB Output is correct
8 Correct 4 ms 7300 KB Output is correct
9 Incorrect 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165804989716'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7264 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7256 KB Output is correct
6 Correct 4 ms 7256 KB Output is correct
7 Correct 4 ms 7256 KB Output is correct
8 Correct 4 ms 7300 KB Output is correct
9 Incorrect 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165804989716'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8404 KB Output is correct
2 Correct 6 ms 8404 KB Output is correct
3 Correct 30 ms 14656 KB Output is correct
4 Correct 22 ms 12688 KB Output is correct
5 Correct 55 ms 20232 KB Output is correct
6 Correct 55 ms 20132 KB Output is correct
7 Correct 54 ms 20188 KB Output is correct
8 Correct 55 ms 20180 KB Output is correct
9 Correct 53 ms 20172 KB Output is correct
10 Incorrect 48 ms 15028 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '31379826622592'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12224 KB Output is correct
2 Correct 41 ms 13256 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 5 ms 8404 KB Output is correct
5 Correct 127 ms 23900 KB Output is correct
6 Correct 131 ms 25348 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 67 ms 16696 KB Output is correct
9 Correct 76 ms 18872 KB Output is correct
10 Correct 36 ms 12264 KB Output is correct
11 Correct 50 ms 13248 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 3 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 8404 KB Output is correct
17 Correct 5 ms 8404 KB Output is correct
18 Correct 33 ms 12864 KB Output is correct
19 Correct 42 ms 14128 KB Output is correct
20 Correct 33 ms 12300 KB Output is correct
21 Correct 48 ms 12956 KB Output is correct
22 Correct 41 ms 12352 KB Output is correct
23 Correct 43 ms 12948 KB Output is correct
24 Correct 5 ms 8404 KB Output is correct
25 Correct 6 ms 8404 KB Output is correct
26 Correct 30 ms 14656 KB Output is correct
27 Correct 22 ms 12688 KB Output is correct
28 Correct 55 ms 20232 KB Output is correct
29 Correct 55 ms 20132 KB Output is correct
30 Correct 54 ms 20188 KB Output is correct
31 Correct 55 ms 20180 KB Output is correct
32 Correct 4 ms 7252 KB Output is correct
33 Correct 3 ms 7252 KB Output is correct
34 Correct 4 ms 7264 KB Output is correct
35 Correct 4 ms 7252 KB Output is correct
36 Correct 4 ms 7256 KB Output is correct
37 Correct 4 ms 7256 KB Output is correct
38 Correct 4 ms 7256 KB Output is correct
39 Correct 4 ms 7300 KB Output is correct
40 Incorrect 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165804989716'
41 Halted 0 ms 0 KB -