답안 #322042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322042 2020-11-14T00:00:38 Z fivefourthreeone Job Scheduling (IOI19_job) C++17
100 / 100
367 ms 20204 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 bad[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;
    bad[b] = true;
    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] || bad[id])continue;
        if(par[id]==-1 || done[find(par[id])]) {
            curr+=t;
            res+=cst*curr;
            done[id] = true;
            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")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 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 138 ms 10980 KB Output is correct
7 Correct 219 ms 15456 KB Output is correct
8 Correct 307 ms 16864 KB Output is correct
9 Correct 367 ms 16848 KB Output is correct
10 Correct 306 ms 16864 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 331 ms 16864 KB Output is correct
13 Correct 256 ms 16864 KB Output is correct
14 Correct 274 ms 16864 KB Output is correct
15 Correct 219 ms 16864 KB Output is correct
16 Correct 235 ms 16864 KB Output is correct
17 Correct 307 ms 16864 KB Output is correct
18 Correct 303 ms 16864 KB Output is correct
19 Correct 220 ms 16864 KB Output is correct
20 Correct 159 ms 16864 KB Output is correct
# 결과 실행 시간 메모리 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 180 ms 16864 KB Output is correct
5 Correct 180 ms 16864 KB Output is correct
6 Correct 176 ms 16864 KB Output is correct
7 Correct 180 ms 16864 KB Output is correct
8 Correct 183 ms 16864 KB Output is correct
9 Correct 181 ms 16864 KB Output is correct
10 Correct 184 ms 16864 KB Output is correct
11 Correct 185 ms 16864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 181 ms 19296 KB Output is correct
7 Correct 181 ms 19168 KB Output is correct
8 Correct 188 ms 19168 KB Output is correct
9 Correct 197 ms 19168 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 9 ms 5936 KB Output is correct
13 Correct 10 ms 5936 KB Output is correct
14 Correct 180 ms 19212 KB Output is correct
15 Correct 178 ms 19296 KB Output is correct
16 Correct 179 ms 19168 KB Output is correct
17 Correct 184 ms 19168 KB Output is correct
18 Correct 180 ms 19168 KB Output is correct
19 Correct 182 ms 19168 KB Output is correct
20 Correct 183 ms 19168 KB Output is correct
21 Correct 190 ms 19168 KB Output is correct
22 Correct 182 ms 19168 KB Output is correct
23 Correct 178 ms 19168 KB Output is correct
24 Correct 180 ms 19168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 311 ms 16864 KB Output is correct
3 Correct 317 ms 20056 KB Output is correct
4 Correct 314 ms 20204 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 5100 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 5228 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 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 138 ms 10980 KB Output is correct
7 Correct 219 ms 15456 KB Output is correct
8 Correct 307 ms 16864 KB Output is correct
9 Correct 367 ms 16848 KB Output is correct
10 Correct 306 ms 16864 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 331 ms 16864 KB Output is correct
13 Correct 256 ms 16864 KB Output is correct
14 Correct 274 ms 16864 KB Output is correct
15 Correct 219 ms 16864 KB Output is correct
16 Correct 235 ms 16864 KB Output is correct
17 Correct 307 ms 16864 KB Output is correct
18 Correct 303 ms 16864 KB Output is correct
19 Correct 220 ms 16864 KB Output is correct
20 Correct 159 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 180 ms 16864 KB Output is correct
25 Correct 180 ms 16864 KB Output is correct
26 Correct 176 ms 16864 KB Output is correct
27 Correct 180 ms 16864 KB Output is correct
28 Correct 183 ms 16864 KB Output is correct
29 Correct 181 ms 16864 KB Output is correct
30 Correct 184 ms 16864 KB Output is correct
31 Correct 185 ms 16864 KB Output is correct
32 Correct 3 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 181 ms 19296 KB Output is correct
38 Correct 181 ms 19168 KB Output is correct
39 Correct 188 ms 19168 KB Output is correct
40 Correct 197 ms 19168 KB Output is correct
41 Correct 4 ms 4972 KB Output is correct
42 Correct 6 ms 5228 KB Output is correct
43 Correct 9 ms 5936 KB Output is correct
44 Correct 10 ms 5936 KB Output is correct
45 Correct 180 ms 19212 KB Output is correct
46 Correct 178 ms 19296 KB Output is correct
47 Correct 179 ms 19168 KB Output is correct
48 Correct 184 ms 19168 KB Output is correct
49 Correct 180 ms 19168 KB Output is correct
50 Correct 182 ms 19168 KB Output is correct
51 Correct 183 ms 19168 KB Output is correct
52 Correct 190 ms 19168 KB Output is correct
53 Correct 182 ms 19168 KB Output is correct
54 Correct 178 ms 19168 KB Output is correct
55 Correct 180 ms 19168 KB Output is correct
56 Correct 4 ms 4972 KB Output is correct
57 Correct 311 ms 16864 KB Output is correct
58 Correct 317 ms 20056 KB Output is correct
59 Correct 314 ms 20204 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 4 ms 4972 KB Output is correct
66 Correct 4 ms 4972 KB Output is correct
67 Correct 4 ms 4972 KB Output is correct
68 Correct 4 ms 5100 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 5228 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 5004 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 4992 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 8 ms 5484 KB Output is correct
89 Correct 10 ms 5680 KB Output is correct
90 Correct 12 ms 5936 KB Output is correct
91 Correct 54 ms 8808 KB Output is correct
92 Correct 111 ms 12516 KB Output is correct
93 Correct 279 ms 19936 KB Output is correct
94 Correct 272 ms 19936 KB Output is correct
95 Correct 278 ms 19936 KB Output is correct
96 Correct 264 ms 19936 KB Output is correct
97 Correct 265 ms 19808 KB Output is correct
98 Correct 262 ms 19936 KB Output is correct
99 Correct 229 ms 19936 KB Output is correct
100 Correct 292 ms 19936 KB Output is correct
101 Correct 308 ms 19936 KB Output is correct
102 Correct 204 ms 19936 KB Output is correct
103 Correct 274 ms 19936 KB Output is correct
104 Correct 288 ms 19936 KB Output is correct
105 Correct 214 ms 19936 KB Output is correct
106 Correct 179 ms 19296 KB Output is correct