답안 #155242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155242 2019-09-27T09:24:11 Z pink_bittern Job Scheduling (IOI19_job) C++14
100 / 100
648 ms 89412 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;

bool BAD[maxn];

vector <ll> V[maxn];

pll ANS[maxn];

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

struct cmp1{
    bool operator ()(ll a1, ll b1){
        pll a = ANS[a1], b = ANS[b1];
        if (a.first * b.second == b.first * a.second){
            return a1 < b1;
        }
        return a.first * b.second < b.first * a.second;
    }
};

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

ll I[maxn];

set <ll, cmp1> S[maxn];

void dfs(ll v, ll p){
    ll q;
    I[v] = v;
    ll mx = 0;
    for (q = 0; q < V[v].size(); q++){
        if (V[v][q] == p){
            continue;
        }
        dfs(V[v][q], v);
        ll i = I[V[v][q]];
        if (S[i].size() > mx){
            mx = S[i].size();
            I[v] = i;
        }
    }
//    cout << "V " << v << " " << I[v] << endl;
    for (q = 0; q < V[v].size(); q++){
        if (V[v][q] == p){
            continue;
        }
        if (I[V[v][q]] == I[v]){
//            cout << "CONTINUE " << V[v][q] << endl;
            continue;
        }
        ll i = I[V[v][q]];
        for (auto el : S[i]){
//            cout << S[I[v]].size() << " SIZE 1" << endl;
            S[I[v]].insert(el);
//            cout << "INSERTING " << el << endl;
//            cout << S[I[v]].size() << " SIZE 2" << endl;
        }
    }
//    cout << "SZ " << S[I[v]].size() << endl;
//    cout << "FIRST " << *(S[I[v]].begin()) << endl;
    ANS[v] = mp(D[v], U[v]);
    vector <ll> merged;
    ll t = D[v], st = D[v];
    while (!S[I[v]].empty()){
        ll i = *(S[I[v]].begin());
//        cout << "I " << i << endl;
        if (cmp2(i, v)){
            merged.pb(i);
            st += ANS[i].first;
            S[I[v]].erase(S[I[v]].begin());
            ANS[v].first += ANS[i].first;
            ANS[v].second += ANS[i].second;
        }
        else{
//            cout << "BREAKING " << i << " " << v << endl;
            break;
        }
    }
    ans -= (st - t) * (U[v]);
//    cout << "DANS " << (st - t) * (U[v]) << " " << st << " " << t << " " << v << endl;
    for (q = 0; q < merged.size(); q++){
        ll i = merged[q];
        BAD[i] = 1;
        t += ANS[i].first;
        ans -= ANS[i].second * (st - t);
//        cout << "DANS1 " << (st - t) * (ANS[i].second) << endl;
    }
    S[I[v]].insert(v);
}

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]);
        }
    }
    dfs(0, 0);
    vector <ll> ALL;
    for (q = 0; q < n; q++){
        ALL.pb(q);
    }
    sort(ALL.begin(), ALL.end(), cmp2);
    ll t = 0;
