답안 #245799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245799 2020-07-07T12:35:57 Z quocnguyen1012 Job Scheduling (IOI19_job) C++14
100 / 100
827 ms 20856 KB
#ifndef LOCAL
#include "job.h"
#endif // LOCAL
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e5 + 5;

int cost[maxn], tim[maxn];
int N;
int lab[maxn], mark[maxn];
ll t = 0, res;

int finds(int u)
{
  if(lab[u] == u) return u;
  return lab[u] = finds(lab[u]);
}

struct cmp
{
  bool operator ()(int a, int b) const
  {
    if(1ll * cost[a] * tim[b] != 1ll * cost[b] * tim[a]) return 1ll * cost[a] * tim[b] > 1ll * cost[b] * tim[a];
    return a < b;
  }
};
set<int, cmp> se;

ll scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d)
{
  N = p.size();
  for(int i = 0; i < N; ++i){
    tim[i] = d[i];
    cost[i] = u[i];
    lab[i] = i;
  }
  for(int i = 0; i < N; ++i)
    se.insert(i);
  for(int i = 0; i < N; ++i){
    int now = *se.begin();
    se.erase(now);
    //cerr << now << '\n';
    if(p[now] == -1 || mark[finds(p[now])]){
      t += tim[now];
      res += 1ll * cost[now] * t;
      mark[now] = 1;
      continue;
    }
    int top = finds(p[now]);
    se.erase(top);
    res -= 1ll * cost[top] * tim[now];
    cost[top] += cost[now];
    tim[top] += tim[now];
    se.insert(top);
    lab[now] = top;
  }
  return res;
}

