제출 #57349

#제출 시각아이디문제언어결과실행 시간메모리
57349gabrielsimoes여행하는 상인 (APIO17_merchant)C++17
0 / 100
204 ms2280 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int MAXN = 101, MAXM = 9901, MAXK = 1001; const ll INF = 1e14; // const ll INF = 1000; int N, M, K; vector<pii> g[MAXN]; ll buy[MAXN][MAXK]; ll sell[MAXN][MAXK]; ll d[MAXN][MAXN]; ll gain[MAXN][MAXN]; ll dist[MAXN]; bool ok[MAXN]; bool testPosCycle(ll x) { // for (int i = 1; i <= N; i++) dist[i] = INF; memset(ok, 0, sizeof(ok)); dist[1] = 0; ok[1] = true; for (int cnt = 0; cnt <= N; cnt++) { for (int i = 1; i <= N; i++) { if (!ok[i]) continue; for (int j = 1; j <= N; j++) { if (i == j) continue; ll dd = dist[i] + gain[i][j] - x*d[i][j]; if (!ok[j] || dd > dist[j]) { dist[j] = dd; ok[j] = true; } if (i != 1 && j == 1 && dd >= 0) return true; } } } // for (int i = 1; i <= N; i++) { // printf("x %d i %d dist %lld\n", x, i, dist[i]); // } return false; } int main() { scanf("%d%d%d", &N, &M, &K); for (int i = 1; i <= N; i++) { for (int k = 1; k <= K; k++) { scanf("%lld%lld", &buy[i][k], &sell[i][k]); } } for (int i = 1; i <= N; i++) { for (int k = 1; k <= N; k++) { d[i][k] = INF; } d[i][i] = 0; } for (int i = 1,a,b,c; i <= M; i++) { scanf("%d%d%d", &a, &b, &c); g[a].push_back({b, c}); d[a][b] = c; } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= K; k++) { if (buy[i][k] != -1 && sell[j][k] != -1) { gain[i][j] = max(gain[i][j], -buy[i][k] + sell[j][k]); } } } } ll l = 0, r = INF; while (l < r) { ll m = (l + r + 1LL) >> 1; if (testPosCycle(m)) l = m; else r = m-1; } printf("%lld\n", l); }

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

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