//    cout << "ANS B4 " << ans << endl;
    for (q = 0; q < ALL.size(); q++){
        if (BAD[ALL[q]]){
            continue;
        }
//        cout << "GOOD " << ALL[q] << " " << ANS[ALL[q]].first << " " << ANS[ALL[q]].second << endl;
        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:63:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < V[v].size(); q++){
                 ~~^~~~~~~~~~~~~
job.cpp:69:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (S[i].size() > mx){
             ~~~~~~~~~~~~^~~~
job.cpp:75:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < V[v].size(); q++){
                 ~~^~~~~~~~~~~~~
job.cpp:113:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < merged.size(); q++){
                 ~~^~~~~~~~~~~~~~~
job.cpp: In function 'll scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:147:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (q = 0; q < ALL.size(); q++){
                 ~~^~~~~~~~~~~~
job.cpp:125:10: warning: variable 'is_bamboo' set but not used [-Wunused-but-set-variable]
     bool is_bamboo = 1;
          ^~~~~~~~~
job.cpp:126:11: warning: unused variable 'w' [-Wunused-variable]
     ll q, w, e, a, b;
           ^
job.cpp:126:14: warning: unused variable 'e' [-Wunused-variable]
     ll q, w, e, a, b;
              ^
job.cpp:126:17: warning: unused variable 'a' [-Wunused-variable]
     ll q, w, e, a, b;
                 ^
job.cpp:126:20: warning: unused variable 'b' [-Wunused-variable]
     ll q, w, e, a, b;
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 17 ms 14456 KB Output is correct
3 Correct 16 ms 14436 KB Output is correct
4 Correct 15 ms 14712 KB Output is correct
5 Correct 65 ms 28792 KB Output is correct
6 Correct 121 ms 43036 KB Output is correct
7 Correct 174 ms 57884 KB Output is correct
8 Correct 231 ms 71704 KB Output is correct
9 Correct 241 ms 71660 KB Output is correct
10 Correct 265 ms 71696 KB Output is correct
11 Correct 14 ms 14460 KB Output is correct
12 Correct 225 ms 71660 KB Output is correct
13 Correct 200 ms 71660 KB Output is correct
14 Correct 224 ms 71740 KB Output is correct
15 Correct 187 ms 71792 KB Output is correct
16 Correct 224 ms 71748 KB Output is correct
17 Correct 225 ms 71760 KB Output is correct
18 Correct 235 ms 71784 KB Output is correct
19 Correct 198 ms 71660 KB Output is correct
20 Correct 233 ms 78088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 14508 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 324 ms 60136 KB Output is correct
5 Correct 374 ms 60264 KB Output is correct
6 Correct 341 ms 60232 KB Output is correct
7 Correct 331 ms 60188 KB Output is correct
8 Correct 333 ms 60028 KB Output is correct
9 Correct 322 ms 60108 KB Output is correct
10 Correct 339 ms 60164 KB Output is correct
11 Correct 367 ms 60128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14460 KB Output is correct
4 Correct 16 ms 14712 KB Output is correct
5 Correct 25 ms 16888 KB Output is correct
6 Correct 403 ms 60660 KB Output is correct
7 Correct 338 ms 60776 KB Output is correct
8 Correct 335 ms 60708 KB Output is correct
9 Correct 350 ms 60776 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 16 ms 14840 KB Output is correct
12 Correct 23 ms 16504 KB Output is correct
13 Correct 25 ms 16760 KB Output is correct
14 Correct 347 ms 60648 KB Output is correct
15 Correct 357 ms 60648 KB Output is correct
16 Correct 332 ms 60840 KB Output is correct
17 Correct 340 ms 60708 KB Output is correct
18 Correct 369 ms 60688 KB Output is correct
19 Correct 349 ms 60884 KB Output is correct
20 Correct 347 ms 60648 KB Output is correct
21 Correct 359 ms 60636 KB Output is correct
22 Correct 369 ms 60776 KB Output is correct
23 Correct 355 ms 60776 KB Output is correct
24 Correct 346 ms 60648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 222 ms 56060 KB Output is correct
3 Correct 219 ms 56108 KB Output is correct
4 Correct 226 ms 56032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 14480 KB Output is correct
2 Correct 16 ms 14456 KB Output is correct
3 Correct 17 ms 14456 KB Output is correct
4 Correct 18 ms 14472 KB Output is correct
5 Correct 17 ms 14456 KB Output is correct
6 Correct 17 ms 14456 KB Output is correct
7 Correct 16 ms 14456 KB Output is correct
8 Correct 17 ms 14456 KB Output is correct
9 Correct 17 ms 14456 KB Output is correct
10 Correct 15 ms 14456 KB Output is correct
11 Correct 17 ms 14456 KB Output is correct
12 Correct 17 ms 14456 KB Output is correct
13 Correct 17 ms 14456 KB Output is correct
14 Correct 17 ms 14456 KB Output is correct
15 Correct 17 ms 14456 KB Output is correct
16 Correct 15 ms 14456 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 17 ms 14456 KB Output is correct
3 Correct 16 ms 14436 KB Output is correct
4 Correct 15 ms 14712 KB Output is correct
5 Correct 65 ms 28792 KB Output is correct
6 Correct 121 ms 43036 KB Output is correct
7 Correct 174 ms 57884 KB Output is correct
8 Correct 231 ms 71704 KB Output is correct
9 Correct 241 ms 71660 KB Output is correct
10 Correct 265 ms 71696 KB Output is correct
11 Correct 14 ms 14460 KB Output is correct
12 Correct 225 ms 71660 KB Output is correct
13 Correct 200 ms 71660 KB Output is correct
14 Correct 224 ms 71740 KB Output is correct
15 Correct 187 ms 71792 KB Output is correct
16 Correct 224 ms 71748 KB Output is correct
17 Correct 225 ms 71760 KB Output is correct
18 Correct 235 ms 71784 KB Output is correct
19 Correct 198 ms 71660 KB Output is correct
20 Correct 233 ms 78088 KB Output is correct
21 Correct 16 ms 14508 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 324 ms 60136 KB Output is correct
25 Correct 374 ms 60264 KB Output is correct
26 Correct 341 ms 60232 KB Output is correct
27 Correct 331 ms 60188 KB Output is correct
28 Correct 333 ms 60028 KB Output is correct
29 Correct 322 ms 60108 KB Output is correct
30 Correct 339 ms 60164 KB Output is correct
31 Correct 367 ms 60128 KB Output is correct
32 Correct 14 ms 14456 KB Output is correct
33 Correct 14 ms 14456 KB Output is correct
34 Correct 14 ms 14460 KB Output is correct
35 Correct 16 ms 14712 KB Output is correct
36 Correct 25 ms 16888 KB Output is correct
37 Correct 403 ms 60660 KB Output is correct
38 Correct 338 ms 60776 KB Output is correct
39 Correct 335 ms 60708 KB Output is correct
40 Correct 350 ms 60776 KB Output is correct
41 Correct 14 ms 14456 KB Output is correct
42 Correct 16 ms 14840 KB Output is correct
43 Correct 23 ms 16504 KB Output is correct
44 Correct 25 ms 16760 KB Output is correct
45 Correct 347 ms 60648 KB Output is correct
46 Correct 357 ms 60648 KB Output is correct
47 Correct 332 ms 60840 KB Output is correct
48 Correct 340 ms 60708 KB Output is correct
49 Correct 369 ms 60688 KB Output is correct
50 Correct 349 ms 60884 KB Output is correct
51 Correct 347 ms 60648 KB Output is correct
52 Correct 359 ms 60636 KB Output is correct
53 Correct 369 ms 60776 KB Output is correct
54 Correct 355 ms 60776 KB Output is correct
55 Correct 346 ms 60648 KB Output is correct
56 Correct 14 ms 14456 KB Output is correct
57 Correct 222 ms 56060 KB Output is correct
58 Correct 219 ms 56108 KB Output is correct
59 Correct 226 ms 56032 KB Output is correct
60 Correct 24 ms 14480 KB Output is correct
61 Correct 16 ms 14456 KB Output is correct
62 Correct 17 ms 14456 KB Output is correct
63 Correct 18 ms 14472 KB Output is correct
64 Correct 17 ms 14456 KB Output is correct
65 Correct 17 ms 14456 KB Output is correct
66 Correct 16 ms 14456 KB Output is correct
67 Correct 17 ms 14456 KB Output is correct
68 Correct 17 ms 14456 KB Output is correct
69 Correct 15 ms 14456 KB Output is correct
70 Correct 17 ms 14456 KB Output is correct
71 Correct 17 ms 14456 KB Output is correct
72 Correct 17 ms 14456 KB Output is correct
73 Correct 17 ms 14456 KB Output is correct
74 Correct 17 ms 14456 KB Output is correct
75 Correct 15 ms 14456 KB Output is correct
76 Correct 14 ms 14456 KB Output is correct
77 Correct 14 ms 14456 KB Output is correct
78 Correct 15 ms 14508 KB Output is correct
79 Correct 14 ms 14516 KB Output is correct
80 Correct 14 ms 14584 KB Output is correct
81 Correct 14 ms 14456 KB Output is correct
82 Correct 14 ms 14456 KB Output is correct
83 Correct 14 ms 14456 KB Output is correct
84 Correct 14 ms 14456 KB Output is correct
85 Correct 14 ms 14416 KB Output is correct
86 Correct 14 ms 14456 KB Output is correct
87 Correct 14 ms 14456 KB Output is correct
88 Correct 21 ms 15736 KB Output is correct
89 Correct 25 ms 16376 KB Output is correct
90 Correct 28 ms 17016 KB Output is correct
91 Correct 106 ms 27488 KB Output is correct
92 Correct 218 ms 41304 KB Output is correct
93 Correct 470 ms 68460 KB Output is correct
94 Correct 476 ms 69104 KB Output is correct
95 Correct 506 ms 68980 KB Output is correct
96 Correct 492 ms 68976 KB Output is correct
97 Correct 473 ms 70252 KB Output is correct
98 Correct 471 ms 71668 KB Output is correct
99 Correct 542 ms 78556 KB Output is correct
100 Correct 479 ms 68844 KB Output is correct
101 Correct 428 ms 60116 KB Output is correct
102 Correct 648 ms 89412 KB Output is correct
103 Correct 455 ms 60536 KB Output is correct
104 Correct 382 ms 54380 KB Output is correct
105 Correct 269 ms 51564 KB Output is correct
106 Correct 502 ms 69420 KB Output is correct