This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma optimize("03")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll
const int MAX=1005;
const int B=104;
const int N=104;
const int block=450;
const int maxB=MAX/B+10;
const ll inf=1e18;
const int mod=1e9+7;
const int mod1=1e9+9;
const int logg=15;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
int n,m,k;
int d[N][N],cost[N][N];
int b[N][MAX],s[N][MAX];
int d1[N][N];
bool check(int x){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d1[i][j]=inf;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(d[i][j]==inf)continue;
d1[i][j]=min(d1[i][j],-(cost[i][j]-x*d[i][j]));
}
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]);
}
}
}
int ans=inf;
for(int i=1;i<=n;i++)ans=min(ans,d1[i][i]);
// cout<<ans<<"\n";
return (ans<=0);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++)cin>>b[i][j]>>s[i][j];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)d[i][j]=inf;
}
for(int i=1;i<=m;i++){
int x,y,w;
cin>>x>>y>>w;
d[x][y]=w;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int f=1;f<=k;f++){
if(s[j][f]==-1||b[i][f]==-1)continue;
cost[i][j]=max(s[j][f]-b[i][f],cost[i][j]);
}
// cout<<i<<" "<<j<<" "<<cost[i][j]<<"\n";
}
}
// cout<<d[2][4]<<"\n";
// check(1e9);
int l=0,r=1e9,res=-1;
while(l<=r){
int m=(l+r)/2;
if(check(m)){
l=m+1;
res=m;
}
else r=m-1;
}
// cout<<check(2)<<"\n";
cout<<res<<"\n";
}
Compilation message (stderr)
merchant.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("03")
|
merchant.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |