제출 #589347

#제출 시각아이디문제언어결과실행 시간메모리
589347stevancv여행하는 상인 (APIO17_merchant)C++14
100 / 100
74 ms3412 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<vector<int>> a(n, vector<int>(2 * k)); for (int i = 0; i < n; i++) { for (int j = 0; j < 2 * k; j++) { cin >> a[i][j]; } } vector<vector<ll>> dist(n, vector<ll>(n, 1e18)); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; x -= 1; y -= 1; dist[x][y] = z; } for (int l = 0; l < n; l++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { smin(dist[i][j], dist[i][l] + dist[l][j]); } } } vector<vector<ll>> opt(n, vector<ll>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ll x = 0; for (int l = 0; l < k; l++) { if (a[i][2 * l] == -1 || a[j][2 * l + 1] == -1) continue; ll tx = a[j][2 * l + 1] - a[i][2 * l]; smax(x, tx); } opt[i][j] = x; } } auto Can = [&] (ll x) { vector<vector<ll>> d(n, vector<ll>(n, 1e18)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = x * min(dist[i][j], (ll)1e18 / x) - opt[i][j]; for (int o = 0; o < n; o++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) smin(d[i][j], d[i][o] + d[o][j]); for (int i = 0; i < n; i++) if (d[i][i] <= 0) return true; return false; }; ll l = 1; ll r = 1e9; ll ans = 0; while (l <= r) { ll mid = l + r >> 1; if (Can(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << en; return 0; }

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

merchant.cpp: In function 'int main()':
merchant.cpp:56:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         ll mid = l + r >> 1;
      |                  ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...