Submission #854450

# Submission time Handle Problem Language Result Execution time Memory
854450 2023-09-27T16:45:59 Z Wansur Closing Time (IOI23_closing) C++17
Compilation error
0 ms 0 KB
#include <vector>
#include<bits/stdc++.h>
#define f first
#define s second

using namespace std;
const int mx=2e5+12;

vector<pair<int,long long>> g[mx];
long long d1[mx];
long long d2[mx];
int n,k;

void dfs(int v,int p,bool ok){
	for(auto To:g[v]){
		int to=To.f,w=To.s;
		if(to==p){
			continue;
		}
		if(ok){
			d2[to]=d2[v]+w;
		}
		else{
			d1[to]=d1[v]+w;
		}
		dfs(to,v,ok);
	}
}

int max_score(int N, int x, int y, long long K, std::vector<int> U,std::vector<int> V, std::vector<int> W){
	n=N,k=K;
	for(int i=0;i<n;i++){
		g[i].clear();
		d1[i]=d2[i]=0;
	}
	for(int i=0;i<n-1;i++){
		g[V[i]].push_back({U[i],W[i]});
		g[U[i]].push_back({V[i],W[i]});
	}
	if(x>y){
		swap(x,y);
	}
	dfs(x,-1,0);
	dfs(y,-1,1);
	long long sum=0,len=d1[y],ans=0,cnt=2*(y-x+1);
	for(int i=x;i<=y;i++){
		sum+=max(d1[i],d2[i]);
	}
	vector<long long> v;
	for(int i=0;i<x;i++){
		v.push_back(d1[i]);
	}
	for(int i=y+1;i<n;i++){
		v.push_back(d2[i]);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(sum+v[i]<=k){
			sum+=v[i];
			cnt++;
		}
	}
	if(sum<=k){
		cnt+=min(n-(y-x+1),(k-sum)/len);
		ans=cnt;
	}
	for(int pos=x;pos<y;pos++){
		long long cnt=0,sum=0;
		vector<long long> v;
		for(int i=0;i<=pos;i++){
			v.push_back(d1[i]);
		}
		for(int i=pos+1;i<n;i++){
			v.push_back(d2[i]);
		}
		sort(v.begin(),v.end());
		for(long long x:v){
			if(sum+x<=k){
				cnt++;
				sum+=x;
			}
		}
		ans=max(ans,cnt);
	}
	v.clear();
	for(int i=0;i<n;i++){
		v.push_back(d1[i]);
	}
	sort(v.begin(),v.end());
	cnt=sum=0;
	for(long long x:v){
		if(sum+x<=k){
			sum+=x;
			cnt++;
		}
	}
	ans=max(ans,cnt);
	cnt=sum=0;
	v.clear();
	for(int i=0;i<n;i++){
		v.push_back(d2[i]);
	}
	sort(v.begin(),v.end());
	for(long long x:v){
		if(sum+x<=k){
			sum+=x;
			cnt++;
		}
	}
	ans=max(ans,cnt);
	return ans;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
closing.cpp:64:33: error: no matching function for call to 'min(int, long long int)'
   64 |   cnt+=min(n-(y-x+1),(k-sum)/len);
      |                                 ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
closing.cpp:64:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   64 |   cnt+=min(n-(y-x+1),(k-sum)/len);
      |                                 ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
closing.cpp:64:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   64 |   cnt+=min(n-(y-x+1),(k-sum)/len);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
closing.cpp:64:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |   cnt+=min(n-(y-x+1),(k-sum)/len);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
closing.cpp:64:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |   cnt+=min(n-(y-x+1),(k-sum)/len);
      |                                 ^