제출 #475301

#제출 시각아이디문제언어결과실행 시간메모리
475301Vladth11Fireworks (APIO16_fireworks)C++14
26 / 100
5 ms7372 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; const ll NMAX = 100001; const ll VMAX = 1000001; const ll INF = (1LL << 59); const ll MOD = 998244353; const ll BLOCK = 318; const ll base = 31; const ll nr_of_bits = 21; vector <pii> v[NMAX]; int n, m; multiset <int> st[NMAX]; int slope[NMAX]; int schema[NMAX]; void shift(int node, int d) { int act = slope[node]; int last = 0; while(act > 0) { auto it = st[node].rbegin(); last = *it; st[node].erase(st[node].find(*it)); act--; } int celalalt = *st[node].rbegin(); st[node].erase(st[node].find(celalalt)); st[node].insert(last + d); st[node].insert(celalalt + d); slope[node] = 1; } void merge(multiset <int> &a, multiset <int> &b) { if(a.size() < b.size()) { swap(a, b); } for(auto x : b) { a.insert(x); } b.clear(); } void DFS(int node, int p) { if(v[node].size() == 1 && node != 1) { st[node].insert(0); st[node].insert(0); slope[node] = 1; return; } for(auto y : v[node]) { int x = y.first; int d = y.second; if(x == p) continue; DFS(x, node); shift(x, d); slope[node] += slope[x]; schema[node] += schema[x]; merge(st[node], st[x]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll sum = 0; int i; cin >> n >> m; for(i = 2; i <= n + m; i++) { int p, l; cin >> p >> l; v[i].push_back({p, l}); v[p].push_back({i, l}); sum += 1LL * l; } DFS(1, 0); int last; while(slope[1] > 0) { auto it = st[1].rbegin(); last = *it; st[1].erase(st[1].find(*it)); slope[1]--; } /// Acum cel din spate e primul cu slope 0 int panta = 0; vector <pii> v; v.push_back({0, 0}); for(auto x : st[1]){ if(x == 0){ continue; } if(v.size() == 0 || v.back().first != x){ v.push_back({x, 1}); }else{ v.back().second++; } panta++; } for(int i = 1; i < v.size(); i++){ sum -= 1LL * panta * 1LL * (v[i].first - v[i - 1].first); panta -= v[i].second; } cout << sum; return 0; }

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

fireworks.cpp: In function 'int main()':
fireworks.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i = 1; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
fireworks.cpp:88:9: warning: variable 'last' set but not used [-Wunused-but-set-variable]
   88 |     int last;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...