Submission #573527

#TimeUsernameProblemLanguageResultExecution timeMemory
573527Rafi22Coin Collecting (JOI19_ho_t4)C++14
100 / 100
59 ms6448 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; const int N=100007; int a[N][2]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,x,y; cin>>n; ll ans=0; for(int i=1;i<=2*n;i++) { cin>>x>>y; bool b; if(y>1) { ans+=y-2; b=1; } else { ans+=1-y; b=0; } if(x<1) { ans+=1-x; a[1][b]++; } else if(x>n) { ans+=x-n; a[n][b]++; } else { a[x][b]++; } } for(int i=1;i<=n;i++) { a[i][0]--,a[i][1]--; if(a[i][0]>0&&a[i][1]<0) { int x=min(a[i][0],-a[i][1]); ans+=x; a[i][0]-=x; a[i][1]+=x; } if(a[i][0]<0&&a[i][1]>0) { int x=min(-a[i][0],a[i][1]); ans+=x; a[i][0]+=x; a[i][1]-=x; } ans+=abs(a[i][0])+abs(a[i][1]); a[i+1][0]+=a[i][0]; a[i+1][1]+=a[i][1]; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...