Submission #532041

#TimeUsernameProblemLanguageResultExecution timeMemory
532041syl123456Coin Collecting (JOI19_ho_t4)C++17
100 / 100
91 ms10384 KiB
#include <bits/stdc++.h> #define all(i) (i).begin(), (i).end() using namespace std; template<typename T1, typename ...T2> void debug(bool _split, T1 i, T2 ...j) { if (_split) cerr << ", "; cerr << i; debug(true, j...); } #define debug(args...) cout << "Line" << __LINE__ << " : [" << #args << << "] is [" << debug(false, args) << "]" << endl; typedef pair<int, int> pi; typedef long long ll; const int inf = 0x3f3f3f3f, lg = 20; const ll mod = 1e9 + 7, INF = 0x3f3f3f3f; signed main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; ll ans = 0; vector<vector<int>> a(n + 1, vector<int>(2, -1)); for (int i = 0; i < 2 * n; ++i) { int x, y; cin >> x >> y; if (x < 1) ans += 1 - x, x = 1; if (x > n) ans += x - n, x = n; if (y < 1) ans += 1 - y, y = 1; if (y > 2) ans += y - 2, y = 2; --x, --y; ++a[x][y]; } for (int i = 0; i < n; ++i) { if (a[i][0] > 0 && a[i][1] < 0) { int x = min(a[i][0], -a[i][1]); a[i][0] -= x, a[i][1] += x; ans += x; } else if (a[i][0] < 0 && a[i][1] > 0) { int x = min(-a[i][0], a[i][1]); a[i][0] += x, a[i][1] -= x; ans += x; } a[i + 1][0] += a[i][0], a[i + 1][1] += a[i][1]; ans += abs(a[i][0]) + abs(a[i][1]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...