Submission #101999

#TimeUsernameProblemLanguageResultExecution timeMemory
101999bakpark여행하는 상인 (APIO17_merchant)C++14
33 / 100
141 ms2236 KiB
#include <cstdio>
#include <algorithm>
#include <limits.h>
#include <memory.h>
using namespace std;
#define INF ((LLONG_MAX)>>10)
#define ll long long

int N,M,K;
ll B[101][1001], S[101][1001], T[101][101],val[101][101];
ll Q[101][101];
ll dist[101][101];
ll g(int st,int en,ll m,ll d){
	return Q[st][en]-d*m;
}
bool f(ll m){
	memset(dist,-1,sizeof(dist));
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			if(T[i][j]) {
				dist[i][j] = T[i][j];
				val[i][j] = g(i,j,m,T[i][j]);
			}
			else val[i][j] = -INF;
		}
	}
	for(int mid=1;mid<=N;mid++){
		for(int st=1;st<=N;st++){
			for(int en=1;en<=N;en++){
				if(dist[st][mid]==-1||dist[mid][en]==-1) continue;
				ll td = dist[st][mid]+dist[mid][en];
				ll hval = max(g(st,en,m,td),val[st][mid]+val[mid][en]);
				if(hval>val[st][en]){
					dist[st][en] = td;
					val[st][en] = hval;
				}
			}
		}
	}
	for(int n=1;n<=N;n++){
		if(val[n][n]>=0) return true;
	}
	return false;
}
int main(){
	scanf("%d %d %d",&N,&M,&K);
	for(int i=1;i<=N;i++){
		for(int j=0;j<K+K;j++){
			ll tmp;scanf("%lld",&tmp);
			if(j&1)	S[i][j/2+1] = tmp;
			else B[i][j/2+1] = tmp;
		}
	}
	for(int i=0;i<M;i++){
		int a,b;
		ll c;
		scanf("%d %d %lld",&a,&b,&c);
		T[a][b] = c;
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			for(int k=1;k<=K;k++){
				if(i==j) continue;
				if(B[i][k]>0&&S[j][k]>0)
					Q[i][j] = max(Q[i][j],S[j][k]-B[i][k]);
			}
		}
	}
	ll l = 0,r = 1000000000,answ=0;
	while(l<=r){
		ll m = (l+r)>>1;
		if(f(m)){
			l = m+1;
			answ = m;
		}
		else r = m-1;
	}
	printf("%lld",answ);
}
		



Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&N,&M,&K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
merchant.cpp:49:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    ll tmp;scanf("%lld",&tmp);
           ~~~~~^~~~~~~~~~~~~
merchant.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %lld",&a,&b,&c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...