답안 #144779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144779 2019-08-17T17:22:30 Z gmfabat Job Scheduling (IOI19_job) C++14
100 / 100
307 ms 15916 KB
#include <bits/stdc++.h>
#include "job.h"
#define ll long long
using namespace std;
const int N = 200005;

int a[N], fa[N], dd[N],sz[N]; ll w[N];

struct node {
    int id; ll son, mom;
    node (int _id = 0, ll _son = 0, ll _mom = 0) {id = _id, son = _son; mom = _mom; }
    bool operator < (const node &b) const {return son*b.mom < b.son*mom; }
};

priority_queue<node>Q;

int find(int o) {return ~fa[o] ? fa[o] = find(fa[o]) : o;}

ll scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d)
{
    int n=p.size();
    memset(fa, -1, sizeof(fa));

    for (int i = 1; i <= n; i++) {  //初始化index , 由1-N 而不是0- N-1, 其實也可不做 , 但下面要小改, 注意index
     a[i]=p[i-1]+1;
     w[i]=u[i-1];
     dd[i]=d[i-1];
    }

    for (int i = 1; i <= n; i++)
       if (find(a[i])^find(i)) fa[find(a[i])] = find(i);

    long long ans = 0; int loc = 0;
    for (int i = 1; i <= n; i++)  scanf("%lld", &w[i]);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &dd[i]);
        Q.push(node(i, w[i], dd[i])); //建堆
        sz[i] = dd[i];
        ans += w[i]*dd[i];
    }
    memset(fa, -1, sizeof(fa));
    while (!Q.empty()) {    // 每次合二個點合二為一, 消一個點和對應邊 , 消到堆為空為止
        node t = Q.top(); Q.pop();
        if (sz[t.id] != t.mom) continue;
        if (find(a[t.id]) == 0) {
            ans += w[t.id]*loc; fa[t.id] = 0; loc += sz[t.id];
        }else {
            int tmp = find(a[t.id]);
            ans += w[t.id]*sz[tmp], fa[t.id] = tmp;
            w[tmp] += w[t.id], sz[tmp] += sz[t.id];
            Q.push(node(tmp, w[tmp], sz[tmp]));
        }
    }
   return ans;
}

Compilation message

job.cpp: In function 'long long int scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:34:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++)  scanf("%lld", &w[i]);
                                   ~~~~~^~~~~~~~~~~~~~~
