Submission #98238

#TimeUsernameProblemLanguageResultExecution timeMemory
98238scanhexCoin Collecting (JOI19_ho_t4)C++17
0 / 100
3 ms384 KiB
#include <bits/stdc++.h> using namespace std; using nagai = long long; #define sz(x) int((x).size()) const int N=200200; int cnt[N][2]; int dist(pair<int,int>a,pair<int,int>b){ return abs(a.first-b.first)+abs(a.second-b.second); } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; nagai ansich=0; for(int i=0;i<2*n;++i){ int x,y; cin>>x>>y; int x1=x,y1=y; if(x<1)x1=1; if(x>n)x1=n; if(y<1)y1=1; if(y>2)y1=2; ansich+=abs(x-x1); ansich+=abs(y-y1); ++cnt[x1-1][y1-1]; } int sum1=-n; for(int i=0;i<n;++i)sum1+=cnt[i][0]; if(sum1<0){ sum1*=-1; for(int i=0;i<n;++i)swap(cnt[i][0],cnt[i][1]); } for(int i=0;i<n;++i){ while(cnt[i][1]>1&&cnt[i][0]<1)++cnt[i][0],--cnt[i][1],++ansich; if(cnt[i][0]<1)ansich+=(1-cnt[i][0]),cnt[i+1][0]-=(1-cnt[i][0]); if(cnt[i][0]>1)ansich+=cnt[i][0]-1,cnt[i+1][0]+=cnt[i][0]-1; if(cnt[i][1]>1)ansich+=cnt[i][1]-1,cnt[i+1][1]+=cnt[i][1]-1; } cout<<ansich<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...