Submission #915018

#TimeUsernameProblemLanguageResultExecution timeMemory
915018yhkhooCoin Collecting (JOI19_ho_t4)C++17
100 / 100
36 ms5800 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; ll ans=0; int c[n][2]; memset(c, 0, n*2*sizeof(int)); for(int i=0; i<2*n; i++){ int x, y; cin >> x >> y; x--; y--; bool sid; if(y<=0){ ans += 0-y; sid = 0; } else{ ans += y-1; sid = 1; } if(x<0){ ans += 0-x; c[0][sid]++; } else if(x>=n){ ans += x-(n-1); c[n-1][sid]++; } else{ c[x][sid]++; } } int d0=0, d1=0; for(int i=0; i<n; i++){ d0 += c[i][0]-1; d1 += c[i][1]-1; if(d0 < 0 && d1 > 0){ int sw = min(-d0, d1); ans += sw; d0 += sw; d1 -= sw; } if(d1 < 0 && d0 > 0){ int sw = min(d0, -d1); ans += sw; d0 -= sw; d1 += sw; } ans += abs(d0); ans += abs(d1); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...