Submission #417268

# Submission time Handle Problem Language Result Execution time Memory
417268 2021-06-03T14:07:33 Z huangqr Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
358 ms 524292 KB
#ifdef local
#define debug(x) cout<<#x<<" "<<x<<endl;
#else
#define debug(x)
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
const ll mod=1e9+7,lim=2e5+5,bitlim=15,inf=1e9;
vector<ll>adjl[lim];
ll pwr[lim],cost[lim];
map<ll,ll> *mps[lim];
 
void dp(ll pos){
	if(adjl[pos].size() == 0){
		debug(pos);
		mps[pos] = new map<ll,ll>();
		mps[pos]->operator[](0)=0;
		mps[pos]->operator[](pwr[pos] + 1) = cost[pos];
		debug("finished");
		debug(pos);
	}
	else{
		debug(pos);
		ll maxsz=0,maxszidx=0;
		for(int i=0;i<adjl[pos].size();i++){
			ll u=adjl[pos][i];
			dp(u);
			if(mps[u]->size()>maxsz){
				maxsz=mps[u]->size();
				maxszidx=u;
			}
		}
		debug(pos);
		mps[pos] = mps[maxszidx];
		for(int i=0;i<adjl[pos].size();i++){
			debug(i);
			ll u=adjl[pos][i];
			if(u==maxszidx)continue;
			debug(u);
			debug(mps[u]->size());
			for(auto p:*mps[u]){
				ll k,v;
				tie(k,v)=p;
				debug("before add");
				mps[pos]->operator[](k)+=v;
				debug("after add");
			}
		}
		debug("nxt step");
		mps[pos]->operator[](0) += cost[pos];
		mps[pos]->operator[](pwr[pos] + 1) += cost[pos];
		auto it=mps[pos]->upper_bound(pwr[pos]);
		ll rem=cost[pos];
		debug("before rem");
		while(rem>0){
			it--;
			if(rem<=it->second)it->second-=rem,rem=0;
			else rem-=it->second,it=mps[pos]->erase(it);
		}
		debug("after rem");
	}
	return;
}
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL);
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
		ll a;
		cin>>a>>pwr[i]>>cost[i];
		if(i!=a)adjl[a].push_back(i);
	}
	dp(1);
	cout<<mps[1]->begin()->second<<"\n";
	return 0;
}

Compilation message

worst_reporter2.cpp: In function 'void dp(ll)':
worst_reporter2.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i=0;i<adjl[pos].size();i++){
      |               ~^~~~~~~~~~~~~~~~~
worst_reporter2.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   30 |    if(mps[u]->size()>maxsz){
      |       ~~~~~~~~~~~~~~^~~~~~
worst_reporter2.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i=0;i<adjl[pos].size();i++){
      |               ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 10 ms 6472 KB Output is correct
6 Correct 7 ms 5964 KB Output is correct
7 Correct 7 ms 5836 KB Output is correct
8 Correct 9 ms 6476 KB Output is correct
9 Correct 7 ms 5964 KB Output is correct
10 Correct 7 ms 5836 KB Output is correct
11 Correct 7 ms 5708 KB Output is correct
12 Correct 8 ms 5988 KB Output is correct
13 Correct 7 ms 5964 KB Output is correct
14 Correct 7 ms 5580 KB Output is correct
15 Correct 7 ms 5580 KB Output is correct
16 Correct 9 ms 6860 KB Output is correct
17 Correct 8 ms 6196 KB Output is correct
18 Correct 6 ms 5580 KB Output is correct
19 Correct 8 ms 6220 KB Output is correct
20 Correct 7 ms 5964 KB Output is correct
21 Correct 6 ms 5964 KB Output is correct
22 Correct 7 ms 6348 KB Output is correct
23 Correct 6 ms 6092 KB Output is correct
24 Correct 7 ms 6220 KB Output is correct
25 Correct 7 ms 6036 KB Output is correct
26 Correct 8 ms 6220 KB Output is correct
27 Correct 9 ms 6220 KB Output is correct
28 Correct 7 ms 6204 KB Output is correct
29 Correct 8 ms 6220 KB Output is correct
30 Correct 9 ms 6092 KB Output is correct
31 Correct 8 ms 6092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 10 ms 6472 KB Output is correct
6 Correct 7 ms 5964 KB Output is correct
7 Correct 7 ms 5836 KB Output is correct
8 Correct 9 ms 6476 KB Output is correct
9 Correct 7 ms 5964 KB Output is correct
10 Correct 7 ms 5836 KB Output is correct
11 Correct 7 ms 5708 KB Output is correct
12 Correct 8 ms 5988 KB Output is correct
13 Correct 7 ms 5964 KB Output is correct
14 Correct 7 ms 5580 KB Output is correct
15 Correct 7 ms 5580 KB Output is correct
16 Correct 9 ms 6860 KB Output is correct
17 Correct 8 ms 6196 KB Output is correct
18 Correct 6 ms 5580 KB Output is correct
19 Correct 8 ms 6220 KB Output is correct
20 Correct 7 ms 5964 KB Output is correct
21 Correct 6 ms 5964 KB Output is correct
22 Correct 7 ms 6348 KB Output is correct
23 Correct 6 ms 6092 KB Output is correct
24 Correct 7 ms 6220 KB Output is correct
25 Correct 7 ms 6036 KB Output is correct
26 Correct 8 ms 6220 KB Output is correct
27 Correct 9 ms 6220 KB Output is correct
28 Correct 7 ms 6204 KB Output is correct
29 Correct 8 ms 6220 KB Output is correct
30 Correct 9 ms 6092 KB Output is correct
31 Correct 8 ms 6092 KB Output is correct
32 Correct 9 ms 6484 KB Output is correct
33 Correct 351 ms 81540 KB Output is correct
34 Correct 295 ms 57216 KB Output is correct
35 Correct 358 ms 78960 KB Output is correct
36 Correct 299 ms 57276 KB Output is correct
37 Correct 222 ms 38760 KB Output is correct
38 Correct 204 ms 34532 KB Output is correct
39 Correct 170 ms 46552 KB Output is correct
40 Correct 152 ms 49200 KB Output is correct
41 Correct 114 ms 49200 KB Output is correct
42 Correct 156 ms 35280 KB Output is correct
43 Correct 166 ms 35148 KB Output is correct
44 Correct 319 ms 109804 KB Output is correct
45 Correct 227 ms 74208 KB Output is correct
46 Correct 117 ms 36608 KB Output is correct
47 Correct 288 ms 57644 KB Output is correct
48 Correct 150 ms 50740 KB Output is correct
49 Correct 134 ms 50676 KB Output is correct
50 Correct 241 ms 65612 KB Output is correct
51 Correct 142 ms 53060 KB Output is correct
52 Correct 262 ms 58776 KB Output is correct
53 Correct 139 ms 51664 KB Output is correct
54 Correct 196 ms 61900 KB Output is correct
55 Correct 241 ms 59944 KB Output is correct
56 Correct 199 ms 59088 KB Output is correct
57 Correct 178 ms 59444 KB Output is correct
58 Correct 218 ms 53188 KB Output is correct
59 Correct 194 ms 53252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 10 ms 6472 KB Output is correct
6 Correct 7 ms 5964 KB Output is correct
7 Correct 7 ms 5836 KB Output is correct
8 Correct 9 ms 6476 KB Output is correct
9 Correct 7 ms 5964 KB Output is correct
10 Correct 7 ms 5836 KB Output is correct
11 Correct 7 ms 5708 KB Output is correct
12 Correct 8 ms 5988 KB Output is correct
13 Correct 7 ms 5964 KB Output is correct
14 Correct 7 ms 5580 KB Output is correct
15 Correct 7 ms 5580 KB Output is correct
16 Correct 9 ms 6860 KB Output is correct
17 Correct 8 ms 6196 KB Output is correct
18 Correct 6 ms 5580 KB Output is correct
19 Correct 8 ms 6220 KB Output is correct
20 Correct 7 ms 5964 KB Output is correct
21 Correct 6 ms 5964 KB Output is correct
22 Correct 7 ms 6348 KB Output is correct
23 Correct 6 ms 6092 KB Output is correct
24 Correct 7 ms 6220 KB Output is correct
25 Correct 7 ms 6036 KB Output is correct
26 Correct 8 ms 6220 KB Output is correct
27 Correct 9 ms 6220 KB Output is correct
28 Correct 7 ms 6204 KB Output is correct
29 Correct 8 ms 6220 KB Output is correct
30 Correct 9 ms 6092 KB Output is correct
31 Correct 8 ms 6092 KB Output is correct
32 Correct 9 ms 6484 KB Output is correct
33 Correct 351 ms 81540 KB Output is correct
34 Correct 295 ms 57216 KB Output is correct
35 Correct 358 ms 78960 KB Output is correct
36 Correct 299 ms 57276 KB Output is correct
37 Correct 222 ms 38760 KB Output is correct
38 Correct 204 ms 34532 KB Output is correct
39 Correct 170 ms 46552 KB Output is correct
40 Correct 152 ms 49200 KB Output is correct
41 Correct 114 ms 49200 KB Output is correct
42 Correct 156 ms 35280 KB Output is correct
43 Correct 166 ms 35148 KB Output is correct
44 Correct 319 ms 109804 KB Output is correct
45 Correct 227 ms 74208 KB Output is correct
46 Correct 117 ms 36608 KB Output is correct
47 Correct 288 ms 57644 KB Output is correct
48 Correct 150 ms 50740 KB Output is correct
49 Correct 134 ms 50676 KB Output is correct
50 Correct 241 ms 65612 KB Output is correct
51 Correct 142 ms 53060 KB Output is correct
52 Correct 262 ms 58776 KB Output is correct
53 Correct 139 ms 51664 KB Output is correct
54 Correct 196 ms 61900 KB Output is correct
55 Correct 241 ms 59944 KB Output is correct
56 Correct 199 ms 59088 KB Output is correct
57 Correct 178 ms 59444 KB Output is correct
58 Correct 218 ms 53188 KB Output is correct
59 Correct 194 ms 53252 KB Output is correct
60 Runtime error 249 ms 524292 KB Execution killed with signal 9
61 Halted 0 ms 0 KB -