#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
980 ms |
596 KB |
Output is correct |
2 |
Correct |
979 ms |
420 KB |
Output is correct |
3 |
Correct |
980 ms |
420 KB |
Output is correct |
4 |
Incorrect |
979 ms |
416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
980 ms |
596 KB |
Output is correct |
2 |
Correct |
979 ms |
420 KB |
Output is correct |
3 |
Correct |
980 ms |
420 KB |
Output is correct |
4 |
Incorrect |
979 ms |
416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
980 ms |
596 KB |
Output is correct |
2 |
Correct |
979 ms |
420 KB |
Output is correct |
3 |
Correct |
980 ms |
420 KB |
Output is correct |
4 |
Incorrect |
979 ms |
416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |