답안 #308008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308008 2020-09-29T18:05:58 Z junseo Job Scheduling (IOI19_job) C++17
100 / 100
301 ms 20072 KB
#include "job.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x)
#define rmax(r, x) r = max(r, x)
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxn = 2e5 + 10;

struct Node {
	int i;
	ll u, d;
	Node(int i, int u, int d) : i(i), u(u), d(d) {}
	Node(void) : Node(0, 0, 0) {}
};

bool operator < (Node l, Node r) { return l.d * r.u > l.u * r.d; }

ll ans = 0;
int pa[maxn];
Node a[maxn];
priority_queue<Node> pq;

int fnd(int x) {
	if(pa[x] < 0)	return x;
	return pa[x] = fnd(pa[x]);
}

void mrge(int i, int j) {
	ans -= a[i].u * a[j].d;
	a[i].u += a[j].u;
	a[i].d += a[j].d;
}

void uni(int a, int b) {
	a = fnd(a), b = fnd(b);
	if(a == b)	return;
	pa[a] = b;
	mrge(b, a);
}

long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d) {
	int n = p.size();
	memset(pa, -1, sizeof(pa));
	for(int i = 0; i < n; ++i) {
		a[i] = Node(i, u[i], d[i]);
		if(i)	pq.emplace(a[i]);
	}
	while(!pq.empty()) {
		Node t = pq.top();	pq.pop();
		if(t.i == 0 || a[t.i].u != t.u)	continue;
		uni(t.i, p[t.i]);
		pq.emplace(a[fnd(t.i)]);
	}
	ans += a[0].u * a[0].d;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Correct 3 ms 5760 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 52 ms 8688 KB Output is correct
6 Correct 116 ms 11372 KB Output is correct
7 Correct 195 ms 15720 KB Output is correct
8 Correct 271 ms 16872 KB Output is correct
9 Correct 271 ms 16744 KB Output is correct
10 Correct 275 ms 16744 KB Output is correct
11 Correct 4 ms 5760 KB Output is correct
12 Correct 288 ms 16744 KB Output is correct
13 Correct 208 ms 16744 KB Output is correct
14 Correct 224 ms 16740 KB Output is correct
15 Correct 180 ms 16744 KB Output is correct
16 Correct 203 ms 16756 KB Output is correct
17 Correct 273 ms 16744 KB Output is correct
18 Correct 262 ms 16744 KB Output is correct
19 Correct 171 ms 16744 KB Output is correct
20 Correct 176 ms 16744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5888 KB Output is correct
2 Correct 3 ms 5760 KB Output is correct
3 Correct 3 ms 5760 KB Output is correct
4 Correct 195 ms 16744 KB Output is correct
5 Correct 202 ms 16872 KB Output is correct
6 Correct 197 ms 16744 KB Output is correct
7 Correct 199 ms 16744 KB Output is correct
8 Correct 203 ms 16744 KB Output is correct
9 Correct 198 ms 16744 KB Output is correct
10 Correct 199 ms 16744 KB Output is correct
11 Correct 212 ms 16744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Correct 4 ms 5760 KB Output is correct
4 Correct 5 ms 5888 KB Output is correct
5 Correct 11 ms 6596 KB Output is correct
6 Correct 202 ms 16744 KB Output is correct
7 Correct 202 ms 16744 KB Output is correct
8 Correct 202 ms 16744 KB Output is correct
9 Correct 213 ms 16744 KB Output is correct
10 Correct 4 ms 5760 KB Output is correct
11 Correct 5 ms 5888 KB Output is correct
12 Correct 10 ms 6596 KB Output is correct
13 Correct 11 ms 6596 KB Output is correct
14 Correct 205 ms 16744 KB Output is correct
15 Correct 208 ms 16744 KB Output is correct
16 Correct 202 ms 16744 KB Output is correct
17 Correct 202 ms 16744 KB Output is correct
18 Correct 202 ms 16744 KB Output is correct
19 Correct 206 ms 16744 KB Output is correct
20 Correct 206 ms 16992 KB Output is correct
21 Correct 207 ms 16744 KB Output is correct
22 Correct 198 ms 16748 KB Output is correct
23 Correct 208 ms 16736 KB Output is correct
24 Correct 200 ms 17000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5760 KB Output is correct
2 Correct 281 ms 19952 KB Output is correct
3 Correct 268 ms 19944 KB Output is correct
4 Correct 301 ms 19944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 4 ms 5836 KB Output is correct
3 Correct 3 ms 5760 KB Output is correct
4 Correct 4 ms 5760 KB Output is correct
5 Correct 4 ms 5760 KB Output is correct
6 Correct 4 ms 5760 KB Output is correct
7 Correct 4 ms 5760 KB Output is correct
8 Correct 4 ms 5760 KB Output is correct
9 Correct 4 ms 5760 KB Output is correct
10 Correct 4 ms 5760 KB Output is correct
11 Correct 4 ms 5760 KB Output is correct
12 Correct 4 ms 5760 KB Output is correct
13 Correct 4 ms 5760 KB Output is correct
14 Correct 4 ms 5760 KB Output is correct
15 Correct 4 ms 5760 KB Output is correct
16 Correct 4 ms 5760 KB Output is correct
17 Correct 4 ms 5760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Correct 3 ms 5760 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 52 ms 8688 KB Output is correct
6 Correct 116 ms 11372 KB Output is correct
7 Correct 195 ms 15720 KB Output is correct
8 Correct 271 ms 16872 KB Output is correct
9 Correct 271 ms 16744 KB Output is correct
10 Correct 275 ms 16744 KB Output is correct
11 Correct 4 ms 5760 KB Output is correct
12 Correct 288 ms 16744 KB Output is correct
13 Correct 208 ms 16744 KB Output is correct
14 Correct 224 ms 16740 KB Output is correct
15 Correct 180 ms 16744 KB Output is correct
16 Correct 203 ms 16756 KB Output is correct
17 Correct 273 ms 16744 KB Output is correct
18 Correct 262 ms 16744 KB Output is correct
19 Correct 171 ms 16744 KB Output is correct
20 Correct 176 ms 16744 KB Output is correct
21 Correct 4 ms 5888 KB Output is correct
22 Correct 3 ms 5760 KB Output is correct
23 Correct 3 ms 5760 KB Output is correct
24 Correct 195 ms 16744 KB Output is correct
25 Correct 202 ms 16872 KB Output is correct
26 Correct 197 ms 16744 KB Output is correct
27 Correct 199 ms 16744 KB Output is correct
28 Correct 203 ms 16744 KB Output is correct
29 Correct 198 ms 16744 KB Output is correct
30 Correct 199 ms 16744 KB Output is correct
31 Correct 212 ms 16744 KB Output is correct
32 Correct 3 ms 5760 KB Output is correct
33 Correct 4 ms 5760 KB Output is correct
34 Correct 4 ms 5760 KB Output is correct
35 Correct 5 ms 5888 KB Output is correct
36 Correct 11 ms 6596 KB Output is correct
37 Correct 202 ms 16744 KB Output is correct
38 Correct 202 ms 16744 KB Output is correct
39 Correct 202 ms 16744 KB Output is correct
40 Correct 213 ms 16744 KB Output is correct
41 Correct 4 ms 5760 KB Output is correct
42 Correct 5 ms 5888 KB Output is correct
43 Correct 10 ms 6596 KB Output is correct
44 Correct 11 ms 6596 KB Output is correct
45 Correct 205 ms 16744 KB Output is correct
46 Correct 208 ms 16744 KB Output is correct
47 Correct 202 ms 16744 KB Output is correct
48 Correct 202 ms 16744 KB Output is correct
49 Correct 202 ms 16744 KB Output is correct
50 Correct 206 ms 16744 KB Output is correct
51 Correct 206 ms 16992 KB Output is correct
52 Correct 207 ms 16744 KB Output is correct
53 Correct 198 ms 16748 KB Output is correct
54 Correct 208 ms 16736 KB Output is correct
55 Correct 200 ms 17000 KB Output is correct
56 Correct 3 ms 5760 KB Output is correct
57 Correct 281 ms 19952 KB Output is correct
58 Correct 268 ms 19944 KB Output is correct
59 Correct 301 ms 19944 KB Output is correct
60 Correct 4 ms 5760 KB Output is correct
61 Correct 4 ms 5836 KB Output is correct
62 Correct 3 ms 5760 KB Output is correct
63 Correct 4 ms 5760 KB Output is correct
64 Correct 4 ms 5760 KB Output is correct
65 Correct 4 ms 5760 KB Output is correct
66 Correct 4 ms 5760 KB Output is correct
67 Correct 4 ms 5760 KB Output is correct
68 Correct 4 ms 5760 KB Output is correct
69 Correct 4 ms 5760 KB Output is correct
70 Correct 4 ms 5760 KB Output is correct
71 Correct 4 ms 5760 KB Output is correct
72 Correct 4 ms 5760 KB Output is correct
73 Correct 4 ms 5760 KB Output is correct
74 Correct 4 ms 5760 KB Output is correct
75 Correct 4 ms 5760 KB Output is correct
76 Correct 4 ms 5760 KB Output is correct
77 Correct 4 ms 5760 KB Output is correct
78 Correct 4 ms 5760 KB Output is correct
79 Correct 5 ms 5760 KB Output is correct
80 Correct 4 ms 5760 KB Output is correct
81 Correct 3 ms 5760 KB Output is correct
82 Correct 4 ms 5760 KB Output is correct
83 Correct 3 ms 5760 KB Output is correct
84 Correct 4 ms 5760 KB Output is correct
85 Correct 4 ms 5760 KB Output is correct
86 Correct 4 ms 5760 KB Output is correct
87 Correct 4 ms 5760 KB Output is correct
88 Correct 7 ms 6272 KB Output is correct
89 Correct 10 ms 6468 KB Output is correct
90 Correct 12 ms 6724 KB Output is correct
91 Correct 51 ms 9456 KB Output is correct
92 Correct 108 ms 12908 KB Output is correct
93 Correct 268 ms 19864 KB Output is correct
94 Correct 286 ms 19816 KB Output is correct
95 Correct 264 ms 20004 KB Output is correct
96 Correct 263 ms 19944 KB Output is correct
97 Correct 259 ms 19948 KB Output is correct
98 Correct 246 ms 19944 KB Output is correct
99 Correct 235 ms 19816 KB Output is correct
100 Correct 266 ms 19944 KB Output is correct
101 Correct 280 ms 19944 KB Output is correct
102 Correct 223 ms 20072 KB Output is correct
103 Correct 269 ms 19816 KB Output is correct
104 Correct 257 ms 19944 KB Output is correct
105 Correct 194 ms 19944 KB Output is correct
106 Correct 212 ms 19304 KB Output is correct