#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#define F first
#define S second
#define PB push_back
using namespace std;
const long long MOD=1e9+7, INF=1e18;
const int INFI=1e9;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<pair<int, ii>> viii;
typedef vector<vii> vvii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
bool vis[2005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
if(n>1000) return 0;
vii coords(2*n+1);
vvll dist(n+1, vll(3, INF));
vector<pair<ll, pair<int, ii>>> ar;
memset(vis, false, 2*n+2);
for(int i=1;i<=2*n;i++) cin>>coords[i].F>>coords[i].S;
for(int i=1;i<=2*n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=2;k++)
ar.PB({abs(coords[i].F-j)+abs(coords[i].S-k), {i, {j, k}}});
sort(ar.begin(), ar.end());
for(int i=0;i<ar.size();i++){
ll dis=ar[i].F;
int from=ar[i].S.F, x=ar[i].S.S.F, y=ar[i].S.S.S;
if(dist[x][y]!=INF || vis[from]) continue;
vis[from]=true;
dist[x][y]=dis;
}
ll ans=0;
for(int j=1;j<=n;j++)
for(int i=1;i<=2;i++)
ans+=dist[j][i];
cout<<ans<<endl;
return 0;
}
Compilation message
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, std::pair<int, int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0;i<ar.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |