Submission #154845

# Submission time Handle Problem Language Result Execution time Memory
154845 2019-09-25T10:21:42 Z pink_bittern Job Scheduling (IOI19_job) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <complex>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")

//#pragma GCC optimize("unroll-loops")

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 2e5 + 100;

ll n, m, k;

ll P[maxn];

ll U[maxn];

ll D[maxn];

ll ans = 0;

vector <ll> V[maxn];

pll ANS[maxn];

bool BAD[maxn];

bool cmp(pll a, pll b){
    return a.first * b.second < b.first * a.second;
}

bool cmp1(ll a, ll b){
    return cmp(ANS[a], ANS[b]);
}

void dfs(ll v, ll p){
    ll q;
    vector <ll> S;
    for (q = 0; q < V[v].size(); q++){
        if (V[v][q] == p){
            continue;
        }
        S.pb(V[v][q]);
        dfs(V[v][q], v);
    }
    pll cur = mp(D[v], U[v]);
    sort(S.begin(), S.end(), cmp1);
    ll j = S.size(), t = D[v];
    for (q = 0; q < S.size(); q++){
        ll v1 = S[q];
        if (!cmp(ANS[v1], cur)){
            j = q;
            break;
        }
        else{
            cur.first += ANS[v1].first;
            cur.second += ANS[v1].second;
            BAD[v1] = 1;
        }
    }
    ans -= (cur.first - t) * (U[v]);
    for (q = 0; q < j; q++){
        ll v1 = S[q];
        t += ANS[v1].first;
        ans -= (cur.first - t) * (ANS[v1].second);
    }
    ANS[v] = cur;
//    cout << v << " CUR " << cur.first << " " << cur.second << endl;
}

ll scheduling_cost(vector <ll> p, vector <ll> u, vector <ll> d){
    n = p.size();
    ll q, w, e, a, b;
    for (q = 0; q < n; q++){
        P[q] = p[q];
        U[q] = u[q];
        D[q] = d[q];
        if (p[q] != -1){
            V[p[q]].pb(q);
            V[q].pb(p[q]);
        }
    }
    dfs(0, 0);
    vector <ll> ALL;
    for (q = 0; q < n; q++){
        ALL.pb(q);
    }
    sort(ALL.begin(), ALL.end(), cmp1);

    ll t = 0;
    for (q = 0; q < ALL.size(); q++){
        if (BAD[ALL[q]]){
            continue;
        }
        t += ANS[ALL[q]].first;
        ans += ANS[ALL[q]].second * t;
    }
    return ans;
}

Compilation message

job.cpp:8:0: warning: ignoring #pragma optimize  [-Wunknown-pragmas]
 #pragma optimize("TKACHENKO-GORYACHENKO")
 
job.cpp: In function 'void dfs(ll, ll)':
job.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < V[v].size(); q++){
                 ~~^~~~~~~~~~~~~
job.cpp:58:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < S.size(); q++){
                 ~~^~~~~~~~~~
job.cpp: In function 'll scheduling_cost(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
job.cpp:100:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < ALL.size(); q++){
                 ~~^~~~~~~~~~~~
job.cpp:82:11: warning: unused variable 'w' [-Wunused-variable]
     ll q, w, e, a, b;
           ^
job.cpp:82:14: warning: unused variable 'e' [-Wunused-variable]
     ll q, w, e, a, b;
              ^
job.cpp:82:17: warning: unused variable 'a' [-Wunused-variable]
     ll q, w, e, a, b;
                 ^
job.cpp:82:20: warning: unused variable 'b' [-Wunused-variable]
     ll q, w, e, a, b;
                    ^
/tmp/ccPmrqO8.o: In function `main':
grader.cpp:(.text.startup+0x2bf): undefined reference to `scheduling_cost(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status