Submission #470395

# Submission time Handle Problem Language Result Execution time Memory
470395 2021-09-03T16:20:17 Z fefe Fireworks (APIO16_fireworks) C++17
7 / 100
6 ms 7372 KB
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pil;

const int MAXN = 300005;
int n, m;
int par[MAXN];
LL val[MAXN];
pil mid[MAXN];
vector<LL> lst[MAXN];
void udt(int i) {
	lst[par[i]].pb(mid[i].fi + val[i]);
	lst[par[i]].pb(mid[i].se + val[i]);
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 2; i <= n + m; i++) {
		int p;
		LL v;
		scanf("%d %lld", &p, &v);
		par[i] = p;
		val[i] = v;
	}

	for (int i = n + m; i > n; i--) {
		mid[i] = pil(0, 0);
		udt(i);
	}

	for (int i = n; i >= 1; i--) {
		sort(all(lst[i]));
		mid[i].fi = lst[i][lst[i].size() / 2 - 1];
		mid[i].se = lst[i][lst[i].size() / 2];
		udt(i);
	}
	val[1] = mid[1].se;
	LL res = 0;
	for (int i = 2; i <= n + m; i++) {
		LL v = val[par[i]] - val[i];
		if (mid[i].fi > v) {
			val[i] = mid[i].fi;
			res += mid[i].fi - v;
		}
		else if (mid[i].se < v) {
			val[i] = mid[i].se;
			res += v - mid[i].se;
		}
		else {
			val[i] = v;
		}
	}
	printf("%lld\n", res);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
fireworks.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d %lld", &p, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7368 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 5 ms 7272 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7348 KB Output is correct
3 Incorrect 4 ms 7348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7368 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 5 ms 7272 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7348 KB Output is correct
13 Incorrect 4 ms 7348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7368 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 5 ms 7272 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7348 KB Output is correct
13 Incorrect 4 ms 7348 KB Output isn't correct
14 Halted 0 ms 0 KB -