Submission #322043

# Submission time Handle Problem Language Result Execution time Memory
322043 2020-11-14T00:01:29 Z fivefourthreeone Job Scheduling (IOI19_job) C++17
100 / 100
314 ms 16992 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(auto i=(a);i<(b); ++i)
#define uwu(i,a, b) for(auto i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = atan(1);
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
vector<int> adj[mxN];
int p[mxN];
int n;
int dsu[mxN];
bool done[mxN];
bool cmp(array<ll, 3> a, array<ll, 3> b) {
    if(a[0]*b[1]==a[1]*b[0]) {
        return a[2] < b[2];
    }
    return a[0]*b[1] > a[1]*b[0];
}
int find(int a) {
    return a==dsu[a] ? a : dsu[a] = find(dsu[a]);
}
bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if(a==b)return false;
    dsu[b] = a;
    return true;
}
ll scheduling_cost(vector<int> par, vector<int> u, vector<int> d) {
    n = par.size();
    iota(dsu, dsu+n, 0);
    priority_queue<array<ll, 3>, vector<array<ll, 3>>, decltype(&cmp)> pq(cmp);
    owo(i, 0, n) {
        pq.push({d[i], u[i], i});
    }
    ll res = 0;
    ll curr = 0;
    while(!pq.empty()) {
        auto[t, cst, id] = pq.top();
        pq.pop();
        //cout<<t<<" "<<cst<<" "<<id<<endl;
        if(tie(t, cst)!=tie(d[id], u[id]) || done[id])continue;
        done[id] = true;
        if(par[id]==-1 || done[find(par[id])]) {
            curr+=t;
            res+=cst*curr;
            continue;
        }
        int nxt = find(par[id]);
        res-=t*u[nxt];
        u[nxt]+=cst;
        d[nxt]+=t;
        merge(nxt, id);
        pq.push({d[nxt], u[nxt], nxt});
    }
    return res;
}/*
vector<int> PAR, U, D;
int N;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>N;
    PAR.resize(N);
    U.resize(N);
    D.resize(N);
    owo(i, 0, N) {
        cin>>PAR[i];
    }
    owo(i, 0, N) {
        cin>>U[i];
    }
    owo(i, 0, N) {
        cin>>D[i];
    }
    cout<<scheduling_cost(PAR, U, D);
    return 0;
}*/

Compilation message

