#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn = 1e5+10;
int mat[maxn][3];
int main(){
int n;
cin >> n;
long long ans=0;
vector<pii> fila, coins;
for(int i=1; i<=2*n; i++){
int x, y;
cin >> x >> y;
if(x<1){
if(y>=2){
mat[1][2]++;
ans+=abs(x-1)+abs(y-2);
}
else{
mat[1][1]++;
ans+=abs(x-1)+abs(y-1);
}
}
if(x>=1 and x<=n){
if(y>=2){
ans+=abs(y-2);
mat[x][2]++;
}
else{
ans+=abs(y-1);
mat[x][1]++;
}
}
if(x>n){
if(y>=2){
mat[n][2]++;
ans+=abs(x-n)+abs(y-2);
}
else{
mat[n][1]++;
ans+=abs(x-n)+abs(y-1);
}
}
}
for(int i=2; i>=1; i--){
for(int j=1; j<=n; j++){
if(mat[j][i]==0){
fila.push_back({j, i});
}
while(mat[j][i]>1){
mat[j][i]--;
coins.push_back({j, i});
}
}
}
sort(fila.begin(), fila.end());
reverse(fila.begin(), fila.end());
sort(coins.begin(), coins.end());
reverse(coins.begin(), coins.end());
for(int i=0; i<fila.size(); i++){
ans += abs(fila[i].first-coins[i].first) + abs(fila[i].second-coins[i].second);
}
cout << ans << endl;
return 0;
}
Compilation message
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:76:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<fila.size(); i++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |