답안 #373257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373257 2021-03-03T23:46:58 Z MilosMilutinovic Job Scheduling (IOI19_job) C++14
컴파일 오류
0 ms 0 KB
#include "job.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back

const int mxN=2e5;
int n;
vector<int> adj[mxN];
vector<ll> p, u, d;
bool was[mxN];
ll ans=0;

struct cmp{
	bool operator()(int x, int y) {
		return (ll)d[x]*(ll)u[y]>(ll)d[y]*(ll)u[x];
	}
};

priority_queue<int, vector<int>, cmp> q[mxN];

void merge(int x, int y) {
	d[x]+=d[y];
	u[x]+=u[y];	
}

void dfs(int x) {
	assert(x>=0&&x<n);
	for(int v:adj[x])
		dfs(v), q[x].push(v);
	while(!q[x].empty()) {
		int y=q[x].top();
		if((ll)d[y]*(ll)u[x]>(ll)d[x]*(ll)u[y])
			break;
		was[y]=true;
		q[x].pop();
		ans-=d[y]*u[x];
		merge(x, y);
		if((int)q[x].size()<(int)q[y].size())
			swap(q[x], q[y]);
		while(!q[y].empty())
			q[x].push(q[y].top()), q[y].pop();
	}	
}

ll scheduling_cost(vector<int> p1, vector<int> u1, vector<int> d1) {
	for(int i=0; i<n; ++i)
		p[i]=p1[i], u=u1[i], d=d1[i];
	n = (int) p.size();
	for(int i=1; i<n; ++i) 
		adj[p1[i]].pb(i);
	dfs(0);
	vector<int> j;
	for(int i=0; i<n; ++i)
		if(!was[i])
			j.pb(i);
	sort(j.rbegin(), j.rend(), [&](int x, int y) {
		return (ll)d[x]*u[y]>(ll)d[y]*u[x];
	});
	ll t=0LL;
	for(int i:j)
		t+=d[i], ans+=(ll)u[i]*t;
	return ans;
}

Compilation message

job.cpp: In function 'long long int scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:49:21: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   49 |   p[i]=p1[i], u=u1[i], d=d1[i];
      |                     ^
In file included from /usr/include/c++/9/vector:72,
                 from job.h:5,
                 from job.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from job.h:5,
                 from job.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::vector<long long int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::initializer_list<long long int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
job.cpp:49:30: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   49 |   p[i]=p1[i], u=u1[i], d=d1[i];
      |                              ^
In file included from /usr/include/c++/9/vector:72,
                 from job.h:5,
                 from job.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from job.h:5,
                 from job.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::vector<long long int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::initializer_list<long long int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~