제출 #155118

#제출 시각아이디문제언어결과실행 시간메모리
155118mhy908여행하는 상인 (APIO17_merchant)C++14
100 / 100
112 ms4268 KiB
#include <bits/stdc++.h> #define inf 1987654321 using namespace std; typedef long long LL; int n, m, k; LL buy[110][1010], sell[110][1010]; LL floyd[110][110]; LL cost[110][110]; LL edge[110][110]; bool negcycle() { for(int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ edge[i][j]=min(edge[i][j], edge[i][k]+edge[k][j]); } } } bool ret=false; for(int i=1; i<=n; i++){ if(edge[i][i]<=0)ret=true; } return ret; } LL binsearch(LL a, LL b){ if(a==b)return a; LL mid=(a+b)/2+1; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ edge[i][j]=min((LL)inf, mid*floyd[i][j]-cost[i][j]); } } if(negcycle())return binsearch(mid, b); return binsearch(a, mid-1); } int main() { scanf("%d %d %d", &n, &m, &k); for(int i=1; i<=n; i++) for(int j=1; j<=k; j++) scanf("%lld %lld", &buy[i][j], &sell[i][j]); for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)floyd[i][j]=inf; for(int i=1; i<=m; i++){ int a, b; LL c; scanf("%d %d %lld", &a, &b, &c); floyd[a][b]=min(floyd[a][b], c); } for(int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ floyd[i][j]=min(floyd[i][j], floyd[i][k]+floyd[k][j]); } } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ for(int z=1; z<=k; z++){ if(sell[j][z]>=0&&buy[i][z]>=0)cost[i][j]=max(cost[i][j], sell[j][z]-buy[i][z]); } } } printf("%lld", binsearch(0, 1000000000)); }

컴파일 시 표준 에러 (stderr) 메시지

merchant.cpp: In function 'int main()':
merchant.cpp:38:10: 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:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld %lld", &buy[i][j], &sell[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:46:14: 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...