Submission #778753

#TimeUsernameProblemLanguageResultExecution timeMemory
778753DobromirAngelovCoin Collecting (JOI19_ho_t4)C++14
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN=1e5+5; int n; int cnt[2][MAXN]; long long ans=0; void add(int t,int x) { if(x<1) { ans+=1-x; cnt[t][1]++; } else if(x>n) { ans+=x-n; cnt[t][n]++; } else cnt[t][x]++; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1; i<=2*n; i++) { int x,y; cin>>x>>y; if(y<=1) { add(0,x); ans+=1-y; } else { add(1,x); ans+=y-2; } } int r0=0,r1=0; for(int i=1; i<=n; i++) { r0+=cnt[0][i]; r1+=cnt[1][i]; ans+=abs(r0+r1-2*i); } ans+=abs(r0-r1)/2; cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...