Submission #1247921

#TimeUsernameProblemLanguageResultExecution timeMemory
1247921vlomaczkCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct Point { ll x, y; }; bool operator<(Point a, Point b) { return a.x < b.x; } ll dist(Point a, Point b) { return abs(a.x-b.x) + abs(a.y-b.y); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; ll ans = 0; vector<Point> pkt; for(int i=0; i<2*n; ++i) { Point p; cin >> p.x >> p.y; if(p.y > 1) { ans += p.y-2; p.y = 2; } else { ans += 1-p.y; p.y = 1; } pkt.push_back(p); } sort(pkt.begin(), pkt.end()); for(int i=n; i>=1; --i) { Point p1 = pkt.back(); pkt.pop_back(); Point p2 = pkt.back(); pkt.pop_back(); ll d1 = dist(p1, {i, 1})+dist(p2, {i, 2}); ll d2 = dist(p1, {i, 2})+dist(p2, {i, 1}); ans += min(d1, d2); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...