Submission #720989

#TimeUsernameProblemLanguageResultExecution timeMemory
720989PringCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 200005; int N, n, ans, c[MXN][2]; pii a[MXN]; int DIS(pii &a, pii &b) { return abs(a.first - b.first) + abs(a.second - b.second); } void PUT(int id) { pii tr; tr.second = (a[id].second >= 2 ? 2 : 1); if (1 <= a[id].first && a[id].first <= n) tr.first = a[id].first; else tr.first = (a[id].first < 1 ? 1 : n); c[tr.first][tr.second - 1]++; ans += DIS(tr, a[id]); } void SOLVE() { int up = 0, down = 0; for (int i = 1; i <= n; i++) { up += c[i][1]; down += c[i][0]; } ans += abs(n - up); int left = 0, right = N; for (int i = 1; i < n; i++) { left += (c[i][0] + c[i][1]); right -= (c[i][0] + c[i][1]); ans += abs(i * 2 - left); } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; N = n * 2; for (int i = 0; i < N; i++) { cin >> a[i].first >> a[i].second; PUT(i); } // for (int j = 1; j >= 0; j--) { // for (int i = 1; i <= n; i++) { // cout << c[i][j] << ' '; // } // cout << endl; // } SOLVE(); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...