Submission #204141

#TimeUsernameProblemLanguageResultExecution timeMemory
204141LifeHappen__Coin Collecting (JOI19_ho_t4)C++14
100 / 100
75 ms8316 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct pack { int x, y; bool operator < (pack a) { return make_pair(x, y) < make_pair(a.x, a.y); } }; const int N = 1e5 + 5; int n, f[N][5], d[N][5], sum[N]; pack a[2 * N]; main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("tpa.txt", "r", stdin); cin >> n; for(int i = 1; i <= 2 * n; ++i) { cin >> a[i].x >> a[i].y; } int ans = 0; for(int i = 1; i <= 2 * n; ++i) { int X, Y; X = a[i].x, Y = a[i].y; X = max(X, 1ll); X = min(X, n); Y = max(Y, 1ll); Y = min(Y, 2ll); ans += abs(a[i].x - X) + abs(a[i].y - Y); f[X][Y]++; } for(int i = 1; i <= n; ++i) { ans += abs(sum[1]); ans += abs(sum[2]); sum[1] += f[i][1] - 1; sum[2] += f[i][2] - 1; while(sum[1] > 0 && sum[2] < 0) { sum[1]--; sum[2]++; ans++; } while(sum[1] < 0 && sum[2] > 0) { sum[1]++; sum[2]--; ans++; } } cout << ans; }

Compilation message (stderr)

joi2019_ho_t4.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...