제출 #470395

#제출 시각아이디문제언어결과실행 시간메모리
470395fefeFireworks (APIO16_fireworks)C++17
7 / 100
6 ms7372 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...