답안 #518949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518949 2022-01-25T09:01:56 Z Sohsoh84 Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
203 ms 197204 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 5e3 + 10;

int n, H[MAXN], C[MAXN];
ll dp[MAXN][MAXN], sum;
vector<int> adj[MAXN], vec;

void dfs(int v) {
	for (int u : adj[v]) {
		dfs(u);
		for (int i = 1; i <= n; i++) {
			dp[v][i] += dp[u][i];
		}
	}

	dp[v][H[v]] += C[v];
	for (int i = n - 1; i > 0; i--)
		dp[v][i] = max(dp[v][i], dp[v][i + 1]);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int p;
		cin >> p;
		if (i > 1) adj[p].push_back(i);
		
		cin >> H[i] >> C[i];
		vec.push_back(H[i]);
		sum += C[i];
	}

	sort(all(vec));
	for (int i = 1; i <= n; i++)
		H[i] = lower_bound(all(vec), H[i]) - vec.begin() + 1;

	dfs(1);
	cout << sum - dp[1][1] << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 202 ms 196604 KB Output is correct
6 Correct 183 ms 196804 KB Output is correct
7 Correct 184 ms 196640 KB Output is correct
8 Correct 198 ms 196668 KB Output is correct
9 Correct 191 ms 196752 KB Output is correct
10 Correct 188 ms 196692 KB Output is correct
11 Correct 196 ms 196688 KB Output is correct
12 Correct 172 ms 197204 KB Output is correct
13 Correct 168 ms 197188 KB Output is correct
14 Correct 170 ms 197008 KB Output is correct
15 Correct 181 ms 197004 KB Output is correct
16 Correct 201 ms 196648 KB Output is correct
17 Correct 186 ms 196660 KB Output is correct
18 Correct 201 ms 196824 KB Output is correct
19 Correct 184 ms 196912 KB Output is correct
20 Correct 183 ms 196908 KB Output is correct
21 Correct 195 ms 196932 KB Output is correct
22 Correct 199 ms 196700 KB Output is correct
23 Correct 203 ms 196652 KB Output is correct
24 Correct 186 ms 196908 KB Output is correct
25 Correct 189 ms 196936 KB Output is correct
26 Correct 168 ms 197188 KB Output is correct
27 Correct 196 ms 196976 KB Output is correct
28 Correct 185 ms 196976 KB Output is correct
29 Correct 174 ms 197064 KB Output is correct
30 Correct 171 ms 196972 KB Output is correct
31 Correct 177 ms 197012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 202 ms 196604 KB Output is correct
6 Correct 183 ms 196804 KB Output is correct
7 Correct 184 ms 196640 KB Output is correct
8 Correct 198 ms 196668 KB Output is correct
9 Correct 191 ms 196752 KB Output is correct
10 Correct 188 ms 196692 KB Output is correct
11 Correct 196 ms 196688 KB Output is correct
12 Correct 172 ms 197204 KB Output is correct
13 Correct 168 ms 197188 KB Output is correct
14 Correct 170 ms 197008 KB Output is correct
15 Correct 181 ms 197004 KB Output is correct
16 Correct 201 ms 196648 KB Output is correct
17 Correct 186 ms 196660 KB Output is correct
18 Correct 201 ms 196824 KB Output is correct
19 Correct 184 ms 196912 KB Output is correct
20 Correct 183 ms 196908 KB Output is correct
21 Correct 195 ms 196932 KB Output is correct
22 Correct 199 ms 196700 KB Output is correct
23 Correct 203 ms 196652 KB Output is correct
24 Correct 186 ms 196908 KB Output is correct
25 Correct 189 ms 196936 KB Output is correct
26 Correct 168 ms 197188 KB Output is correct
27 Correct 196 ms 196976 KB Output is correct
28 Correct 185 ms 196976 KB Output is correct
29 Correct 174 ms 197064 KB Output is correct
30 Correct 171 ms 196972 KB Output is correct
31 Correct 177 ms 197012 KB Output is correct
32 Correct 193 ms 196700 KB Output is correct
33 Runtime error 7 ms 1196 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 202 ms 196604 KB Output is correct
6 Correct 183 ms 196804 KB Output is correct
7 Correct 184 ms 196640 KB Output is correct
8 Correct 198 ms 196668 KB Output is correct
9 Correct 191 ms 196752 KB Output is correct
10 Correct 188 ms 196692 KB Output is correct
11 Correct 196 ms 196688 KB Output is correct
12 Correct 172 ms 197204 KB Output is correct
13 Correct 168 ms 197188 KB Output is correct
14 Correct 170 ms 197008 KB Output is correct
15 Correct 181 ms 197004 KB Output is correct
16 Correct 201 ms 196648 KB Output is correct
17 Correct 186 ms 196660 KB Output is correct
18 Correct 201 ms 196824 KB Output is correct
19 Correct 184 ms 196912 KB Output is correct
20 Correct 183 ms 196908 KB Output is correct
21 Correct 195 ms 196932 KB Output is correct
22 Correct 199 ms 196700 KB Output is correct
23 Correct 203 ms 196652 KB Output is correct
24 Correct 186 ms 196908 KB Output is correct
25 Correct 189 ms 196936 KB Output is correct
26 Correct 168 ms 197188 KB Output is correct
27 Correct 196 ms 196976 KB Output is correct
28 Correct 185 ms 196976 KB Output is correct
29 Correct 174 ms 197064 KB Output is correct
30 Correct 171 ms 196972 KB Output is correct
31 Correct 177 ms 197012 KB Output is correct
32 Correct 193 ms 196700 KB Output is correct
33 Runtime error 7 ms 1196 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -