# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105498 | salmon | Coin Collecting (JOI19_ho_t4) | C++14 | 47 ms | 7388 KiB |
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>
using namespace std;
int N;
int lst[200100][3];
vector<pair<int,int>> v;
int h1,h2;
long long int ans = 0;
int main(){
scanf(" %d",&N);
for(int i = 1; i <= N; i++){
lst[i][1] = 0;
lst[i][2] = 0;
}
for(int i = 0; i < N * 2; i++){
scanf(" %d",&h1);
scanf(" %d",&h2);
if(h2 >= 2){
ans += h2 - 2;
h2 = 2;
}
else{
ans += 1 - h2;
h2 = 1;
}
if(h1 < 1){
ans += 1 - h1;
h1 = 1;
}
if(h1 > N){
ans += h1 - N;
h1 = N;
}
lst[h1][h2]++;
}
int num = 0;
long long int num1 = 0;
for(int i = 1; i <= N; i++){
num += lst[i][1] - 1;
num1 += lst[i][2] - 1;
if(num * num1 < 0){
ans += min(abs(num),(int)abs(num1));
int temp = min(abs(num),(int)abs(num1));
num -= num/abs(num) * temp;
num1 -= num1/abs(num1) * temp;
}
ans += abs(num) + abs(num1);
}
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |