답안 #475081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475081 2021-09-21T04:22:24 Z cpp219 Job Scheduling (IOI19_job) C++14
100 / 100
360 ms 24076 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
typedef pair<ld,ll> LD;
const ll N = 2e5 + 9;
const ll inf = 1e9;
const ll esp = 1e-9;

ld d[N];
ll n,lab[N],ans,par[N],cost[N],Time[N],now;
priority_queue<LD> pq;

ll Find(ll u){
    if (lab[u] < 0) return u;
    return lab[u] = Find(lab[u]);
}

ll scheduling_cost(vector<int> p,vector<int> c,vector<int> D){
    memset(lab,-1,sizeof(lab)); n = p.size();
    for (ll i = 1;i <= n;i++){
        par[i] = p[i - 1] + 1; cost[i] = c[i - 1]; Time[i] = D[i - 1];
        d[i] = 1.0*inf*cost[i]/Time[i];
        pq.push({d[i],-i});
    }
    while(!pq.empty()){
        LD u = pq.top(); pq.pop(); u.sc *= -1;
        if (abs(d[u.sc] - u.fs) > esp) continue;
        if (!par[u.sc] || d[Find(par[u.sc])] == -1){
            now += Time[u.sc]; ans += now * cost[u.sc];
            //cout<<now<<" "<<cost[u.sc]<<" "<<u.sc<<"\n";
            d[u.sc] = -1;
        }
        else{
            ll v = Find(par[u.sc]); ans -= cost[v] * Time[u.sc];
            cost[v] += cost[u.sc]; Time[v] += Time[u.sc];
            d[v] = 1.0*inf * cost[v]/Time[v]; lab[u.sc] = v;
            pq.push({d[v],-v});
        }
    }
    //exit(0);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 3 ms 1996 KB Output is correct
5 Correct 56 ms 7484 KB Output is correct
6 Correct 142 ms 12828 KB Output is correct
7 Correct 207 ms 21168 KB Output is correct
8 Correct 320 ms 24020 KB Output is correct
9 Correct 315 ms 23972 KB Output is correct
10 Correct 299 ms 23964 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 287 ms 23956 KB Output is correct
13 Correct 227 ms 23956 KB Output is correct
14 Correct 266 ms 23968 KB Output is correct
15 Correct 256 ms 23964 KB Output is correct
16 Correct 221 ms 23852 KB Output is correct
17 Correct 310 ms 24068 KB Output is correct
18 Correct 286 ms 24076 KB Output is correct
19 Correct 194 ms 23972 KB Output is correct
20 Correct 154 ms 23964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 171 ms 22532 KB Output is correct
5 Correct 184 ms 22444 KB Output is correct
6 Correct 173 ms 22540 KB Output is correct
7 Correct 173 ms 22444 KB Output is correct
8 Correct 188 ms 22440 KB Output is correct
9 Correct 177 ms 22540 KB Output is correct
10 Correct 174 ms 22448 KB Output is correct
11 Correct 167 ms 22440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1996 KB Output is correct
5 Correct 10 ms 3160 KB Output is correct
6 Correct 178 ms 23064 KB Output is correct
7 Correct 178 ms 23096 KB Output is correct
8 Correct 169 ms 23076 KB Output is correct
9 Correct 215 ms 23104 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
11 Correct 2 ms 1996 KB Output is correct
12 Correct 7 ms 3156 KB Output is correct
13 Correct 7 ms 3144 KB Output is correct
14 Correct 184 ms 23084 KB Output is correct
15 Correct 195 ms 23188 KB Output is correct
16 Correct 196 ms 23084 KB Output is correct
17 Correct 179 ms 23096 KB Output is correct
18 Correct 193 ms 23072 KB Output is correct
19 Correct 180 ms 23064 KB Output is correct
20 Correct 175 ms 23100 KB Output is correct
21 Correct 174 ms 23100 KB Output is correct
22 Correct 231 ms 23068 KB Output is correct
23 Correct 170 ms 23080 KB Output is correct
24 Correct 201 ms 23096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 329 ms 24028 KB Output is correct
3 Correct 355 ms 23976 KB Output is correct
4 Correct 360 ms 23972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 2 ms 1836 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 1 ms 1844 KB Output is correct
16 Correct 1 ms 1868 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 3 ms 1996 KB Output is correct
5 Correct 56 ms 7484 KB Output is correct
6 Correct 142 ms 12828 KB Output is correct
7 Correct 207 ms 21168 KB Output is correct
8 Correct 320 ms 24020 KB Output is correct
9 Correct 315 ms 23972 KB Output is correct
10 Correct 299 ms 23964 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 287 ms 23956 KB Output is correct
13 Correct 227 ms 23956 KB Output is correct
14 Correct 266 ms 23968 KB Output is correct
15 Correct 256 ms 23964 KB Output is correct
16 Correct 221 ms 23852 KB Output is correct
17 Correct 310 ms 24068 KB Output is correct
18 Correct 286 ms 24076 KB Output is correct
19 Correct 194 ms 23972 KB Output is correct
20 Correct 154 ms 23964 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 1 ms 1868 KB Output is correct
23 Correct 1 ms 1868 KB Output is correct
24 Correct 171 ms 22532 KB Output is correct
25 Correct 184 ms 22444 KB Output is correct
26 Correct 173 ms 22540 KB Output is correct
27 Correct 173 ms 22444 KB Output is correct
28 Correct 188 ms 22440 KB Output is correct
29 Correct 177 ms 22540 KB Output is correct
30 Correct 174 ms 22448 KB Output is correct
31 Correct 167 ms 22440 KB Output is correct
32 Correct 1 ms 1868 KB Output is correct
33 Correct 1 ms 1868 KB Output is correct
34 Correct 1 ms 1868 KB Output is correct
35 Correct 2 ms 1996 KB Output is correct
36 Correct 10 ms 3160 KB Output is correct
37 Correct 178 ms 23064 KB Output is correct
38 Correct 178 ms 23096 KB Output is correct
39 Correct 169 ms 23076 KB Output is correct
40 Correct 215 ms 23104 KB Output is correct
41 Correct 1 ms 1868 KB Output is correct
42 Correct 2 ms 1996 KB Output is correct
43 Correct 7 ms 3156 KB Output is correct
44 Correct 7 ms 3144 KB Output is correct
45 Correct 184 ms 23084 KB Output is correct
46 Correct 195 ms 23188 KB Output is correct
47 Correct 196 ms 23084 KB Output is correct
48 Correct 179 ms 23096 KB Output is correct
49 Correct 193 ms 23072 KB Output is correct
50 Correct 180 ms 23064 KB Output is correct
51 Correct 175 ms 23100 KB Output is correct
52 Correct 174 ms 23100 KB Output is correct
53 Correct 231 ms 23068 KB Output is correct
54 Correct 170 ms 23080 KB Output is correct
55 Correct 201 ms 23096 KB Output is correct
56 Correct 1 ms 1868 KB Output is correct
57 Correct 329 ms 24028 KB Output is correct
58 Correct 355 ms 23976 KB Output is correct
59 Correct 360 ms 23972 KB Output is correct
60 Correct 1 ms 1868 KB Output is correct
61 Correct 2 ms 1868 KB Output is correct
62 Correct 1 ms 1868 KB Output is correct
63 Correct 1 ms 1868 KB Output is correct
64 Correct 2 ms 1868 KB Output is correct
65 Correct 1 ms 1868 KB Output is correct
66 Correct 1 ms 1868 KB Output is correct
67 Correct 2 ms 1868 KB Output is correct
68 Correct 1 ms 1868 KB Output is correct
69 Correct 2 ms 1836 KB Output is correct
70 Correct 2 ms 1868 KB Output is correct
71 Correct 2 ms 1868 KB Output is correct
72 Correct 1 ms 1868 KB Output is correct
73 Correct 2 ms 1868 KB Output is correct
74 Correct 1 ms 1844 KB Output is correct
75 Correct 1 ms 1868 KB Output is correct
76 Correct 2 ms 1868 KB Output is correct
77 Correct 1 ms 1868 KB Output is correct
78 Correct 1 ms 1868 KB Output is correct
79 Correct 1 ms 1868 KB Output is correct
80 Correct 1 ms 1868 KB Output is correct
81 Correct 1 ms 1868 KB Output is correct
82 Correct 2 ms 1844 KB Output is correct
83 Correct 2 ms 1868 KB Output is correct
84 Correct 1 ms 1868 KB Output is correct
85 Correct 1 ms 1868 KB Output is correct
86 Correct 2 ms 1884 KB Output is correct
87 Correct 1 ms 1868 KB Output is correct
88 Correct 7 ms 2616 KB Output is correct
89 Correct 8 ms 2868 KB Output is correct
90 Correct 12 ms 3200 KB Output is correct
91 Correct 66 ms 7416 KB Output is correct
92 Correct 119 ms 12816 KB Output is correct
93 Correct 300 ms 23828 KB Output is correct
94 Correct 325 ms 23856 KB Output is correct
95 Correct 290 ms 23832 KB Output is correct
96 Correct 294 ms 23872 KB Output is correct
97 Correct 262 ms 23708 KB Output is correct
98 Correct 276 ms 23960 KB Output is correct
99 Correct 223 ms 23744 KB Output is correct
100 Correct 265 ms 23840 KB Output is correct
101 Correct 291 ms 23964 KB Output is correct
102 Correct 192 ms 23868 KB Output is correct
103 Correct 281 ms 23868 KB Output is correct
104 Correct 275 ms 23976 KB Output is correct
105 Correct 203 ms 23964 KB Output is correct
106 Correct 183 ms 23456 KB Output is correct