답안 #885583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885583 2023-12-10T08:43:10 Z willychan Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
81 ms 196988 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds

const int N =5005;
int H[N];
int C[N];
ll sz[N];
vector<int> side[N];
ll dp[N][N];

bool vis[N];
ll getsize(int cur){
	sz[cur]	=C[cur];
	for(auto i : side[cur]){
		sz[cur]+=getsize(i);
	}
	return sz[cur];
}
int n;
void get(int cur){
	vis[cur]=1;
	dp[cur][n+1]=1e18;
	for(auto i : side[cur]){
		get(i);
		for(int k=1;k<=n;k++){
			dp[cur][k]+=dp[i][k];
		}
	}
	dp[cur][H[cur]]-=C[cur];
	for(int k=n;k>=1;k--){
		dp[cur][k] = min(dp[cur][k+1],dp[cur][k]);
	}
	return ;
}


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;	
	vector<int> d;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a>>H[i]>>C[i];
		d.push_back(H[i]);
		if(a!=i) side[a].push_back(i);
	}
	sort(d.begin(),d.end());
	d.resize(unique(d.begin(),d.end())-d.begin());
	for(int i=1;i<=n;i++){
		H[i] = lower_bound(d.begin(),d.end(),H[i])-d.begin()+1;
	}

	ll ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		getsize(i);
		get(i);
		ans+=sz[i]+dp[i][1];
	}
	cout<<ans<<"\n";
		

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 66 ms 196480 KB Output is correct
6 Correct 66 ms 196492 KB Output is correct
7 Correct 65 ms 196564 KB Output is correct
8 Correct 67 ms 196432 KB Output is correct
9 Correct 65 ms 196536 KB Output is correct
10 Correct 66 ms 196432 KB Output is correct
11 Correct 66 ms 196436 KB Output is correct
12 Correct 67 ms 196944 KB Output is correct
13 Correct 67 ms 196948 KB Output is correct
14 Correct 65 ms 196696 KB Output is correct
15 Correct 66 ms 196692 KB Output is correct
16 Correct 59 ms 196432 KB Output is correct
17 Correct 61 ms 196576 KB Output is correct
18 Correct 65 ms 196588 KB Output is correct
19 Correct 81 ms 196688 KB Output is correct
20 Correct 62 ms 196692 KB Output is correct
21 Correct 62 ms 196688 KB Output is correct
22 Correct 59 ms 196400 KB Output is correct
23 Correct 59 ms 196436 KB Output is correct
24 Correct 62 ms 196788 KB Output is correct
25 Correct 62 ms 196692 KB Output is correct
26 Correct 67 ms 196988 KB Output is correct
27 Correct 65 ms 196688 KB Output is correct
28 Correct 65 ms 196708 KB Output is correct
29 Correct 69 ms 196944 KB Output is correct
30 Correct 66 ms 196692 KB Output is correct
31 Correct 66 ms 196692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 66 ms 196480 KB Output is correct
6 Correct 66 ms 196492 KB Output is correct
7 Correct 65 ms 196564 KB Output is correct
8 Correct 67 ms 196432 KB Output is correct
9 Correct 65 ms 196536 KB Output is correct
10 Correct 66 ms 196432 KB Output is correct
11 Correct 66 ms 196436 KB Output is correct
12 Correct 67 ms 196944 KB Output is correct
13 Correct 67 ms 196948 KB Output is correct
14 Correct 65 ms 196696 KB Output is correct
15 Correct 66 ms 196692 KB Output is correct
16 Correct 59 ms 196432 KB Output is correct
17 Correct 61 ms 196576 KB Output is correct
18 Correct 65 ms 196588 KB Output is correct
19 Correct 81 ms 196688 KB Output is correct
20 Correct 62 ms 196692 KB Output is correct
21 Correct 62 ms 196688 KB Output is correct
22 Correct 59 ms 196400 KB Output is correct
23 Correct 59 ms 196436 KB Output is correct
24 Correct 62 ms 196788 KB Output is correct
25 Correct 62 ms 196692 KB Output is correct
26 Correct 67 ms 196988 KB Output is correct
27 Correct 65 ms 196688 KB Output is correct
28 Correct 65 ms 196708 KB Output is correct
29 Correct 69 ms 196944 KB Output is correct
30 Correct 66 ms 196692 KB Output is correct
31 Correct 66 ms 196692 KB Output is correct
32 Correct 66 ms 196680 KB Output is correct
33 Runtime error 6 ms 1116 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 66 ms 196480 KB Output is correct
6 Correct 66 ms 196492 KB Output is correct
7 Correct 65 ms 196564 KB Output is correct
8 Correct 67 ms 196432 KB Output is correct
9 Correct 65 ms 196536 KB Output is correct
10 Correct 66 ms 196432 KB Output is correct
11 Correct 66 ms 196436 KB Output is correct
12 Correct 67 ms 196944 KB Output is correct
13 Correct 67 ms 196948 KB Output is correct
14 Correct 65 ms 196696 KB Output is correct
15 Correct 66 ms 196692 KB Output is correct
16 Correct 59 ms 196432 KB Output is correct
17 Correct 61 ms 196576 KB Output is correct
18 Correct 65 ms 196588 KB Output is correct
19 Correct 81 ms 196688 KB Output is correct
20 Correct 62 ms 196692 KB Output is correct
21 Correct 62 ms 196688 KB Output is correct
22 Correct 59 ms 196400 KB Output is correct
23 Correct 59 ms 196436 KB Output is correct
24 Correct 62 ms 196788 KB Output is correct
25 Correct 62 ms 196692 KB Output is correct
26 Correct 67 ms 196988 KB Output is correct
27 Correct 65 ms 196688 KB Output is correct
28 Correct 65 ms 196708 KB Output is correct
29 Correct 69 ms 196944 KB Output is correct
30 Correct 66 ms 196692 KB Output is correct
31 Correct 66 ms 196692 KB Output is correct
32 Correct 66 ms 196680 KB Output is correct
33 Runtime error 6 ms 1116 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -