답안 #476942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476942 2021-09-29T08:56:46 Z keta_tsimakuridze Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
563 ms 66908 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t,a[N],c[N],n;
multiset<pii> s[N];
vector <int> V[N]; 
void dfs(int u) {
	for(int i = 0; i < V[u].size(); i++) {
		dfs(V[u][i]);
		int x = V[u][i];
		if(s[u].size() < s[x].size()) swap(s[u],s[x]);
		while(s[x].size()) {
			pii y = *s[x].begin();
			s[x].erase(s[x].find(y));
			s[u].insert(y);
		}
	}
	//
	int saved = c[u];
	while(s[u].upper_bound({a[u],-1}) != s[u].begin()){
		pii x = *--s[u].upper_bound({a[u] ,-1});
		s[u].erase(s[u].find(x));
		if(x.s <= c[u]) {
			c[u] -= x.s;
		}
		else {
			s[u].insert({x.f,x.s - c[u]});
			break;
		}
	}
	s[u].insert({a[u], saved});
}
main(){
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		int p;
		cin >> p >> a[i] >> c[i];
		sum += c[i];
		if(i == 1) {
			if(p != 1) return 0;
			continue;
		}
		if(p >= i) return 0;
		V[p].push_back(i);
		
	}
	dfs(1);
	int ans = 0; 
	for(multiset <pii> :: iterator it = s[1].begin(); it != s[1].end(); it++) {
		ans += (*it).s;	
	}
	cout << sum - ans;
 }

Compilation message

worst_reporter2.cpp: In function 'void dfs(long long int)':
worst_reporter2.cpp:12:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
worst_reporter2.cpp: At global scope:
worst_reporter2.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14284 KB Output is correct
2 Correct 7 ms 14284 KB Output is correct
3 Correct 7 ms 14396 KB Output is correct
4 Correct 7 ms 14284 KB Output is correct
5 Correct 16 ms 14700 KB Output is correct
6 Correct 17 ms 14800 KB Output is correct
7 Correct 16 ms 14924 KB Output is correct
8 Correct 17 ms 14904 KB Output is correct
9 Correct 16 ms 14924 KB Output is correct
10 Correct 16 ms 14880 KB Output is correct
11 Correct 16 ms 14940 KB Output is correct
12 Correct 16 ms 15604 KB Output is correct
13 Correct 21 ms 15592 KB Output is correct
14 Correct 16 ms 15180 KB Output is correct
15 Correct 17 ms 15184 KB Output is correct
16 Correct 17 ms 14784 KB Output is correct
17 Correct 17 ms 14796 KB Output is correct
18 Correct 18 ms 14920 KB Output is correct
19 Correct 17 ms 15168 KB Output is correct
20 Correct 17 ms 15280 KB Output is correct
21 Correct 15 ms 15308 KB Output is correct
22 Correct 13 ms 14940 KB Output is correct
23 Correct 14 ms 14880 KB Output is correct
24 Correct 17 ms 15300 KB Output is correct
25 Correct 16 ms 15308 KB Output is correct
26 Correct 15 ms 15564 KB Output is correct
27 Correct 14 ms 15180 KB Output is correct
28 Correct 15 ms 15408 KB Output is correct
29 Correct 15 ms 15544 KB Output is correct
30 Correct 17 ms 15468 KB Output is correct
31 Correct 21 ms 15436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14284 KB Output is correct
2 Correct 7 ms 14284 KB Output is correct
3 Correct 7 ms 14396 KB Output is correct
4 Correct 7 ms 14284 KB Output is correct
5 Correct 16 ms 14700 KB Output is correct
6 Correct 17 ms 14800 KB Output is correct
7 Correct 16 ms 14924 KB Output is correct
8 Correct 17 ms 14904 KB Output is correct
9 Correct 16 ms 14924 KB Output is correct
10 Correct 16 ms 14880 KB Output is correct
11 Correct 16 ms 14940 KB Output is correct
12 Correct 16 ms 15604 KB Output is correct
13 Correct 21 ms 15592 KB Output is correct
14 Correct 16 ms 15180 KB Output is correct
15 Correct 17 ms 15184 KB Output is correct
16 Correct 17 ms 14784 KB Output is correct
17 Correct 17 ms 14796 KB Output is correct
18 Correct 18 ms 14920 KB Output is correct
19 Correct 17 ms 15168 KB Output is correct
20 Correct 17 ms 15280 KB Output is correct
21 Correct 15 ms 15308 KB Output is correct
22 Correct 13 ms 14940 KB Output is correct
23 Correct 14 ms 14880 KB Output is correct
24 Correct 17 ms 15300 KB Output is correct
25 Correct 16 ms 15308 KB Output is correct
26 Correct 15 ms 15564 KB Output is correct
27 Correct 14 ms 15180 KB Output is correct
28 Correct 15 ms 15408 KB Output is correct
29 Correct 15 ms 15544 KB Output is correct
30 Correct 17 ms 15468 KB Output is correct
31 Correct 21 ms 15436 KB Output is correct
32 Correct 21 ms 14908 KB Output is correct
33 Correct 520 ms 35892 KB Output is correct
34 Correct 554 ms 35928 KB Output is correct
35 Correct 510 ms 35968 KB Output is correct
36 Correct 527 ms 35988 KB Output is correct
37 Correct 513 ms 36972 KB Output is correct
38 Correct 521 ms 38596 KB Output is correct
39 Correct 413 ms 63504 KB Output is correct
40 Correct 447 ms 63548 KB Output is correct
41 Correct 406 ms 66348 KB Output is correct
42 Correct 417 ms 46408 KB Output is correct
43 Correct 448 ms 46184 KB Output is correct
44 Correct 497 ms 34892 KB Output is correct
45 Correct 495 ms 34832 KB Output is correct
46 Correct 563 ms 38092 KB Output is correct
47 Correct 494 ms 49860 KB Output is correct
48 Correct 526 ms 53564 KB Output is correct
49 Correct 422 ms 54140 KB Output is correct
50 Correct 415 ms 35944 KB Output is correct
51 Correct 390 ms 35732 KB Output is correct
52 Correct 563 ms 50924 KB Output is correct
53 Correct 500 ms 54808 KB Output is correct
54 Correct 289 ms 63456 KB Output is correct
55 Correct 376 ms 52140 KB Output is correct
56 Correct 350 ms 62100 KB Output is correct
57 Correct 347 ms 66908 KB Output is correct
58 Correct 409 ms 57884 KB Output is correct
59 Correct 392 ms 57924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14284 KB Output is correct
2 Correct 7 ms 14284 KB Output is correct
3 Correct 7 ms 14396 KB Output is correct
4 Correct 7 ms 14284 KB Output is correct
5 Correct 16 ms 14700 KB Output is correct
6 Correct 17 ms 14800 KB Output is correct
7 Correct 16 ms 14924 KB Output is correct
8 Correct 17 ms 14904 KB Output is correct
9 Correct 16 ms 14924 KB Output is correct
10 Correct 16 ms 14880 KB Output is correct
11 Correct 16 ms 14940 KB Output is correct
12 Correct 16 ms 15604 KB Output is correct
13 Correct 21 ms 15592 KB Output is correct
14 Correct 16 ms 15180 KB Output is correct
15 Correct 17 ms 15184 KB Output is correct
16 Correct 17 ms 14784 KB Output is correct
17 Correct 17 ms 14796 KB Output is correct
18 Correct 18 ms 14920 KB Output is correct
19 Correct 17 ms 15168 KB Output is correct
20 Correct 17 ms 15280 KB Output is correct
21 Correct 15 ms 15308 KB Output is correct
22 Correct 13 ms 14940 KB Output is correct
23 Correct 14 ms 14880 KB Output is correct
24 Correct 17 ms 15300 KB Output is correct
25 Correct 16 ms 15308 KB Output is correct
26 Correct 15 ms 15564 KB Output is correct
27 Correct 14 ms 15180 KB Output is correct
28 Correct 15 ms 15408 KB Output is correct
29 Correct 15 ms 15544 KB Output is correct
30 Correct 17 ms 15468 KB Output is correct
31 Correct 21 ms 15436 KB Output is correct
32 Correct 21 ms 14908 KB Output is correct
33 Correct 520 ms 35892 KB Output is correct
34 Correct 554 ms 35928 KB Output is correct
35 Correct 510 ms 35968 KB Output is correct
36 Correct 527 ms 35988 KB Output is correct
37 Correct 513 ms 36972 KB Output is correct
38 Correct 521 ms 38596 KB Output is correct
39 Correct 413 ms 63504 KB Output is correct
40 Correct 447 ms 63548 KB Output is correct
41 Correct 406 ms 66348 KB Output is correct
42 Correct 417 ms 46408 KB Output is correct
43 Correct 448 ms 46184 KB Output is correct
44 Correct 497 ms 34892 KB Output is correct
45 Correct 495 ms 34832 KB Output is correct
46 Correct 563 ms 38092 KB Output is correct
47 Correct 494 ms 49860 KB Output is correct
48 Correct 526 ms 53564 KB Output is correct
49 Correct 422 ms 54140 KB Output is correct
50 Correct 415 ms 35944 KB Output is correct
51 Correct 390 ms 35732 KB Output is correct
52 Correct 563 ms 50924 KB Output is correct
53 Correct 500 ms 54808 KB Output is correct
54 Correct 289 ms 63456 KB Output is correct
55 Correct 376 ms 52140 KB Output is correct
56 Correct 350 ms 62100 KB Output is correct
57 Correct 347 ms 66908 KB Output is correct
58 Correct 409 ms 57884 KB Output is correct
59 Correct 392 ms 57924 KB Output is correct
60 Incorrect 8 ms 14304 KB Output isn't correct
61 Halted 0 ms 0 KB -