This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//GOAL : BECOME A MASTER
//cf : Mali
//Toktarbek Muhammedali 10B
//Esyk BIL
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fast() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define F first
#define S second
const int N = 2e5 + 10;
// const long long INF = 1e18 + 1;
// const int mod = 1e9 + 7;
using namespace std;
int a[N] , b[N];
void goat(){
int n;
cin >> n;
int l , r , x , y , ans = 0;
for (int i = 1 ; i <= 2*n ; i ++){
cin >> r >> l;
if (l <= 1)x = 1;
else x = 2;
//
if (r <= 1)y = 1;
else if (r >= n)y = n;
else y = r;
// if (abs(r - 1) >= abs(r - n))r = n;
// else r = 1;
//
if (x == 1)a[y]++;
else b[y]++;
ans += abs(abs(x - l) + abs(y - r));
// cout << x << ' ' << y << endl;
}
int cr1 = 0 , cr2 = 0;
for (int i = 1 ; i <= n ; i ++){
cr1 += a[i]-1;
cr2 += b[i]-1;
while (cr1 > 0 && cr2 < 0){
ans++;
cr1--;
cr2++;
}
while (cr1 < 0 && cr2 > 0){
ans++;
cr1++;
cr2--;
}
ans += abs(cr1 + cr2);
}
cout << ans << endl;
}
signed main () {
fast();
///S
//E W
///N
// freopen("B.in", "r", stdin);
// freopen("B.out", "w", stdout);
// int T;
// cin >> T;
// for (int i = 1 ; i <= T ; i ++){
goat();
// }
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |