Submission #1054271

#TimeUsernameProblemLanguageResultExecution timeMemory
1054271HaroldPalembang Bridges (APIO15_bridge)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0); cin.tie(0); /*int k, n; cin >> k >> n; vector<pair<int, int>> a, p; int res = 0; for(int i = 0; i < n; i++) { char c1, c2; int a1, a2; cin >> c1 >> a1 >> c2 >> a2; if(c1 == c2) { res += abs(a1-a2); } else { a.push_back({a1, a2}); } } // incorrect when k = 2 couse need to choose sort(a.begin(), a.end()); for(auto i: a) { pair<int, int> cur = {i.first, i.second}; if(p.empty()) { p.push_back(cur); continue; } if(p.back().second >= cur.first) { p.back() = {cur.first, p.back().second}; } else { p.push_back(cur); } } int i = 0; // point to cur element in a int j = 0; // point to element in p int cross = 0; while(k > 0 && j < p.size()) { cross = p[j].second; while(i < a.size() && a[i].first <= cross) { res += abs(a[i].second-a[i].first); i++; } j++; k--; } while(i < a.size()) { res += abs(a[i].second-a[i].first) + 2*abs(cross-a[i].first); i++; } cout << res+a.size() << endl;*/ int k, n; cin >> k >> n; vector<int> a; vector<pair<ll, ll>> p; ll res = 0; for(int i = 0; i < n; i++) { char c1, c2; ll a1, a2; cin >> c1 >> a1 >> c2 >> a2; if(c1 == c2) { res += abs(a1-a2); } else { a.push_back(a1); a.push_back(a2); p.push_back({a1, a2}); } } sort(a.begin(), a.end()); if(k == 1) { int m = a[a.size()/2]; for(auto i: p) { res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0); } } cout << res << "\n"; return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:82:65: error: no matching function for call to 'max(long long int, int)'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:65: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:65: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                 ^
bridge.cpp:82:87: error: no matching function for call to 'max(long long int, int)'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                                       ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:87: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                                       ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:87: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:87: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridge.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
bridge.cpp:82:87: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             res += abs(i.second-i.first)+1 + 2*max(m-i.second, 0) + 2*max(i.first-m, 0);
      |                                                                                       ^