Submission #904982

#TimeUsernameProblemLanguageResultExecution timeMemory
904982vjudge1Travelling Merchant (APIO17_merchant)C++17
0 / 100
332 ms2180 KiB
#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]; 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(i==j)continue; for(int f=1;f<=k;f++){ if(b[i][f]!=-1&&s[j][f]!=-1){ int cost=s[j][f]-b[i][f]-x*d[i][j]; cost=-cost; d1[i][j]=min(d1[i][j],cost); } } } } 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]); 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]; for(int j=1;j<=k;j++)cin>>s[i][j]; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)if(i!=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]); } } } 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<<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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...