답안 #208637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208637 2020-03-12T00:22:07 Z eriksuenderhauf Job Scheduling (IOI19_job) C++14
100 / 100
204 ms 31216 KB
//#pragma GCC optimize("O3")
#include "job.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
int U[MAXN], D[MAXN];

bool operator<(pii lhs, pii rhs) {
	return (ll)lhs.fi * (ll)rhs.se < (ll)rhs.fi * (ll)lhs.se;
}

struct cmp {
	bool operator()(int lhs, int rhs) {
		return mp(U[lhs],D[lhs]) < mp(U[rhs],D[rhs]);
	}
};

priority_queue<int,vi,cmp> pq[MAXN];
int nx[MAXN], idx[MAXN];
vi ans;

void merge(int u) {
	while (!pq[u].empty()) {
		int v = pq[u].top();
		if (mp(U[v], D[v]) < mp(U[u], D[u]))
			return;
		pq[u].pop();
		nx[idx[u]] = v;
		idx[u] = idx[v];
		U[u] += U[v];
		D[u] += D[v];
		if (pq[u].size() < pq[v].size())
			swap(pq[u], pq[v]);
		while (!pq[v].empty()) {
			pq[u].push(pq[v].top());
			pq[v].pop();
		}
	}
}

void dfs(int u) {
	ans.pb(u);
	while (!pq[u].empty()) {
		int v = pq[u].top(); pq[u].pop();
		dfs(v);
	}
}

