Submission #533710

#TimeUsernameProblemLanguageResultExecution timeMemory
533710alvingogoCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms308 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define AquA cin.tie(0);ios_base::sync_with_stdio(0); #define fs first #define sc second #define cd complex<double> #define p_q priority_queue using namespace std; int main(){ AquA; int n; cin >> n; vector<int> a(n,-1),b(n,-1); long long ans=0; for(int i=0;i<2*n;i++){ int x,y; cin >> x >> y; int c=max(1,min(x,n)),d=max(1,min(y,2)); ans+=abs(c-x)+abs(d-y); if(y==1){ a[c-1]++; } else{ b[c-1]++; } } int e=0,f=0; for(int i=0;i<n;i++){ e+=a[i]; f+=b[i]; if(e>0 && f<0){ int y=min(abs(e),abs(f)); e-=y; f+=y; ans+=y; } else if(f>0 && e<0){ int y=min(abs(e),abs(f)); e+=y; f-=y; ans+=y; } ans+=abs(e); ans+=abs(f); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...