Submission #1207822

#TimeUsernameProblemLanguageResultExecution timeMemory
1207822Zbyszek99Fireworks (APIO16_fireworks)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<long long>
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

struct dp
{
    multiset<ll> points;
    ll init_slope = 0;
    void merge(dp other)
    {
        init_slope += other.init_slope;
        forall(it,other.points)
        {
            points.insert(it);
        }
    }
    void add_edge(ll x)
    {
        ll cur_slope = init_slope + siz(points);
        ll opt_poz = 0;
        ll prev = 0;
        while(true)
        {
            auto cur = points.end();
            cur--;
            prev = opt_poz;
            opt_poz = *cur;
            cur_slope--;
         //   cout << opt_poz << " " << cur_slope << " slope\n";
            points.erase(points.find(opt_poz));
            if(cur_slope == -1)
            {
                break;
            }
        }
        points.insert(opt_poz+x);
        points.insert(prev+x);
    }
};

vi graph[300'001];
ll edge[300'001];

dp dfs(int v)
{
    dp ans;
    if(siz(graph[v]) == 0)
    {
        ans.init_slope = -1;
        ans.points = {{edge[v]],edge[v]}};
    }
    else
    {
        bool was = 0;
        forall(it,graph[v])
        {
            dp new_dp = dfs(it);
            if(!was)
            {
                was = 1;
                ans = new_dp;
            }
            else
            {
                if(siz(new_dp.points) > siz(ans.points))
                {
                    swap(ans,new_dp);
                }
                ans.merge(new_dp);
            }
        }
        if(v != 1) ans.add_edge(edge[v]);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random();
    int n,m;
    cin >> n >> m;
    ll cur_ans = 0;
    rep2(i,2,n+m)
    {
        int p;
        cin >> p >> edge[i];
        cur_ans += edge[i];
        graph[p].pb(i);
    }
    dp ans = dfs(1);
    ll ans_ = cur_ans;
    ll cur_slope = ans.init_slope;
    ll prev_point = 0;
    forall(it,ans.points)
    {
        cur_ans += cur_slope * (it-prev_point);
        prev_point = it;
        cur_slope++;
        ans_ = min(ans_,cur_ans);
    }
    cout << ans_;
}

Compilation message (stderr)

fireworks.cpp: In function 'dp dfs(int)':
fireworks.cpp:70:31: error: expected '}' before ']' token
   70 |         ans.points = {{edge[v]],edge[v]}};
      |                       ~       ^
fireworks.cpp:70:31: error: expected '}' before ']' token
   70 |         ans.points = {{edge[v]],edge[v]}};
      |                      ~        ^
fireworks.cpp:70:31: error: expected ';' before ']' token
   70 |         ans.points = {{edge[v]],edge[v]}};
      |                               ^
      |                               ;
fireworks.cpp:70:41: warning: no return statement in function returning non-void [-Wreturn-type]
   70 |         ans.points = {{edge[v]],edge[v]}};
      |                                         ^
fireworks.cpp: At global scope:
fireworks.cpp:71:5: error: expected declaration before '}' token
   71 |     }
      |     ^
fireworks.cpp:72:5: error: expected unqualified-id before 'else'
   72 |     else
      |     ^~~~
fireworks.cpp:94:5: error: expected unqualified-id before 'return'
   94 |     return ans;
      |     ^~~~~~
fireworks.cpp:95:1: error: expected declaration before '}' token
   95 | }
      | ^