제출 #52355

#제출 시각아이디문제언어결과실행 시간메모리
52355imeimi2000여행하는 상인 (APIO17_merchant)C++17
100 / 100
107 ms9544 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n, k; const int inf = 1e9 + 7; const llong linf = (llong)inf * inf; int buy[101][1001], sell[101][1001]; int t[101][101]; int c[101][101]; llong d[101][101]; int main() { int m; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= k; ++j) { scanf("%d%d", buy[i] + j, sell[i] + j); if (buy[i][j] != -1 && buy[i][j] < sell[i][j]) exit(1); } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { t[i][j] = inf; } } for (int i = 0; i < m; ++i) { int v, w, p; scanf("%d%d%d", &v, &w, &p); t[v][w] = p; } for (int p = 1; p <= n; ++p) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { t[i][j] = min(t[i][j], t[i][p] + t[p][j]); } } } for (int i = 1; i <= k; ++i) { for (int j = 1; j <= n; ++j) { for (int p = 1; p <= n; ++p) { if (buy[j][i] != -1 && sell[p][i] != -1) { c[j][p] = max(c[j][p], sell[p][i] - buy[j][i]); } } } } int s = 0, e = inf; while (s < e) { m = (s + e + 1) / 2; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (t[i][j] == inf) d[i][j] = linf; else d[i][j] = (llong)m * t[i][j] - c[i][j]; } } for (int p = 1; p <= n; ++p) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { d[i][j] = min(d[i][j], d[i][p] + d[p][j]); } } } int ch = 0; for (int i = 1; i <= n; ++i) { if (d[i][i] <= 0) { ch = 1; break; } } if (ch) s = m; else e = m - 1; } printf("%d\n", s); return 0; }

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

merchant.cpp: In function 'int main()':
merchant.cpp:31: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:34:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", buy[i] + j, sell[i] + j);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &v, &w, &p);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...