This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
ll solve(vi &V, int st, int dr, int delta) {
ll re = 0;
for(auto &it : V) {
if(it < st) {
re += st - it;
it = st;
}
if(it > dr) {
re += it - dr;
it = dr;
}
}
sort(all(V));
int p = 0;
for(int i = st; i < dr; ++i) {
///bara dintre i si i + 1
while(p < sz(V) && V[p] <= i) ++p;
re += abs(p - delta * (i - st + 1));
}
return re;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
vi X, Y;
cin >> n;
for(int i = 0; i < 2 * n; ++i) {
int x, y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
ll re = solve(X, 1, n, 2) + solve(Y, 1, 2, n);
cout << re << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |