제출 #374261

#제출 시각아이디문제언어결과실행 시간메모리
374261mathking1021여행하는 상인 (APIO17_merchant)C++17
100 / 100
107 ms3772 KiB
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; ll n, m, k; ll d[105][105]; ll e[105][105]; ll c[105][105]; ll a[105][1005]; ll b[105][1005]; ll x[105]; ll y[105]; bool f(ll p) { for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { c[i][j] = d[i][j] * p - e[i][j]; } } x[1] = 0; y[1] = 0; for(ll i = 2; i <= n; i++) { x[i] = 2e18; y[i] = 0; } for(ll ii = 1; ii <= n; ii++) { for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { if(i == j) continue; if(x[j] > x[i] + c[i][j]) x[j] = x[i] + c[i][j], y[j] = y[i] - 1; else if(x[j] == x[i] + c[i][j]) y[j] = min(y[j], y[i] - 1); } } } for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { if(i == j) continue; if(x[j] > x[i] + c[i][j]) return true; else if(x[j] == x[i] + c[i][j] && y[j] > y[i] - 1) return true; } } return false; } int main() { scanf("%lld%lld%lld", &n, &m, &k); for(ll i = 1; i <= n; i++) { for(ll j = 0; j < k; j++) { ll t1, t2; scanf("%lld%lld", &t1, &t2); if(t1 == -1) a[i][j] = 1e18; else a[i][j] = t1; if(t2 == -1) b[i][j] = -1e18; else b[i][j] = t2; } } for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { d[i][j] = 2e9; } d[i][i] = 0; } for(ll i = 0; i < m; i++) { ll t1, t2, t3; scanf("%lld%lld%lld", &t1, &t2, &t3); d[t1][t2] = t3; } for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { e[i][j] = 0; for(ll ii = 0; ii < k; ii++) { e[i][j] = max(e[i][j], b[j][ii] - a[i][ii]); } } } for(ll ii = 1; ii <= n; ii++) { for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= n; j++) { d[i][j] = min(d[i][j], d[i][ii] + d[ii][j]); } } } ll lt = 0, rt = 2e9, mid, ans = 0; // f(3); while(lt <= rt) { mid = (lt + rt) / 2; if(f(mid)) ans = mid, lt = mid + 1; else rt = mid - 1; } printf("%lld\n", ans); return 0; }

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

merchant.cpp: In function 'int main()':
merchant.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     scanf("%lld%lld%lld", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |             scanf("%lld%lld", &t1, &t2);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   82 |         scanf("%lld%lld%lld", &t1, &t2, &t3);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...