Submission #154862

# Submission time Handle Problem Language Result Execution time Memory
154862 2019-09-25T12:02:15 Z pink_bittern Job Scheduling (IOI19_job) C++14
24 / 100
206 ms 41208 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 <int> p, vector <int> u, vector <int> d){
    n = p.size();
    bool is_bamboo = 1;
    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] != q - 1){
            is_bamboo = 0;
        }
        if (p[q] != -1){
            V[p[q]].pb(q);
            V[q].pb(p[q]);
        }
    }
    if (is_bamboo){
        ll t = 0;
        for (q = 0; q < n; q++){
            t += d[q];
            ans += t * u[q];
        }
        return ans;
    }
    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<int>, std::vector<int>, std::vector<int>)':
job.cpp:111:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < ALL.size(); q++){
                 ~~^~~~~~~~~~~~
job.cpp:83:11: warning: unused variable 'w' [-Wunused-variable]
     ll q, w, e, a, b;
           ^
job.cpp:83:14: warning: unused variable 'e' [-Wunused-variable]
     ll q, w, e, a, b;
              ^
job.cpp:83:17: warning: unused variable 'a' [-Wunused-variable]
     ll q, w, e, a, b;
                 ^
job.cpp:83:20: warning: unused variable 'b' [-Wunused-variable]
     ll q, w, e, a, b;
                    ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5136 KB Output is correct
5 Correct 34 ms 9720 KB Output is correct
6 Correct 60 ms 14408 KB Output is correct
7 Correct 88 ms 19112 KB Output is correct
8 Correct 114 ms 23832 KB Output is correct
9 Correct 123 ms 23900 KB Output is correct
10 Correct 114 ms 23904 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 115 ms 23800 KB Output is correct
13 Correct 121 ms 23800 KB Output is correct
14 Correct 121 ms 24028 KB Output is correct
15 Correct 120 ms 23820 KB Output is correct
16 Correct 113 ms 23800 KB Output is correct
17 Correct 117 ms 23800 KB Output is correct
18 Correct 113 ms 23928 KB Output is correct
19 Correct 114 ms 23800 KB Output is correct
20 Correct 120 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 173 ms 30932 KB Output is correct
5 Correct 173 ms 30916 KB Output is correct
6 Correct 185 ms 30960 KB Output is correct
7 Correct 173 ms 30916 KB Output is correct
8 Correct 185 ms 30788 KB Output is correct
9 Correct 182 ms 30928 KB Output is correct
10 Correct 185 ms 30912 KB Output is correct
11 Correct 176 ms 30932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5100 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5240 KB Output is correct
5 Correct 15 ms 6444 KB Output is correct
6 Correct 196 ms 31488 KB Output is correct
7 Correct 196 ms 31556 KB Output is correct
8 Correct 204 ms 31560 KB Output is correct
9 Correct 206 ms 31684 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 8 ms 5240 KB Output is correct
12 Correct 13 ms 6264 KB Output is correct
13 Correct 14 ms 6444 KB Output is correct
14 Correct 192 ms 31680 KB Output is correct
15 Correct 194 ms 31572 KB Output is correct
16 Correct 191 ms 31556 KB Output is correct
17 Correct 192 ms 31684 KB Output is correct
18 Correct 194 ms 31352 KB Output is correct
19 Correct 199 ms 31720 KB Output is correct
20 Correct 191 ms 31552 KB Output is correct
21 Correct 196 ms 31444 KB Output is correct
22 Correct 206 ms 31556 KB Output is correct
23 Correct 197 ms 31572 KB Output is correct
24 Correct 190 ms 31428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Incorrect 191 ms 41208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Incorrect 6 ms 4984 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5136 KB Output is correct
5 Correct 34 ms 9720 KB Output is correct
6 Correct 60 ms 14408 KB Output is correct
7 Correct 88 ms 19112 KB Output is correct
8 Correct 114 ms 23832 KB Output is correct
9 Correct 123 ms 23900 KB Output is correct
10 Correct 114 ms 23904 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 115 ms 23800 KB Output is correct
13 Correct 121 ms 23800 KB Output is correct
14 Correct 121 ms 24028 KB Output is correct
15 Correct 120 ms 23820 KB Output is correct
16 Correct 113 ms 23800 KB Output is correct
17 Correct 117 ms 23800 KB Output is correct
18 Correct 113 ms 23928 KB Output is correct
19 Correct 114 ms 23800 KB Output is correct
20 Correct 120 ms 23924 KB Output is correct
21 Correct 8 ms 5112 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 7 ms 5112 KB Output is correct
24 Correct 173 ms 30932 KB Output is correct
25 Correct 173 ms 30916 KB Output is correct
26 Correct 185 ms 30960 KB Output is correct
27 Correct 173 ms 30916 KB Output is correct
28 Correct 185 ms 30788 KB Output is correct
29 Correct 182 ms 30928 KB Output is correct
30 Correct 185 ms 30912 KB Output is correct
31 Correct 176 ms 30932 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 8 ms 5100 KB Output is correct
34 Correct 7 ms 5112 KB Output is correct
35 Correct 7 ms 5240 KB Output is correct
36 Correct 15 ms 6444 KB Output is correct
37 Correct 196 ms 31488 KB Output is correct
38 Correct 196 ms 31556 KB Output is correct
39 Correct 204 ms 31560 KB Output is correct
40 Correct 206 ms 31684 KB Output is correct
41 Correct 7 ms 5112 KB Output is correct
42 Correct 8 ms 5240 KB Output is correct
43 Correct 13 ms 6264 KB Output is correct
44 Correct 14 ms 6444 KB Output is correct
45 Correct 192 ms 31680 KB Output is correct
46 Correct 194 ms 31572 KB Output is correct
47 Correct 191 ms 31556 KB Output is correct
48 Correct 192 ms 31684 KB Output is correct
49 Correct 194 ms 31352 KB Output is correct
50 Correct 199 ms 31720 KB Output is correct
51 Correct 191 ms 31552 KB Output is correct
52 Correct 196 ms 31444 KB Output is correct
53 Correct 206 ms 31556 KB Output is correct
54 Correct 197 ms 31572 KB Output is correct
55 Correct 190 ms 31428 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Incorrect 191 ms 41208 KB Output isn't correct
58 Halted 0 ms 0 KB -