job.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &dd[i]);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 54 ms 5616 KB Output is correct
6 Correct 120 ms 9676 KB Output is correct
7 Correct 195 ms 13748 KB Output is correct
8 Correct 286 ms 15780 KB Output is correct
9 Correct 291 ms 15720 KB Output is correct
10 Correct 306 ms 15844 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 285 ms 15848 KB Output is correct
13 Correct 228 ms 15720 KB Output is correct
14 Correct 242 ms 15844 KB Output is correct
15 Correct 187 ms 15716 KB Output is correct
16 Correct 222 ms 15712 KB Output is correct
17 Correct 296 ms 15844 KB Output is correct
18 Correct 296 ms 15720 KB Output is correct
19 Correct 174 ms 15812 KB Output is correct
20 Correct 150 ms 15884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 175 ms 15820 KB Output is correct
5 Correct 170 ms 15892 KB Output is correct
6 Correct 167 ms 15736 KB Output is correct
7 Correct 194 ms 15688 KB Output is correct
8 Correct 208 ms 15716 KB Output is correct
9 Correct 168 ms 15720 KB Output is correct
10 Correct 175 ms 15716 KB Output is correct
11 Correct 173 ms 15808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 10 ms 2108 KB Output is correct
6 Correct 200 ms 15752 KB Output is correct
7 Correct 189 ms 15716 KB Output is correct
8 Correct 189 ms 15772 KB Output is correct
9 Correct 178 ms 15848 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 4 ms 1272 KB Output is correct
12 Correct 8 ms 2108 KB Output is correct
13 Correct 9 ms 2108 KB Output is correct
14 Correct 194 ms 15720 KB Output is correct
15 Correct 230 ms 15848 KB Output is correct
16 Correct 184 ms 15848 KB Output is correct
17 Correct 183 ms 15716 KB Output is correct
18 Correct 178 ms 15716 KB Output is correct
19 Correct 183 ms 15776 KB Output is correct
20 Correct 186 ms 15720 KB Output is correct
21 Correct 184 ms 15768 KB Output is correct
22 Correct 182 ms 15788 KB Output is correct
23 Correct 176 ms 15716 KB Output is correct
24 Correct 179 ms 15720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 286 ms 15784 KB Output is correct
3 Correct 292 ms 15792 KB Output is correct
4 Correct 307 ms 15716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1148 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 54 ms 5616 KB Output is correct
6 Correct 120 ms 9676 KB Output is correct
7 Correct 195 ms 13748 KB Output is correct
8 Correct 286 ms 15780 KB Output is correct
9 Correct 291 ms 15720 KB Output is correct
10 Correct 306 ms 15844 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 285 ms 15848 KB Output is correct
13 Correct 228 ms 15720 KB Output is correct
14 Correct 242 ms 15844 KB Output is correct
15 Correct 187 ms 15716 KB Output is correct
16 Correct 222 ms 15712 KB Output is correct
17 Correct 296 ms 15844 KB Output is correct
18 Correct 296 ms 15720 KB Output is correct
19 Correct 174 ms 15812 KB Output is correct
20 Correct 150 ms 15884 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 175 ms 15820 KB Output is correct
25 Correct 170 ms 15892 KB Output is correct
26 Correct 167 ms 15736 KB Output is correct
27 Correct 194 ms 15688 KB Output is correct
28 Correct 208 ms 15716 KB Output is correct
29 Correct 168 ms 15720 KB Output is correct
30 Correct 175 ms 15716 KB Output is correct
31 Correct 173 ms 15808 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 3 ms 1144 KB Output is correct
34 Correct 3 ms 1144 KB Output is correct
35 Correct 4 ms 1272 KB Output is correct
36 Correct 10 ms 2108 KB Output is correct
37 Correct 200 ms 15752 KB Output is correct
38 Correct 189 ms 15716 KB Output is correct
39 Correct 189 ms 15772 KB Output is correct
40 Correct 178 ms 15848 KB Output is correct
41 Correct 3 ms 1144 KB Output is correct
42 Correct 4 ms 1272 KB Output is correct
43 Correct 8 ms 2108 KB Output is correct
44 Correct 9 ms 2108 KB Output is correct
45 Correct 194 ms 15720 KB Output is correct
46 Correct 230 ms 15848 KB Output is correct
47 Correct 184 ms 15848 KB Output is correct
48 Correct 183 ms 15716 KB Output is correct
49 Correct 178 ms 15716 KB Output is correct
50 Correct 183 ms 15776 KB Output is correct
51 Correct 186 ms 15720 KB Output is correct
52 Correct 184 ms 15768 KB Output is correct
53 Correct 182 ms 15788 KB Output is correct
54 Correct 176 ms 15716 KB Output is correct
55 Correct 179 ms 15720 KB Output is correct
56 Correct 3 ms 1144 KB Output is correct
57 Correct 286 ms 15784 KB Output is correct
58 Correct 292 ms 15792 KB Output is correct
59 Correct 307 ms 15716 KB Output is correct
60 Correct 3 ms 1144 KB Output is correct
61 Correct 3 ms 1144 KB Output is correct
62 Correct 3 ms 1144 KB Output is correct
63 Correct 3 ms 1148 KB Output is correct
64 Correct 3 ms 1144 KB Output is correct
65 Correct 3 ms 1144 KB Output is correct
66 Correct 3 ms 1144 KB Output is correct
67 Correct 3 ms 1144 KB Output is correct
68 Correct 3 ms 1116 KB Output is correct
69 Correct 3 ms 1144 KB Output is correct
70 Correct 3 ms 1144 KB Output is correct
71 Correct 3 ms 1144 KB Output is correct
72 Correct 3 ms 1144 KB Output is correct
73 Correct 3 ms 1144 KB Output is correct
74 Correct 3 ms 1144 KB Output is correct
75 Correct 3 ms 1144 KB Output is correct
76 Correct 3 ms 1144 KB Output is correct
77 Correct 3 ms 1144 KB Output is correct
78 Correct 3 ms 1144 KB Output is correct
79 Correct 3 ms 1144 KB Output is correct
80 Correct 3 ms 1144 KB Output is correct
81 Correct 3 ms 1144 KB Output is correct
82 Correct 3 ms 1144 KB Output is correct
83 Correct 3 ms 1144 KB Output is correct
84 Correct 3 ms 1144 KB Output is correct
85 Correct 3 ms 1144 KB Output is correct
86 Correct 3 ms 1144 KB Output is correct
87 Correct 3 ms 1144 KB Output is correct
88 Correct 7 ms 1660 KB Output is correct
89 Correct 9 ms 1784 KB Output is correct
90 Correct 11 ms 2108 KB Output is correct
91 Correct 53 ms 4848 KB Output is correct
92 Correct 114 ms 8560 KB Output is correct
93 Correct 259 ms 15768 KB Output is correct
94 Correct 265 ms 15848 KB Output is correct
95 Correct 267 ms 15720 KB Output is correct
96 Correct 279 ms 15860 KB Output is correct
97 Correct 259 ms 15848 KB Output is correct
98 Correct 248 ms 15716 KB Output is correct
99 Correct 235 ms 15720 KB Output is correct
100 Correct 275 ms 15764 KB Output is correct
101 Correct 274 ms 15708 KB Output is correct
102 Correct 207 ms 15792 KB Output is correct
103 Correct 260 ms 15756 KB Output is correct
104 Correct 266 ms 15848 KB Output is correct
105 Correct 200 ms 15844 KB Output is correct
106 Correct 188 ms 15916 KB Output is correct