/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
#define pii pair < ll, ll >
using namespace std;
const int N = 4e5 + 5;
const int lg = 21;
int n;
pii x[N];
main() {
//file("pieaters");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n * 2; i++) {
cin >> x[i].first >> x[i].second;
}
srand(time(0));
int z = rand() % 1000 + 1;
while(z--) random_shuffle(x + 1, x + n * 2 + 1);
vector < pii > v;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= 2; j++) {
v.pb({i, j});
}
}
sort(all(v));
long long ans = 1e18;
for(int timer = 1; timer <= 500000; timer++) {
next_permutation(all(v));
long long res = 0;
for(int i = 0; i < v.size(); i++) {
res += abs(v[i].first - x[i + 1].first) + abs(v[i].second - x[i + 1].second);
}
ans = min(ans, res);
}
cout << ans;
}
Compilation message
joi2019_ho_t4.cpp:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
23 | main() {
| ^~~~
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Incorrect |
18 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Incorrect |
18 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Incorrect |
18 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |