제출 #555781

#제출 시각아이디문제언어결과실행 시간메모리
555781cadmiumsky여행하는 상인 (APIO17_merchant)C++14
0 / 100
109 ms2496 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll const ll inf = 5e14 + 5; const int nmax = 105; void fw(int n, ll dist[nmax][nmax]) { for(int h = 0; h < n; h++) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][h] + dist[h][j]); } } } void fwmx(int n, ll dist[nmax][nmax]) { for(int h = 0; h < n; h++) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) dist[i][j] = max(dist[i][j], dist[i][h] + dist[h][j]); } } } void print(int n, ll dist[nmax][nmax]) { //for(int i = 0; i < n; i++) { //for(int j = 0; j < n; j++) //cerr << dist[i][j] << ' '; //cerr << '\n'; //} return; } ll dist[nmax][nmax], cost[nmax][nmax], alter[nmax][nmax]; ll buy[nmax][nmax], sell[nmax][nmax]; bool check(int n, int coef) { //cerr << "Alter with coef " << coef << '\n'; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) alter[i][j] = cost[i][j] - dist[i][j] * coef; } print(n, alter); fwmx(n, alter); for(int i = 0; i < n; i++) { if(alter[i][i] >= 0) return 1; } return 0; } signed main() { int n, m, k; cin >> n >> m >> k; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { cin >> buy[i][j] >> sell[i][j]; if(buy[i][j] == -1) buy[i][j] = inf; if(sell[i][j] == -1) sell[i][j] = -inf; } } for(int i = 0; i< n; i++) for(int j = 0; j < n; j++) dist[i][j] = inf; for(int i = 0, x, y, c; i < m; i++) cin >> x >> y >> c, --x, --y, dist[x][y] = min(dist[x][y], c); fw(n, dist); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cost[i][j] = 0; for(int h = 0; h < k; h++) cost[i][j] = max(cost[i][j], sell[j][h] - buy[i][h]); } } //cerr << "Cost:\n"; print(n, cost); //cerr << "Dist:\n"; print(n, dist); int l = 0, r = 1e9 + 5, mid; while(r - l > 1) { mid = l + r >> 1; if(check(n, mid)) l = mid; else r = mid; } cout << l << '\n'; }

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

merchant.cpp: In function 'int main()':
merchant.cpp:83:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |     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...