제출 #133820

#제출 시각아이디문제언어결과실행 시간메모리
133820MetBRoller Coaster Railroad (IOI16_railroad)C++14
컴파일 에러
0 ms0 KiB
#include <algorithm> #include <iostream> #include <string.h> #include <cstdlib> #include <vector> #include <string> #include <bitset> #include <math.h> #include <queue> #include <stack> #include <set> #include <map> typedef long long ll; typedef long double ld; const ll MOD = 1e9 + 7, INF = 1e18 + 1; using namespace std; int p[1000000], sz[1000000]; set <int> mp; struct stop { int x; bool op, left; bool operator < (const stop& b) { if (x == b.x) return op > b.op; else return x < b.x; } }; struct edge { int u, v, c; bool operator < (const edge& b) { return c < b.c; } }; vector <stop> v; int find (int x) { if (p[x] == x) return x; else return p[x] = find (p[x]); } void unite (int a, int b) { a = find (a); b = find (b); if (a == b) return; if (sz[a] < sz[b]) swap (a, b); p[b] = a; sz[a] += sz[b]; } int ind (int a, vector <int>& s) { return lower_bound (s.begin(), s.end(), a) - s.begin (); } ll plan_roller_coaster (vector <int> s, vector <int> t) { ll ans = 0, balance = 0; vector <int> coord; for (int i = 0; i < s.size (); i++) { if (s[i] >= t[i]) { v.push_back ({s[i], true, true}); v.push_back ({t[i], false, true}); } else { v.push_back ({s[i], true, false}); v.push_back ({t[i], false, false}); } mp.insert (s[i]); mp.insert (t[i]); } for (auto a : mp) coord.push_back (a); for (int i = 0; i < coord.size (); i++) { sz[i] = 1; p[i] = i; } v.push_back ({1, true, true}); v.push_back ({coord.back (), false, true}); for (int i = 0; i < s.size (); i++) unite (ind (s[i], coord), ind (t[i], coord)); sort (v.begin(), v.end()); vector <edge> tr; for (int i = 0; i < v.size (); i++) { if (v[i].left ^ v[i].op) balance++; else balance--; vector <edge> tr; if (i != v.size () - 1) { ans += max (0, balance * (v[i+1].x - v[i].x)); if (balance) unite (ind (v[i].x, coord), ind (v[i+1].x, coord)); else tr.push_back ({ind (v[i].x, coord), ind (v[i+1].x, coord), (v[i+1].x - v[i].x)}); } } sort (tr.begin(), tr.end()); for (edge e : tr) { if (find (e.u) != find (e.v)) { ans += e.c; unite (e.u, e.v); } } return ans; }

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

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size (); i++)
                  ~~^~~~~~~~~~~
railroad.cpp:100:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < coord.size (); i++)
                  ~~^~~~~~~~~~~~~~~
railroad.cpp:109:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size (); i++)
                  ~~^~~~~~~~~~~
railroad.cpp:116:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size (); i++)
                  ~~^~~~~~~~~~~
railroad.cpp:123:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i != v.size () - 1) 
       ~~^~~~~~~~~~~~~~~~
railroad.cpp:125:48: error: no matching function for call to 'max(int, ll)'
    ans += max (0, balance * (v[i+1].x - v[i].x));
                                                ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from railroad.cpp:1:
/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:
railroad.cpp:125:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
    ans += max (0, balance * (v[i+1].x - v[i].x));
                                                ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from railroad.cpp:1:
/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:
railroad.cpp:125:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
    ans += max (0, balance * (v[i+1].x - v[i].x));
                                                ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from railroad.cpp:1:
/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:
railroad.cpp:125:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
    ans += max (0, balance * (v[i+1].x - v[i].x));
                                                ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from railroad.cpp:1:
/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:
railroad.cpp:125:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
    ans += max (0, balance * (v[i+1].x - v[i].x));
                                                ^