Submission #211079

# Submission time Handle Problem Language Result Execution time Memory
211079 2020-03-19T07:47:34 Z 147 Job Scheduling (IOI19_job) C++14
Compilation error
0 ms 0 KB
#include "job.h"
#include <bits/stdc++.h>
#define int long long
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<long long int>, std::vector<long long int>, std::vector<long long int>)':
job.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(s.size()==n-1){
        ~~~~~~~~^~~~~
job.cpp:20:9: warning: unused variable 'ans' [-Wunused-variable]
     int ans=0;
         ^~~
job.cpp:56:9: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return result;
         ^~~~~~
/tmp/ccrCJsOl.o: In function `main':
grader.cpp:(.text.startup+0x2bf): undefined reference to `scheduling_cost(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status