#include "job.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
vector<pair<pair<int,int>,int>> v;
vector<int> V;
vector<vector<int>> vv;
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
return a.F.F * b.F.S < a.F.S * b.F.F;
}
long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {//d=t;
int n=p.size();
int head;
pair<pair<int,int>,int> P;
v.assign(n,P);
vv.assign(n,V);
set<int> s;
int ans=0;
int k=0;
for(int i=0;i<n;i++){
if(p[i]==-1){
head=i;
continue;
}vv[p[i]].push_back(i);
s.insert(p[i]);
v[k].F.F=u[i];
v[k].F.S=d[i];
v[k].S=i;
k++;
}int result;
if(s.size()==n-1){
vector<int> ans;
while(vv[head].size()!=0){
ans.push_back(head);
head=vv[head][0];
}ans.push_back(head);
int t=0;
result=0;
for(int i=0;i<n;i++){
t+=d[ans[i]];
result+=u[ans[i]]*t;
}
}if(s.size()==1){
int t=u[head];
result=t*d[head];
sort(v.begin(),v.end(),cmp);
for(auto i : v){
t+=i.F.F;
result+=t*i.F.S;
}
}
return result;
}
Compilation message
job.cpp: In function 'long long int scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size()==n-1){
~~~~~~~~^~~~~
job.cpp:19:9: warning: unused variable 'ans' [-Wunused-variable]
int ans=0;
^~~
job.cpp:55:9: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
return result;
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |