답안 #802882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802882 2023-08-02T15:31:38 Z Ahmed57 Job Scheduling (IOI19_job) C++17
42 / 100
147 ms 31524 KB
#include<bits/stdc++.h>

using namespace std;
long long D[200001],U[200001];
bool comp(int a,int b){
     return (D[a]*U[b])<(D[b]*U[a]);
}
struct cmp {
	bool operator()(const int &a, const int &b) {
		return (D[a]*U[b])>(D[b]*U[a]);
	}
};
priority_queue<int,vector<int>,cmp> adj[200001];
vector<int> ans;
void dfs(int u) {
	ans.push_back(u);
	for(;adj[u].size();adj[u].pop())dfs(adj[u].top());
}
long long scheduling_cost(vector<int> p,vector<int> u,vector<int> d){
    int n = p.size();
    long long nxt[n],nick_name[n];
    U[0] = u[0] , D[0] = d[0];
    nxt[0] = -1;nick_name[0] = 0;
    for(int i = 1;i<n;i++){
        nick_name[i] = i;
        nxt[i] = -1;
        U[i] = u[i];
        D[i] = d[i];
        adj[p[i]].push(i);
    }
    for(int i = n-1;i>=0;i--){
        while(adj[i].size()){
            int x = -1;
            if(comp(adj[i].top(),i)){
                x = adj[i].top();
            }else break;
            adj[i].pop();
            nxt[nick_name[i]] = x;
            nick_name[i] = nick_name[x];
            D[i]+=D[x];
            U[i]+=U[x];
            if(adj[i].size()<adj[x].size())swap(adj[i],adj[x]);
            while(adj[x].size()){
                adj[i].push(adj[x].top());adj[x].pop();
            }
        }
    }
    dfs(0);
    sort(ans.begin(),ans.end(),comp);
    long long all = 0 , cur = 0;
    for(int i = 0;i<ans.size();i++){
        int lol = ans[i];
        while(lol!=-1){
        cur+=d[lol];
        all+=cur*u[lol];
        lol = nxt[lol];
        }
    }
    return all;
}/*
int main(){
    cout<<scheduling_cost({-1,0,0},{5,2,5},{3,4,1});
}*/

Compilation message

job.cpp: In function 'long long int scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0;i<ans.size();i++){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6568 KB Output is correct
3 Correct 4 ms 6568 KB Output is correct
4 Correct 4 ms 6648 KB Output is correct
5 Correct 21 ms 11384 KB Output is correct
6 Correct 41 ms 15664 KB Output is correct
7 Correct 46 ms 19920 KB Output is correct
8 Correct 73 ms 24268 KB Output is correct
9 Correct 59 ms 24268 KB Output is correct
10 Correct 59 ms 24292 KB Output is correct
11 Correct 3 ms 6568 KB Output is correct
12 Correct 61 ms 24268 KB Output is correct
13 Correct 75 ms 24240 KB Output is correct
14 Correct 73 ms 24232 KB Output is correct
15 Correct 61 ms 24168 KB Output is correct
16 Correct 65 ms 24392 KB Output is correct
17 Correct 59 ms 24240 KB Output is correct
18 Correct 58 ms 24304 KB Output is correct
19 Correct 66 ms 24224 KB Output is correct
20 Correct 87 ms 31524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 126 ms 20160 KB Output is correct
5 Correct 124 ms 20240 KB Output is correct
6 Correct 132 ms 20144 KB Output is correct
7 Correct 130 ms 20140 KB Output is correct
8 Correct 125 ms 20160 KB Output is correct
9 Correct 123 ms 20228 KB Output is correct
10 Correct 123 ms 20156 KB Output is correct
11 Correct 147 ms 20192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6576 KB Output is correct
5 Correct 7 ms 7392 KB Output is correct
6 Correct 129 ms 20224 KB Output is correct
7 Correct 128 ms 20244 KB Output is correct
8 Correct 133 ms 20288 KB Output is correct
9 Correct 127 ms 20144 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 6 ms 7252 KB Output is correct
13 Correct 7 ms 7352 KB Output is correct
14 Correct 125 ms 20212 KB Output is correct
15 Correct 141 ms 20216 KB Output is correct
16 Correct 131 ms 20184 KB Output is correct
17 Correct 128 ms 20216 KB Output is correct
18 Correct 127 ms 20172 KB Output is correct
19 Correct 125 ms 20160 KB Output is correct
20 Correct 125 ms 20200 KB Output is correct
21 Correct 134 ms 20188 KB Output is correct
22 Correct 125 ms 20204 KB Output is correct
23 Correct 124 ms 20176 KB Output is correct
24 Correct 147 ms 20180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 57 ms 24124 KB Output is correct
3 Correct 58 ms 25284 KB Output is correct
4 Correct 65 ms 25248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6568 KB Output is correct
2 Incorrect 3 ms 6572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6568 KB Output is correct
3 Correct 4 ms 6568 KB Output is correct
4 Correct 4 ms 6648 KB Output is correct
5 Correct 21 ms 11384 KB Output is correct
6 Correct 41 ms 15664 KB Output is correct
7 Correct 46 ms 19920 KB Output is correct
8 Correct 73 ms 24268 KB Output is correct
9 Correct 59 ms 24268 KB Output is correct
10 Correct 59 ms 24292 KB Output is correct
11 Correct 3 ms 6568 KB Output is correct
12 Correct 61 ms 24268 KB Output is correct
13 Correct 75 ms 24240 KB Output is correct
14 Correct 73 ms 24232 KB Output is correct
15 Correct 61 ms 24168 KB Output is correct
16 Correct 65 ms 24392 KB Output is correct
17 Correct 59 ms 24240 KB Output is correct
18 Correct 58 ms 24304 KB Output is correct
19 Correct 66 ms 24224 KB Output is correct
20 Correct 87 ms 31524 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 126 ms 20160 KB Output is correct
25 Correct 124 ms 20240 KB Output is correct
26 Correct 132 ms 20144 KB Output is correct
27 Correct 130 ms 20140 KB Output is correct
28 Correct 125 ms 20160 KB Output is correct
29 Correct 123 ms 20228 KB Output is correct
30 Correct 123 ms 20156 KB Output is correct
31 Correct 147 ms 20192 KB Output is correct
32 Correct 4 ms 6484 KB Output is correct
33 Correct 4 ms 6484 KB Output is correct
34 Correct 3 ms 6484 KB Output is correct
35 Correct 3 ms 6576 KB Output is correct
36 Correct 7 ms 7392 KB Output is correct
37 Correct 129 ms 20224 KB Output is correct
38 Correct 128 ms 20244 KB Output is correct
39 Correct 133 ms 20288 KB Output is correct
40 Correct 127 ms 20144 KB Output is correct
41 Correct 3 ms 6484 KB Output is correct
42 Correct 4 ms 6612 KB Output is correct
43 Correct 6 ms 7252 KB Output is correct
44 Correct 7 ms 7352 KB Output is correct
45 Correct 125 ms 20212 KB Output is correct
46 Correct 141 ms 20216 KB Output is correct
47 Correct 131 ms 20184 KB Output is correct
48 Correct 128 ms 20216 KB Output is correct
49 Correct 127 ms 20172 KB Output is correct
50 Correct 125 ms 20160 KB Output is correct
51 Correct 125 ms 20200 KB Output is correct
52 Correct 134 ms 20188 KB Output is correct
53 Correct 125 ms 20204 KB Output is correct
54 Correct 124 ms 20176 KB Output is correct
55 Correct 147 ms 20180 KB Output is correct
56 Correct 3 ms 6484 KB Output is correct
57 Correct 57 ms 24124 KB Output is correct
58 Correct 58 ms 25284 KB Output is correct
59 Correct 65 ms 25248 KB Output is correct
60 Correct 3 ms 6568 KB Output is correct
61 Incorrect 3 ms 6572 KB Output isn't correct
62 Halted 0 ms 0 KB -