제출 #296127

#제출 시각아이디문제언어결과실행 시간메모리
296127RealSuperman1Roller Coaster Railroad (IOI16_railroad)C++14
컴파일 에러
0 ms0 KiB
#include "railroad.h" #include <bits/stdc++.h> #define ll long long #define int long long #define pb push_back #define fi first #define se second #define pll pair<long long, long long> #define pii pair<int, int> using namespace std; const ll INF = 1e18; int n; bool cmp(pii x, pii y) { return x.fi > y.fi; } ll case3(vector <int> s, vector <int> t) { vector <pii> t1(n); for (int i = 0; i < n; i++) t1[i] = {t[i], i}; sort(t1.begin(), t1.end(), cmp); // for (auto to : s1) // cout << to.fi << " " << to.se << endl; // cout << endl; // return 0; vector <int> nx(n, -1); set <pii> sn = {}; for (int i = 0; i < n; i++) sn.insert({s[i], i}); set <pii>::iterator it; for (int i = 0; i < n; i++) { it = sn.lower_bound({t1[i].fi, 0}); if (it == sn.end()) continue; pii val = *it; if (val.se == t1[i].se) it = sn.upper_bound(val); if (it == sn.end()) continue; val = *it; nx[t1[i].se] = val.se; // cout << t1[i].se << "->" << val.se << endl; sn.erase(it); if (sn.size() == 1) break; } if (sn.size() == 1) return 0ll; vector <int> s_new, t_new; for (set<pii>::iterator it = sn.begin(); it != sn.end(); it++) { int curt, curs; pii val = *it; int u = val.se; curs = s[u]; while (nx[u] != -1) u = nx[u]; curt = t[u]; s_new.pb(curs); t_new.pb(curt); } ll ans = 0, sumt = 0, sums = 0; for (int i = 0; i < s_new.size(); i++) { // cout << s_new[i] << " "; sums += s_new[i] * 1ll; } // cout << endl; pii mx1 = {-1, -1}, mx2 = {-1, -1}; for (int i = 0; i < t_new.size(); i++) { // cout << t_new[i] << " "; sumt += t_new[i] * 1ll; if (t_new[i] >= mx1.fi) { mx2 = mx1; mx1 = {t_new[i], i}; } else if (t_new[i] >= mx2.fi) mx2 = {t_new[i], i}; } // cout << endl; ll mn = INF; for (int i = 0; i < s_new.size(); i++) { if (mx1.se != i) mn = min(mn, s_new[i] * 1ll - mx1.fi * 1ll); else mn = min(mn, s_new[i] * 1ll - mx2.fi * 1ll); } // cout << mx1.fi << " " << mx1.se << endl; // cout << mx2.fi << " " << mx2.se << endl; return sumt - sums + mn; } ll plan_roller_coaster(vector <int> s, vector <int> t) { n = s.size(); if (n > 16 || true) { return case3(s, t); } vector < vector <ll> > w; vector < vector <ll> > dp; w.resize(n); for (int i = 0; i < n; i++) { w[i].resize(n); for (int j = 0; j < n; j++) { if (i == j) continue; w[i][j] = max(0, t[i] - s[j]); } } dp.resize((1 << n)); for (int mask = 0; mask < (1 << n); mask++) { dp[mask].resize(n); for (int i = 0; i < n; i++) dp[mask][i] = INF; } for (int i = 0; i < n; i++) dp[0][i] = 0; vector <int> b; for (int mask = 1; mask < (1 << n); mask++) { b.clear(); for (int i = 0; i < n; i++) if (1 & (mask >> i)) b.pb(i); if (b.size() == 1) { dp[mask][b[0]] = 0; continue; } for (int i = 0; i < b.size(); i++) for (int j = 0; j < b.size(); j++) { if (i == j) continue; int mask1 = (mask ^ (1 << b[i])); dp[mask][b[i]] = min(dp[mask][b[i]], dp[mask1][b[j]] + w[b[j]][b[i]]); } } ll ans = INF; for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]); return ans; }

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

railroad.cpp: In function 'long long int case3(std::vector<long long int>, std::vector<long long int>)':
railroad.cpp:66:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for (int i = 0; i < s_new.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
railroad.cpp:72:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for (int i = 0; i < t_new.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
railroad.cpp:83:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for (int i = 0; i < s_new.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
railroad.cpp:65:5: warning: unused variable 'ans' [-Wunused-variable]
   65 |  ll ans = 0, sumt = 0, sums = 0;
      |     ^~~
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<long long int>, std::vector<long long int>)':
railroad.cpp:107:32: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  107 |    w[i][j] = max(0, t[i] - s[j]);
      |                                ^
In file included from /usr/include/c++/9/vector:60,
                 from railroad.h:3,
                 from railroad.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
railroad.cpp:107:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  107 |    w[i][j] = max(0, t[i] - s[j]);
      |                                ^
In file included from /usr/include/c++/9/vector:60,
                 from railroad.h:3,
                 from railroad.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
railroad.cpp:107:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  107 |    w[i][j] = max(0, t[i] - s[j]);
      |                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
railroad.cpp:107:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  107 |    w[i][j] = max(0, t[i] - s[j]);
      |                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from railroad.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
railroad.cpp:107:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  107 |    w[i][j] = max(0, t[i] - s[j]);
      |                                ^
railroad.cpp:128:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |   for (int i = 0; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
railroad.cpp:129:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |    for (int j = 0; j < b.size(); j++) {
      |                    ~~^~~~~~~~~~