Submission #915696

#TimeUsernameProblemLanguageResultExecution timeMemory
915696tvladm2009Palembang Bridges (APIO15_bridge)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <complex> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <numeric> #include <cstring> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cmath> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <deque> #include <random> using namespace std; template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;} template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;} #define files(FILENAME) read(FILENAME); write(FILENAME) #define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin) #define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout) #define all(c) (c).begin(), (c).end() #define sz(c) (int)(c).size() #define left left228 #define right right228 #define y1 y1228 #define mp make_pair #define pb push_back #define y2 y2228 #define rank rank228 using ll = long long; using ld = long double; const string FILENAME = "input"; int k, n; map<int, vector<int>> ind; struct three { ll first; ll second; ll third; bool operator < (three oth) const { return first > oth.first; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //read(FILENAME); cin >> k >> n; ll add = 0; vector<pair<int, int>> v; vector<int> points; int cnt = 0; for (int i = 1; i <= n; i++) { char p, q; int s, t; cin >> p >> s >> q >> t; if (p == q) { add += abs(s - t); } else { points.pb(s); points.pb(t); if (p == '1') { swap(s, t); } v.pb(mp(s, t)); cnt++; } } sort(all(points)); if (k == 1) { auto f = [&](int bridge) { ll res = 0; for (auto i: points) { res += abs(i - bridge); } res += cnt; return res; }; int med = (sz(points) + 1) / 2; cout << f(points[med - 1]) + add << '\n'; } else { auto f = [&](int i, int j) { ll res = 0; for (auto x: v) { res += min(abs(x.first - i) + abs(x.second - i), abs(x.first - j) + abs(x.second - j)); } res += cnt; return res; }; vector<int> bridges = points; for (int i = 0; i < sz(points); i++) { for (int j = 0; j < sz(points); j++) { bridges.pb((points[i] + points[j]) / 2); bridges.pb((points[i] + points[j] + 1) / 2); } } sort(all(bridges)); bridges.resize(all(bridges) - bridges.begin()); ll ans = 1e18; for (auto i: bridges) { for (auto j: bridges) { chkmin(ans, f(i, j)); } } cout << ans + add << '\n'; return 0; sort(all(v)); ll sum = 0; for (auto i: v) { sum += abs(i.second - i.first); } for (auto i: v) { ind[max(i.first, i.second)].pb(min(i.first, i.second)); } points.resize(unique(all(points)) - points.begin()); //ll ans = 1e18; for (int i = 0; i + 1 < sz(points); i++) { ll cost = sum; priority_queue<three> pq; int offset = 0; ll inpq = 2 * (points[i + 1] - points[i]); for (int j = i + 1; j < sz(points); j++) { while (!pq.empty() && -pq.top().first <= offset) { cost += pq.top().second; inpq -= pq.top().third; pq.pop(); } for (auto kek: ind[points[j]]) { if (kek >= points[i]) { cost -= points[j] - kek; pq.push({-(points[j] - points[i] + kek - points[i] - points[j] + kek + offset), points[j] - points[i] + kek - points[i], points[j] - kek}); inpq += points[j] - kek; } } chkmin(ans, cost + inpq); if (j == sz(points)) { break; } offset += 2 * (points[j + 1] - points[j]); } } cout << ans + cnt + add << '\n'; } return 0; } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 5 2 5 5 7 */

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:112:48: error: no matching function for call to 'std::vector<int>::resize(std::vector<int>::iterator, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
  112 |   bridges.resize(all(bridges) - bridges.begin());
      |                                                ^
In file included from /usr/include/c++/10/vector:67,
                 from bridge.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:937:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
  937 |       resize(size_type __new_size)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:937:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:957:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
  957 |       resize(size_type __new_size, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:957:24: note:   no known conversion for argument 1 from 'std::vector<int>::iterator' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
  957 |       resize(size_type __new_size, const value_type& __x)
      |              ~~~~~~~~~~^~~~~~~~~~