#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
#include <numeric>
#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppi pair<int,pair<int,int>>
#define int int64_t
using namespace std;
// /\_/\
// (= ._.)
// / > \>
// encouraging cat
const int INF = 10000000000000000;
//const int mod = 1000000007;
const int mod = 998244353;
const int MAXN = 200005;
//ifstream fin('xor.in');
//ofstream fout('xor.out');
signed main()
{
int n;
cin >> n;
int x,y;
int xx,yy;
int res = 0;
vector<vector<int>> a(n + 10,vector<int> (2,0));
for (int i = 1; i <= 2*n; i++)
{
cin >> x >> y;
if (y <= 1)
yy = 1;
else
yy = 2;
if (x < 1)
xx = 1;
else if (x > n)
xx = n;
else
xx = x;
a[xx][yy]++;
res += abs(x-xx)+abs(y-yy);
}
x = y = 0;
for (int i = 1; i <= n; i++) {
x += a[i][1]-1;
y += a[i][2]-1;
while (x < 0 && y > 0)
{
x++;
y--;
res++;
}
while (x > 0 && y < 0)
{
x--;
y++;
res++;
}
res += abs(x) + abs(y);
}
cout << res << '\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... |