Submission #481625

#TimeUsernameProblemLanguageResultExecution timeMemory
481625RainbowbunnyCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n; long long ans, cnt; long long X[MAXN], Y[MAXN]; vector <long long> V; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= 2 * n; i++) { cin >> X[i] >> Y[i]; if(X[i] <= 0) { ans += (1 - X[i]); X[i] = 1; } if(X[i] > n) { ans += (X[i] - n); X[i] = n; } if(X[i] >= 1 and X[i] <= n) { if(Y[i] <= 1) { ans -= (Y[i] - 1); cnt++; } else { ans += (Y[i] - 2); } V.push_back(X[i]); } } sort(V.begin(), V.end()); ans += abs(cnt - n); for(int i = 0; i < (int)V.size(); i += 2) { ans += abs(V[i] - i / 2 - 1); ans += abs(V[i + 1] - i / 2 - 1); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...