제출 #106217

#제출 시각아이디문제언어결과실행 시간메모리
106217polyfish여행하는 상인 (APIO17_merchant)C++14
컴파일 에러
0 ms0 KiB
//Pantyhose(black) + glasses = infinity #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << " = " << x << '\n'; #define BP() cerr << "OK!\n"; #define PR(A, n) {cerr << #A << " = "; for (int64_t _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define PR0(A, n) {cerr << #A << " = "; for (int64_t _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define FILE_NAME "merchant" const int64_t MAX_N = 102; const int64_t MAX_K = 1002; const int64_t INF = 1e9+1e8; struct edge { int64_t u, v; double w; edge() {} edge(int64_t u, int64_t v, double w): u(u), v(v), w(w) {} }; int64_t n, m, k, b[MAX_N][MAX_K], s[MAX_N][MAX_K], c[MAX_N][MAX_N], mx[MAX_N][MAX_N]; vector<edge> g[MAX_N]; double d[MAX_N]; void read_input() { cin >> n >> m >> k; for (int64_t i=1; i<=n; ++i) { for (int64_t j=1; j<=k; ++j) cin >> b[i][j] >> s[i][j]; } } void floyd() { for (int64_t i=1; i<=n; ++i) { for (int64_t j=1; j<=n; ++j) c[i][j] = INF; } for (int64_t i=1; i<=n; ++i) c[i][i] = 0; for (int64_t i=1; i<=m; ++i) { int64_t u, v; cin >> u >> v; cin >> c[u][v]; } for (int64_t k=1; k<=n; ++k) { for (int64_t i=1; i<=n; ++i) { for (int64_t j=1; j<=n; ++j) { c[i][j] = min(c[i][j], c[i][k] + c[k][j]); assert(c[i][j]>=0); } } } // debug(c[4][1]); } void init() { for (int64_t i=1; i<=n; ++i) { for (int64_t j=1; j<=n; ++j) { mx[i][j] = -INF; for (int64_t t=1; t<=k; ++t) { if (b[i][t]!=-1 && s[j][t]!=-1) mx[i][j] = max(mx[i][j], -b[i][t] + s[j][t]); } } } // debug(mx[1][4]); } bool relax(edge e) { if (d[e.v]>d[e.u] + e.w) { d[e.v] = d[e.u] + e.w; return true; } return false; } bool check_negative_cycle(double x) { vector<edge> E; for (int64_t i=1; i<=n; ++i) { for (int64_t j=1; j<=n; ++j) E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j]))); } memset(d, 0, sizeof(d)); for (int64_t i=0; i<=n; ++i) { if (i==n) return true; bool stop = true; for (auto e : E) { if (relax(e)) stop = false; } if (stop) break; } return false; } double bisect() { double l = 0, r = INF; while (abs(l-r)>1e-2) { double mid = (l + r) / 2; if (check_negative_cycle(mid)) l = mid; else r = mid; } return r; } int main() { freopen(FILE_NAME".inp", "r", stdin); freopen(FILE_NAME".out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); read_input(); floyd(); init(); // debug(check_negative_cycle(1.9)); cout << int64_t(bisect()); // for (int64_t i=1; i<=n; ++i) { // for (int64_t j=1; j<=n; ++j) { // if (mx[i][j]==-INF) // cout << -1 << " \n"[j==n]; // else // cout << mx[i][j] << " \n"[j==n]; // } // } }

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

merchant.cpp: In function 'bool check_negative_cycle(double)':
merchant.cpp:94:56: error: no matching function for call to 'max(long long int, int64_t&)'
    E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j])));
                                                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from merchant.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
merchant.cpp:94:56: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j])));
                                                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from merchant.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
merchant.cpp:94:56: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j])));
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from merchant.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
merchant.cpp:94:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j])));
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from merchant.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
merchant.cpp:94:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    E.push_back(edge(i, j, x*c[i][j] - max(0LL, mx[i][j])));
                                                        ^
merchant.cpp: In function 'int main()':
merchant.cpp:133:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen(FILE_NAME".inp", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:134:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen(FILE_NAME".out", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~