답안 #946995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946995 2024-03-15T09:49:18 Z vjudge1 Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
317 ms 82244 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
long long mainres,n,p[maxn],h[maxn],c[maxn];
vector<long long>adj[maxn];
set<pair<long long,long long>>dp[maxn];


void vorod(){
	cin>>n;
	for(long long i=1;i<=n;i++){
		cin>>p[i]>>h[i]>>c[i];
		mainres+=c[i];
		if(i!=p[i]){
			adj[p[i]].push_back(i);
		}
	}
}

void merge(long long u,long long v){
	long long fu=u;
	if((long long)dp[u].size()<(long long)dp[v].size()){
		swap(u,v);
	}
	for(auto x:dp[v]){
		auto y=*dp[u].lower_bound(make_pair(x.first,-1));
		if(y.first==x.first){
			dp[u].erase(y);
			y.second+=x.second;
			dp[u].insert(y);
		}else{
			dp[u].insert(x);
		}
	}
	if(fu!=u){
		swap(dp[u],dp[fu]);
	}
}

void ins(long long u){
	long long moonde=c[u];
	while(moonde>0&&(long long)dp[u].size()>0&&(*dp[u].begin()).first<h[u]){
		auto xx=dp[u].lower_bound(make_pair(h[u],-1));
		xx--;
		auto x=*xx;
		if(x.second>=moonde){
			dp[u].erase(x);
			x.second-=moonde;
			dp[u].insert(x);
			break;
		}else{
			dp[u].erase(x);
			moonde-=x.second;
		}
	}
	if((long long)dp[u].size()==0||(*dp[u].begin()).first>h[u]){
		dp[u].insert(make_pair(h[u],c[u]));
		return ;
	}
	auto xx=dp[u].lower_bound(make_pair(h[u],-1));
	xx--;
	auto x=*xx;
	if(x.first==h[u]){
		dp[u].erase(x);
		x.second+=c[u];
		dp[u].insert(x);
	}else{
		dp[u].insert(make_pair(h[u],c[u]));
	}
}

void solved(long long u){
	for(auto x:adj[u]){
		solved(x);
		merge(u,x);
	}
//	cout<<u<<" hainjy:"<<endl;
//	for(auto x:dp[u]){
//		cout<<x.first<<" "<<x.second<<endl;;
//	}	
	ins(u);
//	cout<<u<<" injy:"<<endl;
//	for(auto x:dp[u]){
//		cout<<x.first<<" "<<x.second<<endl;;
//	}
}

void pre(){
	//felan hichy
}

void solve(){
	solved(1);
	for(auto x:dp[1]){
		mainres-=x.second;
	}
}

void khor(){
	cout<<mainres<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
	khor();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 4 ms 19092 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 8 ms 19548 KB Output is correct
8 Correct 10 ms 20312 KB Output is correct
9 Correct 7 ms 19804 KB Output is correct
10 Correct 9 ms 19548 KB Output is correct
11 Correct 7 ms 19288 KB Output is correct
12 Correct 7 ms 19292 KB Output is correct
13 Correct 8 ms 19372 KB Output is correct
14 Correct 9 ms 19292 KB Output is correct
15 Correct 9 ms 19456 KB Output is correct
16 Correct 9 ms 20572 KB Output is correct
17 Correct 8 ms 19804 KB Output is correct
18 Correct 5 ms 19364 KB Output is correct
19 Correct 8 ms 19548 KB Output is correct
20 Correct 7 ms 19620 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 8 ms 19544 KB Output is correct
24 Correct 8 ms 19548 KB Output is correct
25 Correct 7 ms 19544 KB Output is correct
26 Correct 8 ms 19804 KB Output is correct
27 Correct 7 ms 19548 KB Output is correct
28 Correct 10 ms 19748 KB Output is correct
29 Correct 7 ms 19548 KB Output is correct
30 Correct 7 ms 19804 KB Output is correct
31 Correct 8 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 4 ms 19092 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 8 ms 19548 KB Output is correct
8 Correct 10 ms 20312 KB Output is correct
9 Correct 7 ms 19804 KB Output is correct
10 Correct 9 ms 19548 KB Output is correct
11 Correct 7 ms 19288 KB Output is correct
12 Correct 7 ms 19292 KB Output is correct
13 Correct 8 ms 19372 KB Output is correct
14 Correct 9 ms 19292 KB Output is correct
15 Correct 9 ms 19456 KB Output is correct
16 Correct 9 ms 20572 KB Output is correct
17 Correct 8 ms 19804 KB Output is correct
18 Correct 5 ms 19364 KB Output is correct
19 Correct 8 ms 19548 KB Output is correct
20 Correct 7 ms 19620 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 8 ms 19544 KB Output is correct
24 Correct 8 ms 19548 KB Output is correct
25 Correct 7 ms 19544 KB Output is correct
26 Correct 8 ms 19804 KB Output is correct
27 Correct 7 ms 19548 KB Output is correct
28 Correct 10 ms 19748 KB Output is correct
29 Correct 7 ms 19548 KB Output is correct
30 Correct 7 ms 19804 KB Output is correct
31 Correct 8 ms 19804 KB Output is correct
32 Correct 9 ms 20060 KB Output is correct
33 Correct 297 ms 82244 KB Output is correct
34 Correct 237 ms 57616 KB Output is correct
35 Correct 317 ms 79184 KB Output is correct
36 Correct 246 ms 57608 KB Output is correct
37 Correct 161 ms 40600 KB Output is correct
38 Correct 127 ms 33980 KB Output is correct
39 Correct 165 ms 36188 KB Output is correct
40 Correct 176 ms 36296 KB Output is correct
41 Incorrect 150 ms 39116 KB Output isn't correct
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 4 ms 19092 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 8 ms 19548 KB Output is correct
8 Correct 10 ms 20312 KB Output is correct
9 Correct 7 ms 19804 KB Output is correct
10 Correct 9 ms 19548 KB Output is correct
11 Correct 7 ms 19288 KB Output is correct
12 Correct 7 ms 19292 KB Output is correct
13 Correct 8 ms 19372 KB Output is correct
14 Correct 9 ms 19292 KB Output is correct
15 Correct 9 ms 19456 KB Output is correct
16 Correct 9 ms 20572 KB Output is correct
17 Correct 8 ms 19804 KB Output is correct
18 Correct 5 ms 19364 KB Output is correct
19 Correct 8 ms 19548 KB Output is correct
20 Correct 7 ms 19620 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 8 ms 19544 KB Output is correct
24 Correct 8 ms 19548 KB Output is correct
25 Correct 7 ms 19544 KB Output is correct
26 Correct 8 ms 19804 KB Output is correct
27 Correct 7 ms 19548 KB Output is correct
28 Correct 10 ms 19748 KB Output is correct
29 Correct 7 ms 19548 KB Output is correct
30 Correct 7 ms 19804 KB Output is correct
31 Correct 8 ms 19804 KB Output is correct
32 Correct 9 ms 20060 KB Output is correct
33 Correct 297 ms 82244 KB Output is correct
34 Correct 237 ms 57616 KB Output is correct
35 Correct 317 ms 79184 KB Output is correct
36 Correct 246 ms 57608 KB Output is correct
37 Correct 161 ms 40600 KB Output is correct
38 Correct 127 ms 33980 KB Output is correct
39 Correct 165 ms 36188 KB Output is correct
40 Correct 176 ms 36296 KB Output is correct
41 Incorrect 150 ms 39116 KB Output isn't correct
42 Halted 0 ms 0 KB -