답안 #475301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475301 2021-09-21T19:18:22 Z Vladth11 Fireworks (APIO16_fireworks) C++14
26 / 100
5 ms 7372 KB
#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;
}

Compilation message

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;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7244 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7364 KB Output is correct
5 Correct 4 ms 7368 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 5 ms 7348 KB Output is correct
12 Correct 5 ms 7372 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7372 KB Output is correct
15 Correct 4 ms 7360 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 5 ms 7360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7244 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 4 ms 7372 KB Output is correct
12 Correct 4 ms 7372 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7364 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
16 Correct 5 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 4 ms 7372 KB Output is correct
21 Correct 5 ms 7348 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 4 ms 7372 KB Output is correct
24 Correct 4 ms 7372 KB Output is correct
25 Correct 4 ms 7360 KB Output is correct
26 Correct 4 ms 7372 KB Output is correct
27 Correct 5 ms 7372 KB Output is correct
28 Correct 4 ms 7372 KB Output is correct
29 Correct 5 ms 7360 KB Output is correct
30 Incorrect 5 ms 7372 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7244 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 4 ms 7372 KB Output is correct
12 Correct 4 ms 7372 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7364 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
16 Correct 5 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 4 ms 7372 KB Output is correct
21 Correct 5 ms 7348 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 4 ms 7372 KB Output is correct
24 Correct 4 ms 7372 KB Output is correct
25 Correct 4 ms 7360 KB Output is correct
26 Correct 4 ms 7372 KB Output is correct
27 Correct 5 ms 7372 KB Output is correct
28 Correct 4 ms 7372 KB Output is correct
29 Correct 5 ms 7360 KB Output is correct
30 Incorrect 5 ms 7372 KB Output isn't correct
31 Halted 0 ms 0 KB -