Submission #246844

#TimeUsernameProblemLanguageResultExecution timeMemory
246844kshitij_sodaniTravelling Merchant (APIO17_merchant)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'
llo n,m,k;
llo dist[101][101];
llo dist2[101][101];

llo min2(llo aa,llo bb){
	if(aa==-1){
		return bb;
	}
	else if(bb==-1){
		return aa;
	}
	return min(aa,bb);
}
llo cost[101][1000][2];
vector<pair<pair<llo,llo>,llo>> ed;
//vector<pair<pair<llo,llo>,llo>> ed2;
//llo vis[101][101];
bool check(llo mid){
	if(mid==0){
		return true;
	}
/*	for(llo i=0;i<n;i++){
		dist2[i][i]=0;
	}*/
	for(auto j:ed){
		dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
	}
	for(llo kk=0;kk<n;kk++){
		for(llo i=0;i<n;i++){
			for(llo j=0;j<n;j++){
				dist2[i][j]=min(dist2[i][j],dist2[i][kk]+dist2[kk][j]);
			}
		}
	}

	for(llo i=0;i<n;i++){
		for(llo j=0;j<n;j++){
			if(i==j){
				if(dist[i][i]<0){
					return true;
				}
				continue;
			}
			if(dist2[i][j]+dist2[j][i]<=0){
				return true;
			}
		}
	}

	return false;


}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m>>k;
	for(llo i=0;i<n;i++){
		for(llo j=0;j<n;j++){
			dist[i][j]=1e18;
		}
		dist[i][i]=0;
	}
	for(llo i=0;i<n;i++){
		for(llo j=0;j<k;j++){
			cin>>cost[i][j][0]>>cost[i][j][1];
		}
	}
	for(llo i=0;i<m;i++){
		llo aa,bb,cc;
		cin>>aa>>bb>>cc;
		dist[aa-1][bb-1]=min(dist[aa-1][bb-1],cc);
	}
	for(llo kk=0;kk<n;kk++){
		for(llo i=0;i<n;i++){
			for(llo j=0;j<n;j++){
				dist[i][j]=min(dist[i][j],dist[i][kk]+dist[kk][j]);
			}
		}
	}
	
	for(llo i=0;i<n;i++){
		for(llo j=0;j<n;j++){
			/*if(i==j){
				continue;
			}*/
			llo xx=0;
			for(llo kk=0;kk<k;kk++){
				if(cost[i][kk][0]==-1 or cost[j][kk][1]==-1){
					continue;
				}
				xx=max(xx,-cost[i][kk][0]+cost[j][kk][1]);
			}
			ed.pb({{i,j},xx});
		}
	}
	llo low=0;
	llo high=1e9;
	while(low<high-1){
		llo mid=(low+high)/2;
		if(check(mid)){
			low=mid;
		}
		else{
			high=mid;
		}
	}
	for(llo i=high;i>=low;i--){
		if(check(i)){
			cout<<i<<endl;
			return 0;
		}
	}

	return 0;
}

Compilation message (stderr)

merchant.cpp: In function 'bool check(llo)':
merchant.cpp:34:59: error: no matching function for call to 'min(long long int, llo&)'
   dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
                                                           ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from merchant.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
merchant.cpp:34:59: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'llo {aka long int}')
   dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
                                                           ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from merchant.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
merchant.cpp:34:59: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'llo {aka long int}')
   dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
                                                           ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from merchant.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
merchant.cpp:34:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
                                                           ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from merchant.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
merchant.cpp:34:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   dist2[j.a.a][j.a.b]=min(LLONG_MAX/mid,dist[j.a.a][j.a.b])*mid-j.b;
                                                           ^