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>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
ll n;
vll X, Y;
cin >> n;
ll re = 0;
vector<array<ll, 2> > A(n, {0, 0});
for(ll i = 0; i < 2 * n; ++i) {
ll x, y;
cin >> x >> y;
if(x < 1) {
re += 1 - x;
x = 1;
}
if(x > n) {
re += x - n;
x = n;
}
if(y < 1) {
re += 1 - y;
y = 1;
}
if(y > 2) {
re += y - 2;
y = 2;
}
A[x-1][y-1]++;
}
ll a = 0, b = 0;
for(ll i = 0; i < n; ++i) {
a += A[i][0];
b += A[i][1];
--a;
--b;
while(a * b < 0) { /// semne diferite
++re;
if(a < 0) {
++a;
--b;
} else {
--a;
++b;
}
}
re += abs(a) + abs(b);
}
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... |