답안 #660227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660227 2022-11-21T08:39:08 Z wenqi Job Scheduling (IOI19_job) C++17
100 / 100
237 ms 18752 KB
// trans rights
#include <bits/extc++.h>
using namespace std;
#include "job.h"
using ll = long long;
using base = complex<double>;
#define up(k, N) for (int k = 1; k <= N; k++)
#define down(k, N) for (int k = N; k >= 1; k--)
#define f0(A) memset(A, 0, sizeof(A))
#define f3(A) memset(A, 0x3f, sizeof(A))
#define all(A) begin(A), end(A)

struct Job
{
    int id;
    ll d, u;

    bool operator < (const Job &a) const
    {
        return d * a.u > a.d * u;
    }

    bool operator != (const Job &a) const
    {
        return d != a.d or u != a.u;
    }
};

Job jobs[200069];
bool taken[200069];
int parents[200069];

int getp(int i)
{
    return i == parents[i] ? i : parents[i] = getp(parents[i]);
}

ll scheduling_cost(vector<int> P, vector<int> U, vector<int> D)
{
    int N = (int) P.size();
    priority_queue<Job> pq;
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        Job job;
        job.id = i;
        job.u = U[i];
        job.d = D[i];
        ans += job.u * job.d;
        jobs[i] = job;
        pq.push(job);
        parents[i] = i;
    }
    while (not pq.empty())
    {
        auto job = pq.top();
        pq.pop();

        if (job != jobs[job.id] or taken[job.id])
            continue;

        int p = P[job.id];
        if (p == -1)
        {
        }else{
            auto &pj = jobs[getp(p)];
            ans += pj.d * job.u;
            pj.d += job.d;
            pj.u += job.u;
            pq.push(pj);
            parents[job.id] = getp(p);
        }
        taken[job.id] = true;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 34 ms 4972 KB Output is correct
6 Correct 75 ms 9528 KB Output is correct
7 Correct 143 ms 16072 KB Output is correct
8 Correct 237 ms 18608 KB Output is correct
9 Correct 185 ms 18644 KB Output is correct
10 Correct 185 ms 18740 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 231 ms 18692 KB Output is correct
13 Correct 151 ms 18636 KB Output is correct
14 Correct 171 ms 18752 KB Output is correct
15 Correct 131 ms 18732 KB Output is correct
16 Correct 139 ms 18616 KB Output is correct
17 Correct 188 ms 18696 KB Output is correct
18 Correct 232 ms 18660 KB Output is correct
19 Correct 115 ms 18648 KB Output is correct
20 Correct 120 ms 18680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 136 ms 17184 KB Output is correct
5 Correct 139 ms 17212 KB Output is correct
6 Correct 140 ms 17160 KB Output is correct
7 Correct 172 ms 17212 KB Output is correct
8 Correct 153 ms 17212 KB Output is correct
9 Correct 158 ms 17188 KB Output is correct
10 Correct 162 ms 17192 KB Output is correct
11 Correct 147 ms 17200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 6 ms 1304 KB Output is correct
6 Correct 158 ms 17720 KB Output is correct
7 Correct 169 ms 17808 KB Output is correct
8 Correct 144 ms 17712 KB Output is correct
9 Correct 155 ms 17736 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 5 ms 1284 KB Output is correct
13 Correct 6 ms 1304 KB Output is correct
14 Correct 142 ms 17736 KB Output is correct
15 Correct 147 ms 17828 KB Output is correct
16 Correct 146 ms 17740 KB Output is correct
17 Correct 151 ms 17732 KB Output is correct
18 Correct 154 ms 17728 KB Output is correct
19 Correct 145 ms 17720 KB Output is correct
20 Correct 151 ms 17720 KB Output is correct
21 Correct 169 ms 17752 KB Output is correct
22 Correct 140 ms 17760 KB Output is correct
23 Correct 141 ms 17732 KB Output is correct
24 Correct 143 ms 17720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 193 ms 18712 KB Output is correct
3 Correct 206 ms 18696 KB Output is correct
4 Correct 176 ms 18608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 34 ms 4972 KB Output is correct
6 Correct 75 ms 9528 KB Output is correct
7 Correct 143 ms 16072 KB Output is correct
8 Correct 237 ms 18608 KB Output is correct
9 Correct 185 ms 18644 KB Output is correct
10 Correct 185 ms 18740 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 231 ms 18692 KB Output is correct
13 Correct 151 ms 18636 KB Output is correct
14 Correct 171 ms 18752 KB Output is correct
15 Correct 131 ms 18732 KB Output is correct
16 Correct 139 ms 18616 KB Output is correct
17 Correct 188 ms 18696 KB Output is correct
18 Correct 232 ms 18660 KB Output is correct
19 Correct 115 ms 18648 KB Output is correct
20 Correct 120 ms 18680 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 136 ms 17184 KB Output is correct
25 Correct 139 ms 17212 KB Output is correct
26 Correct 140 ms 17160 KB Output is correct
27 Correct 172 ms 17212 KB Output is correct
28 Correct 153 ms 17212 KB Output is correct
29 Correct 158 ms 17188 KB Output is correct
30 Correct 162 ms 17192 KB Output is correct
31 Correct 147 ms 17200 KB Output is correct
32 Correct 0 ms 308 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 6 ms 1304 KB Output is correct
37 Correct 158 ms 17720 KB Output is correct
38 Correct 169 ms 17808 KB Output is correct
39 Correct 144 ms 17712 KB Output is correct
40 Correct 155 ms 17736 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 5 ms 1284 KB Output is correct
44 Correct 6 ms 1304 KB Output is correct
45 Correct 142 ms 17736 KB Output is correct
46 Correct 147 ms 17828 KB Output is correct
47 Correct 146 ms 17740 KB Output is correct
48 Correct 151 ms 17732 KB Output is correct
49 Correct 154 ms 17728 KB Output is correct
50 Correct 145 ms 17720 KB Output is correct
51 Correct 151 ms 17720 KB Output is correct
52 Correct 169 ms 17752 KB Output is correct
53 Correct 140 ms 17760 KB Output is correct
54 Correct 141 ms 17732 KB Output is correct
55 Correct 143 ms 17720 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 193 ms 18712 KB Output is correct
58 Correct 206 ms 18696 KB Output is correct
59 Correct 176 ms 18608 KB Output is correct
60 Correct 1 ms 312 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 320 KB Output is correct
64 Correct 1 ms 312 KB Output is correct
65 Correct 1 ms 312 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 312 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 312 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 0 ms 312 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 0 ms 212 KB Output is correct
82 Correct 1 ms 312 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 0 ms 212 KB Output is correct
86 Correct 0 ms 312 KB Output is correct
87 Correct 0 ms 212 KB Output is correct
88 Correct 3 ms 852 KB Output is correct
89 Correct 5 ms 1068 KB Output is correct
90 Correct 6 ms 1432 KB Output is correct
91 Correct 41 ms 4940 KB Output is correct
92 Correct 81 ms 9392 KB Output is correct
93 Correct 201 ms 18508 KB Output is correct
94 Correct 183 ms 18480 KB Output is correct
95 Correct 188 ms 18596 KB Output is correct
96 Correct 192 ms 18492 KB Output is correct
97 Correct 181 ms 18488 KB Output is correct
98 Correct 175 ms 18596 KB Output is correct
99 Correct 161 ms 18352 KB Output is correct
100 Correct 182 ms 18512 KB Output is correct
101 Correct 219 ms 18608 KB Output is correct
102 Correct 149 ms 18584 KB Output is correct
103 Correct 197 ms 18608 KB Output is correct
104 Correct 192 ms 18732 KB Output is correct
105 Correct 134 ms 18596 KB Output is correct
106 Correct 152 ms 17980 KB Output is correct