Submission #473981

# Submission time Handle Problem Language Result Execution time Memory
473981 2021-09-16T14:04:52 Z Killer2501 Job Scheduling (IOI19_job) C++14
100 / 100
325 ms 24228 KB
#include "job.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pld pair<ld, ll>
#define fi first
#define se second
using namespace std;
const int N = 4e5+5;
const int M = 205;
const ld mod = 1e9;
const ld base = 1e-7;
ll n, m, k, ans, lab[N], cost[N], tim[N], id[N], par[N], t;
ld d[N];
struct node
{
	bool operator ()(ll x, ll y) const
	{
		if(cost[x] * tim[y] == cost[y] * tim[x])return x < y;
		cost[x] * tim[y] > cost[y] * tim[x];
	}
};
ll findp(ll u)
{
	return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
priority_queue<pld> pq;
ll scheduling_cost(vector<int> p, vector<int> c, vector<int> di)
{
	n = p.size();
	fill_n(lab, n+1, -1);
	for(int i = 1; i <= n; i ++)
	{
		par[i] = p[i-1]+1;
		cost[i] = c[i-1];
		tim[i] = di[i-1];
		d[i] = mod * cost[i] / tim[i];
		pq.push({d[i], -i});
		//cout << cost[i]  <<" "<<tim[i]<<" ";
	}
	while(!pq.empty())
	{
		pld u = pq.top();
		pq.pop();
        u.se = -u.se;
		if(abs(d[u.se]-u.fi) > base)continue;
		//cout << (ld)u.fi <<" ";
		if(!par[u.se] || d[findp(par[u.se])] == -1)
		{
 
			t += tim[u.se];
			ans += t * cost[u.se];
			d[u.se] = -1;
		}
		else
		{
			ll v = findp(par[u.se]);
			ans -= cost[v] * tim[u.se];
			cost[v] += cost[u.se];
			tim[v] += tim[u.se];
			lab[u.se] = v;
			d[v] = mod * cost[v] / tim[v];
			pq.push({d[v], -v});
		}
 
	}
	return ans;
}

Compilation message

job.cpp: In member function 'bool node::operator()(long long int, long long int) const':
job.cpp:22:20: warning: statement has no effect [-Wunused-value]
   22 |   cost[x] * tim[y] > cost[y] * tim[x];
      |   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 60 ms 6332 KB Output is correct
6 Correct 131 ms 12064 KB Output is correct
7 Correct 221 ms 20784 KB Output is correct
8 Correct 311 ms 23960 KB Output is correct
9 Correct 303 ms 24084 KB Output is correct
10 Correct 310 ms 23956 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 312 ms 24012 KB Output is correct
13 Correct 230 ms 23960 KB Output is correct
14 Correct 272 ms 24004 KB Output is correct
15 Correct 205 ms 24228 KB Output is correct
16 Correct 231 ms 23996 KB Output is correct
17 Correct 324 ms 23964 KB Output is correct
18 Correct 288 ms 24008 KB Output is correct
19 Correct 191 ms 24092 KB Output is correct
20 Correct 154 ms 24128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 180 ms 22544 KB Output is correct
5 Correct 194 ms 22556 KB Output is correct
6 Correct 176 ms 22568 KB Output is correct
7 Correct 188 ms 22544 KB Output is correct
8 Correct 170 ms 22580 KB Output is correct
9 Correct 178 ms 22572 KB Output is correct
10 Correct 173 ms 22572 KB Output is correct
11 Correct 174 ms 22548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 10 ms 1716 KB Output is correct
6 Correct 178 ms 23168 KB Output is correct
7 Correct 170 ms 23068 KB Output is correct
8 Correct 175 ms 23120 KB Output is correct
9 Correct 176 ms 23080 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 6 ms 1608 KB Output is correct
13 Correct 7 ms 1736 KB Output is correct
14 Correct 171 ms 23128 KB Output is correct
15 Correct 182 ms 23068 KB Output is correct
16 Correct 174 ms 23064 KB Output is correct
17 Correct 177 ms 23132 KB Output is correct
18 Correct 181 ms 23132 KB Output is correct
19 Correct 187 ms 23136 KB Output is correct
20 Correct 191 ms 23084 KB Output is correct
21 Correct 179 ms 23136 KB Output is correct
22 Correct 175 ms 23132 KB Output is correct
23 Correct 175 ms 23140 KB Output is correct
24 Correct 173 ms 23084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 302 ms 24008 KB Output is correct
3 Correct 322 ms 24120 KB Output is correct
4 Correct 325 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 60 ms 6332 KB Output is correct
6 Correct 131 ms 12064 KB Output is correct
7 Correct 221 ms 20784 KB Output is correct
8 Correct 311 ms 23960 KB Output is correct
9 Correct 303 ms 24084 KB Output is correct
10 Correct 310 ms 23956 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 312 ms 24012 KB Output is correct
13 Correct 230 ms 23960 KB Output is correct
14 Correct 272 ms 24004 KB Output is correct
15 Correct 205 ms 24228 KB Output is correct
16 Correct 231 ms 23996 KB Output is correct
17 Correct 324 ms 23964 KB Output is correct
18 Correct 288 ms 24008 KB Output is correct
19 Correct 191 ms 24092 KB Output is correct
20 Correct 154 ms 24128 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 180 ms 22544 KB Output is correct
25 Correct 194 ms 22556 KB Output is correct
26 Correct 176 ms 22568 KB Output is correct
27 Correct 188 ms 22544 KB Output is correct
28 Correct 170 ms 22580 KB Output is correct
29 Correct 178 ms 22572 KB Output is correct
30 Correct 173 ms 22572 KB Output is correct
31 Correct 174 ms 22548 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 10 ms 1716 KB Output is correct
37 Correct 178 ms 23168 KB Output is correct
38 Correct 170 ms 23068 KB Output is correct
39 Correct 175 ms 23120 KB Output is correct
40 Correct 176 ms 23080 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 6 ms 1608 KB Output is correct
44 Correct 7 ms 1736 KB Output is correct
45 Correct 171 ms 23128 KB Output is correct
46 Correct 182 ms 23068 KB Output is correct
47 Correct 174 ms 23064 KB Output is correct
48 Correct 177 ms 23132 KB Output is correct
49 Correct 181 ms 23132 KB Output is correct
50 Correct 187 ms 23136 KB Output is correct
51 Correct 191 ms 23084 KB Output is correct
52 Correct 179 ms 23136 KB Output is correct
53 Correct 175 ms 23132 KB Output is correct
54 Correct 175 ms 23140 KB Output is correct
55 Correct 173 ms 23084 KB Output is correct
56 Correct 0 ms 300 KB Output is correct
57 Correct 302 ms 24008 KB Output is correct
58 Correct 322 ms 24120 KB Output is correct
59 Correct 325 ms 24020 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 308 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 1 ms 308 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 1 ms 304 KB Output is correct
76 Correct 1 ms 332 KB Output is correct
77 Correct 1 ms 332 KB Output is correct
78 Correct 0 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 1 ms 332 KB Output is correct
81 Correct 1 ms 332 KB Output is correct
82 Correct 1 ms 296 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 0 ms 332 KB Output is correct
85 Correct 1 ms 332 KB Output is correct
86 Correct 0 ms 332 KB Output is correct
87 Correct 1 ms 332 KB Output is correct
88 Correct 5 ms 1100 KB Output is correct
89 Correct 7 ms 1352 KB Output is correct
90 Correct 9 ms 1720 KB Output is correct
91 Correct 46 ms 6204 KB Output is correct
92 Correct 124 ms 12104 KB Output is correct
93 Correct 323 ms 23836 KB Output is correct
94 Correct 255 ms 23856 KB Output is correct
95 Correct 267 ms 23968 KB Output is correct
96 Correct 289 ms 23904 KB Output is correct
97 Correct 283 ms 23832 KB Output is correct
98 Correct 260 ms 23996 KB Output is correct
99 Correct 226 ms 23788 KB Output is correct
100 Correct 274 ms 23900 KB Output is correct
101 Correct 297 ms 24092 KB Output is correct
102 Correct 193 ms 23964 KB Output is correct
103 Correct 282 ms 24028 KB Output is correct
104 Correct 308 ms 23964 KB Output is correct
105 Correct 204 ms 23980 KB Output is correct
106 Correct 184 ms 23460 KB Output is correct