job.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
job.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 57 ms 8040 KB Output is correct
6 Correct 126 ms 10980 KB Output is correct
7 Correct 213 ms 15456 KB Output is correct
8 Correct 309 ms 16864 KB Output is correct
9 Correct 307 ms 16864 KB Output is correct
10 Correct 307 ms 16864 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 314 ms 16864 KB Output is correct
13 Correct 253 ms 16884 KB Output is correct
14 Correct 255 ms 16864 KB Output is correct
15 Correct 218 ms 16864 KB Output is correct
16 Correct 239 ms 16864 KB Output is correct
17 Correct 304 ms 16832 KB Output is correct
18 Correct 303 ms 16864 KB Output is correct
19 Correct 227 ms 16864 KB Output is correct
20 Correct 162 ms 16864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 178 ms 16864 KB Output is correct
5 Correct 175 ms 16864 KB Output is correct
6 Correct 180 ms 16864 KB Output is correct
7 Correct 174 ms 16864 KB Output is correct
8 Correct 176 ms 16992 KB Output is correct
9 Correct 187 ms 16864 KB Output is correct
10 Correct 177 ms 16864 KB Output is correct
11 Correct 183 ms 16992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 10 ms 5808 KB Output is correct
6 Correct 182 ms 16864 KB Output is correct
7 Correct 178 ms 16864 KB Output is correct
8 Correct 178 ms 16864 KB Output is correct
9 Correct 178 ms 16864 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 9 ms 5808 KB Output is correct
13 Correct 10 ms 5808 KB Output is correct
14 Correct 176 ms 16992 KB Output is correct
15 Correct 178 ms 16864 KB Output is correct
16 Correct 178 ms 16860 KB Output is correct
17 Correct 177 ms 16864 KB Output is correct
18 Correct 179 ms 16864 KB Output is correct
19 Correct 179 ms 16864 KB Output is correct
20 Correct 182 ms 16864 KB Output is correct
21 Correct 183 ms 16864 KB Output is correct
22 Correct 174 ms 16864 KB Output is correct
23 Correct 182 ms 16864 KB Output is correct
24 Correct 178 ms 16880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 310 ms 16864 KB Output is correct
3 Correct 307 ms 16864 KB Output is correct
4 Correct 309 ms 16864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 5 ms 5100 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 57 ms 8040 KB Output is correct
6 Correct 126 ms 10980 KB Output is correct
7 Correct 213 ms 15456 KB Output is correct
8 Correct 309 ms 16864 KB Output is correct
9 Correct 307 ms 16864 KB Output is correct
10 Correct 307 ms 16864 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 314 ms 16864 KB Output is correct
13 Correct 253 ms 16884 KB Output is correct
14 Correct 255 ms 16864 KB Output is correct
15 Correct 218 ms 16864 KB Output is correct
16 Correct 239 ms 16864 KB Output is correct
17 Correct 304 ms 16832 KB Output is correct
18 Correct 303 ms 16864 KB Output is correct
19 Correct 227 ms 16864 KB Output is correct
20 Correct 162 ms 16864 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 4 ms 4972 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 178 ms 16864 KB Output is correct
25 Correct 175 ms 16864 KB Output is correct
26 Correct 180 ms 16864 KB Output is correct
27 Correct 174 ms 16864 KB Output is correct
28 Correct 176 ms 16992 KB Output is correct
29 Correct 187 ms 16864 KB Output is correct
30 Correct 177 ms 16864 KB Output is correct
31 Correct 183 ms 16992 KB Output is correct
32 Correct 4 ms 4972 KB Output is correct
33 Correct 4 ms 4972 KB Output is correct
34 Correct 4 ms 4972 KB Output is correct
35 Correct 4 ms 5100 KB Output is correct
36 Correct 10 ms 5808 KB Output is correct
37 Correct 182 ms 16864 KB Output is correct
38 Correct 178 ms 16864 KB Output is correct
39 Correct 178 ms 16864 KB Output is correct
40 Correct 178 ms 16864 KB Output is correct
41 Correct 4 ms 4972 KB Output is correct
42 Correct 4 ms 5100 KB Output is correct
43 Correct 9 ms 5808 KB Output is correct
44 Correct 10 ms 5808 KB Output is correct
45 Correct 176 ms 16992 KB Output is correct
46 Correct 178 ms 16864 KB Output is correct
47 Correct 178 ms 16860 KB Output is correct
48 Correct 177 ms 16864 KB Output is correct
49 Correct 179 ms 16864 KB Output is correct
50 Correct 179 ms 16864 KB Output is correct
51 Correct 182 ms 16864 KB Output is correct
52 Correct 183 ms 16864 KB Output is correct
53 Correct 174 ms 16864 KB Output is correct
54 Correct 182 ms 16864 KB Output is correct
55 Correct 178 ms 16880 KB Output is correct
56 Correct 4 ms 4972 KB Output is correct
57 Correct 310 ms 16864 KB Output is correct
58 Correct 307 ms 16864 KB Output is correct
59 Correct 309 ms 16864 KB Output is correct
60 Correct 4 ms 4972 KB Output is correct
61 Correct 4 ms 4972 KB Output is correct
62 Correct 4 ms 5100 KB Output is correct
63 Correct 4 ms 5100 KB Output is correct
64 Correct 4 ms 5100 KB Output is correct
65 Correct 5 ms 5100 KB Output is correct
66 Correct 4 ms 4972 KB Output is correct
67 Correct 4 ms 4992 KB Output is correct
68 Correct 4 ms 5120 KB Output is correct
69 Correct 4 ms 5100 KB Output is correct
70 Correct 4 ms 5100 KB Output is correct
71 Correct 4 ms 5100 KB Output is correct
72 Correct 4 ms 5100 KB Output is correct
73 Correct 4 ms 5100 KB Output is correct
74 Correct 4 ms 5100 KB Output is correct
75 Correct 4 ms 5100 KB Output is correct
76 Correct 4 ms 5100 KB Output is correct
77 Correct 4 ms 4972 KB Output is correct
78 Correct 4 ms 4972 KB Output is correct
79 Correct 4 ms 4972 KB Output is correct
80 Correct 4 ms 4972 KB Output is correct
81 Correct 4 ms 4972 KB Output is correct
82 Correct 4 ms 4972 KB Output is correct
83 Correct 4 ms 4972 KB Output is correct
84 Correct 4 ms 4972 KB Output is correct
85 Correct 4 ms 4972 KB Output is correct
86 Correct 4 ms 4972 KB Output is correct
87 Correct 4 ms 4972 KB Output is correct
88 Correct 7 ms 5484 KB Output is correct
89 Correct 10 ms 5552 KB Output is correct
90 Correct 12 ms 5808 KB Output is correct
91 Correct 50 ms 8040 KB Output is correct
92 Correct 107 ms 10980 KB Output is correct
93 Correct 270 ms 16992 KB Output is correct
94 Correct 267 ms 16864 KB Output is correct
95 Correct 273 ms 16864 KB Output is correct
96 Correct 286 ms 16864 KB Output is correct
97 Correct 255 ms 16864 KB Output is correct
98 Correct 250 ms 16864 KB Output is correct
99 Correct 213 ms 16864 KB Output is correct
100 Correct 268 ms 16864 KB Output is correct
101 Correct 306 ms 16864 KB Output is correct
102 Correct 201 ms 16864 KB Output is correct
103 Correct 286 ms 16864 KB Output is correct
104 Correct 287 ms 16864 KB Output is correct
105 Correct 210 ms 16992 KB Output is correct
106 Correct 183 ms 16864 KB Output is correct