Submission #110957

#TimeUsernameProblemLanguageResultExecution timeMemory
110957oolimryCoin Collecting (JOI19_ho_t4)C++14
100 / 100
88 ms4344 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> ii; int main() { //freopen("i.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(0); long long ans = 0ll; int n; cin >> n; long long arr[n][2]; for(int i = 0;i < n;i++){ arr[i][0] = 0; arr[i][1] = 0; } for(int i = 0;i < 2 * n;i++){ long long x, y; cin >> x >> y; if(x <= 1){ if(y <= 1){ arr[0][0]++; ans += abs(y-1) + abs(x-1); } else{ arr[0][1]++; ans += abs(y-2) + abs(x-1); } } else if(x >= n){ if(y <= 1){ arr[n-1][0]++; ans += abs(y-1) + abs(x-n); } else{ arr[n-1][1]++; ans += abs(y-2) + abs(x-n); } } else{ if(y <= 1){ arr[x-1][0]++; ans += abs(y-1); } else{ arr[x-1][1]++; ans += abs(y-2); } } } for(int i = 0;i < n - 1;i++){ long long x = arr[i][0]; long long y = arr[i][1]; //cout << x << " " << y << " "; long long ds[3] = {0ll, x - 1, 1 - y}; ii d = ii(1203123214213,-1); for(int j = 0;j < 3;j++){ d = min(d, ii(abs(ds[j]) + abs(x-ds[j]-1) + abs(y+ds[j]-1),ds[j])); } //cout << d.first << " " << d.second << "\n"; ans += d.first; arr[i][0] -= d.second; arr[i][1] += d.second; arr[i+1][0] += (arr[i][0] - 1); arr[i+1][1] += (arr[i][1] - 1); } ans += abs(arr[n-1][0] - 1); //ans += abs(arr[n-1][0] - 1); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...