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>
#define pb push_back
#define ins isnert
#define pii pair<int,int>
#define ff first
#define ss second
#define loop(i,a,b) for(int i = (a); i < (b); i ++)
#define op(x) cerr << #x << " = " << x << endl;
#define opa(x) cerr << #x << " = " << x << ", ";
#define ops(x) cerr << x;
#define spac cerr << ' ';
#define entr cerr << endl;
#define STL(x) cerr << #x << " : "; for(auto &qwe:x) cerr << qwe << ' '; cerr << endl;
#define ARR(x, nnn) cerr << #x << " : "; loop(qwe,0,nnn) cerr << x[qwe] << ' '; cerr << endl;
#define BAE(x) (x).begin(), (x).end()
#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
pii a[30], b[30];
int main(){
int n, m;
cin >> n;
m = n << 1;
loop(i,0,m) cin >> a[i].ff >> a[i].ss;
loop(i,0,n){
b[i] = {i + 1, 1};
b[i + n] = {i + 1, 2};
}
sort(b, b + m);
long long ans = (ll)(1e18), tmp;
do{
shuffle(b, b + m, RNG);
tmp = 0;
loop(i,0,m){
tmp += abs(a[i].ff - b[i].ff);
tmp += abs(a[i].ss - b[i].ss);
}
ans = min(ans, tmp);
}while((long double)clock() / CLOCKS_PER_SEC <= 0.98);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |