Submission #1247932

#TimeUsernameProblemLanguageResultExecution timeMemory
1247932vlomaczkCoin Collecting (JOI19_ho_t4)C++20
100 / 100
75 ms5704 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<vector<int>> mapa(n+1, vector<int>(3)); 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; } if(p.x < 1) { ans += 1-p.x; p.x = 1; } if(p.x > n) { ans += p.x-n; p.x = n; } mapa[p.x][p.y]++; } /*cout << ans << "\n"; for(int j=1; j<=2; ++j) { for(int i=1; i<=n; ++i) { cout << mapa[i][j] << " "; } cout << "\n"; }*/ ll a=0, b=0, c=0; for(int i=1; i<=n; ++i) { a += abs(b) + abs(c); b += mapa[i][1] - 1; c += mapa[i][2] - 1; if(b > 0) { int moge_dac = b; int moge_wziac = max(0LL, -c); b -= min(moge_dac, moge_wziac); c += min(moge_dac, moge_wziac); a += min(moge_dac, moge_wziac); } else if(c > 0) { int moge_dac = c; int moge_wziac = max(0LL, -b); c -= min(moge_dac, moge_wziac); b += min(moge_dac, moge_wziac); a += min(moge_dac, moge_wziac); } //cout << i << ": " << a << " " << b << " " << c << "\n"; } ans += a; cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...