QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410484 | #676. Travelling Merchant | SirPh# | 0 | 94ms | 5388kb | C++14 | 2.3kb | 2024-05-14 03:06:05 | 2024-05-14 03:06:06 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize("trapv")
using namespace std;
const int mod=(int)1e9+7;
#define endl '\n'
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
int dis[101][101];
int buysell[101][101];
int dis1[101][101];
int buy[101][1001];
int sell[101][1001];
int inf=1e15;
bool overflow(int a,int b)
{
if(a>=(inf/b))return 1;
else return 0;
}
void iforgor()
{
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<=n;i++)for(int j=0;j<k;j++)buysell[i][j]=-2e9;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=1e15;
for(int i=1;i<=n;i++)
{
for(int j=0;j<k;j++)
{
int a,b;
cin>>a>>b;
buy[i][j]=a;
sell[i][j]=b;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++){
for(int e=0;e<k;e++)
{
if(buy[i][e]==-1||sell[j][e]==-1)continue;
buysell[i][j]=max(buysell[i][j],sell[j][e]-buy[i][e]);
}
}
}
for(int i=0;i<m;i++)
{
int a,b,c;
cin>>a>>b>>c;
dis[a][b]=c;
}
for(int kk=1;kk<=n;kk++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][kk]+dis[kk][j]);
int ans=0;
int l=1,r=2e9;
int ez=0;
while(l<=r)
{
int mid=(l+r)/2;
bool negcyc=false;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis1[i][j]=1e15;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(overflow(mid,dis[i][j])||buysell[i][j]==2e9)dis1[i][j]=1e15;
else
dis1[i][j]=mid*dis[i][j]-buysell[i][j];
}
for(int kk=1;kk<=n;kk++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis1[i][j]=min(dis1[i][j],dis1[i][kk]+dis1[kk][j]);
for(int i=1;i<=n;i++)if(dis1[i][i]<=0)negcyc=true,ez=i;
if(negcyc)
{
ans=mid;
l=mid+1;
}
else r=mid-1;
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--)iforgor();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 94ms
memory: 5388kb
input:
100 181 1000 553730496 158361961 892706912 178296397 743382683 297380306 641674485 99624440 917350062 18856036 844421978 187895310 648680590 312745394 560991872 402321479 712754581 166489560 776432653 57402415 554268728 511597509 861517186 541462029 843246768 457630601 923371196 521104850 557772066 ...
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Runtime Error
Test #14:
score: 0
Runtime Error
input:
50 50 20 1000000000 94476 1000000000 75837 1000000000 27079 1000000000 129004 1000000000 100830 1000000000 98560 1000000000 99302 1000000000 65993 30410 1 1000000000 66183 1000000000 89148 1000000000 21236 1000000000 11935 1000000000 53895 1000000000 126490 1000000000 104741 1000000000 78615 1000000...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #37:
score: 0
Runtime Error
input:
100 243 1000 969713863 380451398 977287381 546839551 578242281 267067963 834635238 316438277 806980243 189648353 779415475 453867771 741678190 352485450 473763928 190177433 687118672 377243148 644333594 197290749 949048287 436673078 690006797 180711316 714366028 387342721 980055654 198167471 8873988...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%