Submission #660015

#TimeUsernameProblemLanguageResultExecution timeMemory
660015aebovPalembang Bridges (APIO15_bridge)C++17
Compilation error
0 ms0 KiB
#include<iostream> #include<algorithm> #include<cstring> #include<iomanip> #include<map> #include<utility> #include<unordered_map> #include<vector> #include<set> #define pii pair<int,int> #define pll pair<ll, ll> #define F first #define S second #define ll long long #define pb push_back using namespace std; const int N = (int)1e5 + 5, mod = (ll)1e9 + 7; int n, k, x, y; char ch, hc; ll sm = 0, sm2 = (ll)1e18 + 18; void sub(){ // cerr << "\n entered #sub 2 \n"; vector<int> cv; vector<pii> vc; vc.pb({0,0}); for(int i = 1; i <= n; i ++){ cin >> ch >> x >> hc >> y; if(x < y)swap(x, y); if(ch == hc) sm += x - y; else vc.pb({y, x}); } n = vc.size() - 1; // cout << "N " << n << endl; for(int i = 1; i <= n; i ++) { cv.pb(vc[i].F); cv.pb(vc[i].S); } sort(cv.begin(), cv.end()); // for(auto u : cv)cout << u << endl; for(int i = 0; i < cv.size(); i ++){ for(int j = i; j < cv.size(); j ++) { int x = cv[i], y = cv[j]; int sum = 0; for(int z = 1; z <= n; z ++){ if(vc[z].S < x) sum += (x<<1) - vc[z].F - vc[z].S + 1; else if(vc[z].F > y) sum += vc[z].F + vc[z].S - (y<<1) + 1; else if(x < vc[z].F && vc[z].S < y)sum += min(vc[z].F + vc[z].S -(x<<1) + 1,(y<<1) - vc[z].F - vc[z].S + 1); else sum += vc[z].S - vc[z].F + 1; } sm2 = min(sm2, sum); } } // cout << sm << " " << sm2 << endl; cout << sm + sm2 << endl; exit(0); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k >> n; vector<int> vc; if(k == 2 && n < 101)sub(); // cerr << "\n enteres #sub1 \n"; for(int i = 1; i <= n; i ++){ cin >> ch >> x >> hc >> y; if(ch == hc) sm += abs(x - y); else sm ++, vc.pb(x), vc.pb(y); } sort(vc.begin(), vc.end()); int pos = vc[(vc.size() - 1) / 2]; for(auto x : vc)sm += abs(x - pos); cout << sm << endl; }

Compilation message (stderr)

bridge.cpp: In function 'void sub()':
bridge.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i = 0; i < cv.size(); i ++){
      |                 ~~^~~~~~~~~~~
bridge.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int j = i; j < cv.size(); j ++) {
      |                  ~~^~~~~~~~~~~
bridge.cpp:50:22: error: no matching function for call to 'min(long long int&, int&)'
   50 |    sm2 = min(sm2, sum);
      |                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
bridge.cpp:50:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |    sm2 = min(sm2, sum);
      |                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
bridge.cpp:50:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |    sm2 = min(sm2, sum);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from bridge.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
bridge.cpp:50:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |    sm2 = min(sm2, sum);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from bridge.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
bridge.cpp:50:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |    sm2 = min(sm2, sum);
      |                      ^