#ifdef LOCAL
signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  int n; cin >> n;
  vector<int> p(n), u(n), d(n);
  for(auto & it : p) cin >> it;
  for(auto & it : u) cin >> it;
  for(auto & it : d) cin >> it;
  cout << scheduling_cost(p, u, d);
}
#endif // LOCAL
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 91 ms 4492 KB Output is correct
6 Correct 225 ms 8568 KB Output is correct
7 Correct 563 ms 12816 KB Output is correct
8 Correct 683 ms 16888 KB Output is correct
9 Correct 801 ms 16888 KB Output is correct
10 Correct 727 ms 16888 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 640 ms 17016 KB Output is correct
13 Correct 370 ms 17016 KB Output is correct
14 Correct 378 ms 17528 KB Output is correct
15 Correct 230 ms 16760 KB Output is correct
16 Correct 269 ms 17528 KB Output is correct
17 Correct 726 ms 16828 KB Output is correct
18 Correct 739 ms 16888 KB Output is correct
19 Correct 180 ms 16760 KB Output is correct
20 Correct 166 ms 17528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 293 ms 19324 KB Output is correct
5 Correct 285 ms 19360 KB Output is correct
6 Correct 276 ms 19320 KB Output is correct
7 Correct 271 ms 19448 KB Output is correct
8 Correct 309 ms 19364 KB Output is correct
9 Correct 374 ms 19296 KB Output is correct
10 Correct 292 ms 19424 KB Output is correct
11 Correct 276 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 12 ms 1152 KB Output is correct
6 Correct 284 ms 19832 KB Output is correct
7 Correct 390 ms 19960 KB Output is correct
8 Correct 273 ms 19960 KB Output is correct
9 Correct 299 ms 20120 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 13 ms 1280 KB Output is correct
14 Correct 287 ms 19964 KB Output is correct
15 Correct 270 ms 19832 KB Output is correct
16 Correct 272 ms 19960 KB Output is correct
17 Correct 278 ms 19948 KB Output is correct
18 Correct 271 ms 19880 KB Output is correct
19 Correct 270 ms 19964 KB Output is correct
20 Correct 275 ms 19960 KB Output is correct
21 Correct 326 ms 20016 KB Output is correct
22 Correct 298 ms 19832 KB Output is correct
23 Correct 301 ms 19960 KB Output is correct
24 Correct 271 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 764 ms 16912 KB Output is correct
3 Correct 827 ms 16888 KB Output is correct
4 Correct 741 ms 16892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 91 ms 4492 KB Output is correct
6 Correct 225 ms 8568 KB Output is correct
7 Correct 563 ms 12816 KB Output is correct
8 Correct 683 ms 16888 KB Output is correct
9 Correct 801 ms 16888 KB Output is correct
10 Correct 727 ms 16888 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 640 ms 17016 KB Output is correct
13 Correct 370 ms 17016 KB Output is correct
14 Correct 378 ms 17528 KB Output is correct
15 Correct 230 ms 16760 KB Output is correct
16 Correct 269 ms 17528 KB Output is correct
17 Correct 726 ms 16828 KB Output is correct
18 Correct 739 ms 16888 KB Output is correct
19 Correct 180 ms 16760 KB Output is correct
20 Correct 166 ms 17528 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 293 ms 19324 KB Output is correct
25 Correct 285 ms 19360 KB Output is correct
26 Correct 276 ms 19320 KB Output is correct
27 Correct 271 ms 19448 KB Output is correct
28 Correct 309 ms 19364 KB Output is correct
29 Correct 374 ms 19296 KB Output is correct
30 Correct 292 ms 19424 KB Output is correct
31 Correct 276 ms 19320 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 12 ms 1152 KB Output is correct
37 Correct 284 ms 19832 KB Output is correct
38 Correct 390 ms 19960 KB Output is correct
39 Correct 273 ms 19960 KB Output is correct
40 Correct 299 ms 20120 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 6 ms 512 KB Output is correct
43 Correct 11 ms 1152 KB Output is correct
44 Correct 13 ms 1280 KB Output is correct
45 Correct 287 ms 19964 KB Output is correct
46 Correct 270 ms 19832 KB Output is correct
47 Correct 272 ms 19960 KB Output is correct
48 Correct 278 ms 19948 KB Output is correct
49 Correct 271 ms 19880 KB Output is correct
50 Correct 270 ms 19964 KB Output is correct
51 Correct 275 ms 19960 KB Output is correct
52 Correct 326 ms 20016 KB Output is correct
53 Correct 298 ms 19832 KB Output is correct
54 Correct 301 ms 19960 KB Output is correct
55 Correct 271 ms 19960 KB Output is correct
56 Correct 5 ms 256 KB Output is correct
57 Correct 764 ms 16912 KB Output is correct
58 Correct 827 ms 16888 KB Output is correct
59 Correct 741 ms 16892 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 5 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 5 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 5 ms 384 KB Output is correct
73 Correct 5 ms 384 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 5 ms 384 KB Output is correct
80 Correct 5 ms 384 KB Output is correct
81 Correct 5 ms 384 KB Output is correct
82 Correct 5 ms 512 KB Output is correct
83 Correct 5 ms 384 KB Output is correct
84 Correct 5 ms 384 KB Output is correct
85 Correct 5 ms 384 KB Output is correct
86 Correct 5 ms 384 KB Output is correct
87 Correct 5 ms 384 KB Output is correct
88 Correct 10 ms 768 KB Output is correct
89 Correct 13 ms 1152 KB Output is correct
90 Correct 16 ms 1408 KB Output is correct
91 Correct 76 ms 5368 KB Output is correct
92 Correct 248 ms 10488 KB Output is correct
93 Correct 554 ms 20768 KB Output is correct
94 Correct 602 ms 20600 KB Output is correct
95 Correct 542 ms 20600 KB Output is correct
96 Correct 723 ms 20748 KB Output is correct
97 Correct 609 ms 20728 KB Output is correct
98 Correct 460 ms 20776 KB Output is correct
99 Correct 416 ms 20572 KB Output is correct
100 Correct 544 ms 20600 KB Output is correct
101 Correct 611 ms 20728 KB Output is correct
102 Correct 344 ms 20856 KB Output is correct
103 Correct 677 ms 20756 KB Output is correct
104 Correct 547 ms 20660 KB Output is correct
105 Correct 257 ms 20816 KB Output is correct
106 Correct 368 ms 20088 KB Output is correct