ll scheduling_cost(vi p, vi u, vi d) {
	int n = p.size();
	for (int i = 0; i < n; i++) {
		tie(idx[i],nx[i]) = mp(i,-1);
		tie(U[i],D[i]) = mp(u[i], d[i]);
	}
	for (int i = n-1; i > 0; i--) {
		merge(i);
		pq[p[i]].push(i);
	}
	merge(0);
	dfs(0);
	sort(ans.begin(), ans.end(), [](int lhs, int rhs) {
		return mp(U[lhs],D[lhs]) < mp(U[rhs],D[rhs]);
	});
	ll sm = 0, ret = 0;
	for (int i = ans.size()-1; i >= 0; i--) {
		for (int j = ans[i]; j != -1; j = nx[j]) {
			sm += d[j];
			ret += sm * u[j];
		}
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 9 ms 6648 KB Output is correct
5 Correct 36 ms 11000 KB Output is correct
6 Correct 64 ms 15224 KB Output is correct
7 Correct 92 ms 19448 KB Output is correct
8 Correct 119 ms 23836 KB Output is correct
9 Correct 118 ms 23832 KB Output is correct
10 Correct 120 ms 23800 KB Output is correct
11 Correct 8 ms 6652 KB Output is correct
12 Correct 124 ms 23928 KB Output is correct
13 Correct 117 ms 23800 KB Output is correct
14 Correct 120 ms 23928 KB Output is correct
15 Correct 118 ms 24056 KB Output is correct
16 Correct 118 ms 24056 KB Output is correct
17 Correct 116 ms 23800 KB Output is correct
18 Correct 116 ms 24056 KB Output is correct
19 Correct 113 ms 23928 KB Output is correct
20 Correct 130 ms 31216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6648 KB Output is correct
2 Correct 9 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 192 ms 18548 KB Output is correct
5 Correct 197 ms 18540 KB Output is correct
6 Correct 190 ms 18540 KB Output is correct
7 Correct 185 ms 18540 KB Output is correct
8 Correct 197 ms 18544 KB Output is correct
9 Correct 190 ms 18540 KB Output is correct
10 Correct 192 ms 18544 KB Output is correct
11 Correct 195 ms 18540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6652 KB Output is correct
4 Correct 9 ms 6648 KB Output is correct
5 Correct 15 ms 7288 KB Output is correct
6 Correct 198 ms 19180 KB Output is correct
7 Correct 198 ms 19052 KB Output is correct
8 Correct 201 ms 19052 KB Output is correct
9 Correct 201 ms 19180 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 10 ms 6648 KB Output is correct
12 Correct 14 ms 7160 KB Output is correct
13 Correct 15 ms 7160 KB Output is correct
14 Correct 202 ms 19180 KB Output is correct
15 Correct 194 ms 19052 KB Output is correct
16 Correct 203 ms 19052 KB Output is correct
17 Correct 197 ms 19052 KB Output is correct
18 Correct 197 ms 19052 KB Output is correct
19 Correct 196 ms 19052 KB Output is correct
20 Correct 200 ms 19052 KB Output is correct
21 Correct 204 ms 19052 KB Output is correct
22 Correct 196 ms 19052 KB Output is correct
23 Correct 195 ms 19052 KB Output is correct
24 Correct 201 ms 19052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6648 KB Output is correct
2 Correct 116 ms 23928 KB Output is correct
3 Correct 120 ms 23868 KB Output is correct
4 Correct 119 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 9 ms 6580 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 9 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 8 ms 6648 KB Output is correct
9 Correct 9 ms 6648 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 8 ms 6648 KB Output is correct
13 Correct 8 ms 6648 KB Output is correct
14 Correct 8 ms 6648 KB Output is correct
15 Correct 8 ms 6648 KB Output is correct
16 Correct 8 ms 6648 KB Output is correct
17 Correct 9 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 9 ms 6648 KB Output is correct
5 Correct 36 ms 11000 KB Output is correct
6 Correct 64 ms 15224 KB Output is correct
7 Correct 92 ms 19448 KB Output is correct
8 Correct 119 ms 23836 KB Output is correct
9 Correct 118 ms 23832 KB Output is correct
10 Correct 120 ms 23800 KB Output is correct
11 Correct 8 ms 6652 KB Output is correct
12 Correct 124 ms 23928 KB Output is correct
13 Correct 117 ms 23800 KB Output is correct
14 Correct 120 ms 23928 KB Output is correct
15 Correct 118 ms 24056 KB Output is correct
16 Correct 118 ms 24056 KB Output is correct
17 Correct 116 ms 23800 KB Output is correct
18 Correct 116 ms 24056 KB Output is correct
19 Correct 113 ms 23928 KB Output is correct
20 Correct 130 ms 31216 KB Output is correct
21 Correct 9 ms 6648 KB Output is correct
22 Correct 9 ms 6648 KB Output is correct
23 Correct 8 ms 6648 KB Output is correct
24 Correct 192 ms 18548 KB Output is correct
25 Correct 197 ms 18540 KB Output is correct
26 Correct 190 ms 18540 KB Output is correct
27 Correct 185 ms 18540 KB Output is correct
28 Correct 197 ms 18544 KB Output is correct
29 Correct 190 ms 18540 KB Output is correct
30 Correct 192 ms 18544 KB Output is correct
31 Correct 195 ms 18540 KB Output is correct
32 Correct 9 ms 6648 KB Output is correct
33 Correct 8 ms 6648 KB Output is correct
34 Correct 8 ms 6652 KB Output is correct
35 Correct 9 ms 6648 KB Output is correct
36 Correct 15 ms 7288 KB Output is correct
37 Correct 198 ms 19180 KB Output is correct
38 Correct 198 ms 19052 KB Output is correct
39 Correct 201 ms 19052 KB Output is correct
40 Correct 201 ms 19180 KB Output is correct
41 Correct 8 ms 6648 KB Output is correct
42 Correct 10 ms 6648 KB Output is correct
43 Correct 14 ms 7160 KB Output is correct
44 Correct 15 ms 7160 KB Output is correct
45 Correct 202 ms 19180 KB Output is correct
46 Correct 194 ms 19052 KB Output is correct
47 Correct 203 ms 19052 KB Output is correct
48 Correct 197 ms 19052 KB Output is correct
49 Correct 197 ms 19052 KB Output is correct
50 Correct 196 ms 19052 KB Output is correct
51 Correct 200 ms 19052 KB Output is correct
52 Correct 204 ms 19052 KB Output is correct
53 Correct 196 ms 19052 KB Output is correct
54 Correct 195 ms 19052 KB Output is correct
55 Correct 201 ms 19052 KB Output is correct
56 Correct 9 ms 6648 KB Output is correct
57 Correct 116 ms 23928 KB Output is correct
58 Correct 120 ms 23868 KB Output is correct
59 Correct 119 ms 23800 KB Output is correct
60 Correct 8 ms 6648 KB Output is correct
61 Correct 9 ms 6580 KB Output is correct
62 Correct 8 ms 6648 KB Output is correct
63 Correct 9 ms 6648 KB Output is correct
64 Correct 8 ms 6648 KB Output is correct
65 Correct 8 ms 6648 KB Output is correct
66 Correct 8 ms 6648 KB Output is correct
67 Correct 8 ms 6648 KB Output is correct
68 Correct 9 ms 6648 KB Output is correct
69 Correct 8 ms 6648 KB Output is correct
70 Correct 8 ms 6648 KB Output is correct
71 Correct 8 ms 6648 KB Output is correct
72 Correct 8 ms 6648 KB Output is correct
73 Correct 8 ms 6648 KB Output is correct
74 Correct 8 ms 6648 KB Output is correct
75 Correct 8 ms 6648 KB Output is correct
76 Correct 9 ms 6648 KB Output is correct
77 Correct 9 ms 6648 KB Output is correct
78 Correct 9 ms 6520 KB Output is correct
79 Correct 8 ms 6648 KB Output is correct
80 Correct 8 ms 6648 KB Output is correct
81 Correct 8 ms 6648 KB Output is correct
82 Correct 9 ms 6648 KB Output is correct
83 Correct 9 ms 6672 KB Output is correct
84 Correct 9 ms 6636 KB Output is correct
85 Correct 9 ms 6652 KB Output is correct
86 Correct 8 ms 6648 KB Output is correct
87 Correct 8 ms 6648 KB Output is correct
88 Correct 12 ms 7032 KB Output is correct
89 Correct 16 ms 7164 KB Output is correct
90 Correct 15 ms 7288 KB Output is correct
91 Correct 46 ms 10488 KB Output is correct
92 Correct 89 ms 14200 KB Output is correct
93 Correct 198 ms 21752 KB Output is correct
94 Correct 197 ms 21880 KB Output is correct
95 Correct 202 ms 22008 KB Output is correct
96 Correct 195 ms 21752 KB Output is correct
97 Correct 179 ms 21108 KB Output is correct
98 Correct 181 ms 22472 KB Output is correct
99 Correct 177 ms 21112 KB Output is correct
100 Correct 194 ms 21876 KB Output is correct
101 Correct 200 ms 22644 KB Output is correct
102 Correct 195 ms 22000 KB Output is correct
103 Correct 185 ms 21368 KB Output is correct
104 Correct 161 ms 22008 KB Output is correct
105 Correct 140 ms 22136 KB Output is correct
106 Correct 170 ms 19312 KB Output is correct