Submission #860975

#TimeUsernameProblemLanguageResultExecution timeMemory
860975NeroZeinCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms600 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n;//1 -> n, 1 -> 2 cin >> n; n *= 2; vector<int> x(n), y(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } long long ans = 0; vector<vector<int>> p(n / 2 + 1, vector<int> (3)); for (int i = 0; i < n; ++i) { int nxtx = 0, nxty = 0; if (1 <= x[i] && x[i] <= n / 2) { nxtx = x[i]; } else if (x[i] < 1) { nxtx = 1; } else { nxtx = n / 2; } if (y[i] <= 1) { nxty = 1; } else { nxty = 2; } ans += abs(x[i] - nxtx); ans += abs(y[i] - nxty); p[nxtx][nxty]++; } vector<pair<int, int>> f; vector<pair<int, int>> t; for (int i = 1; i <= n / 2; ++i) { for (int j = 1; j <= 2; ++j) { if (p[i][j] > 1) { for (int k = 1; k < p[i][j]; ++k) { f.emplace_back(i, j); } } else if (p[i][j] == 0) { t.emplace_back(i, j); } } } sort(f.begin(), f.end()); sort(t.begin(), t.end()); assert(t.size() == f.size()); for (int i = 0; i < (int) t.size(); ++i) { ans += abs(t[i].first - f[i].first); ans += abs(t[i].second - f[i].second); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...