Submission #98230

#TimeUsernameProblemLanguageResultExecution timeMemory
98230scanhexCoin Collecting (JOI19_ho_t4)C++17
0 / 100
4 ms640 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]); } int ptr=0; for(int i=0;i<n;++i){ for(int j=0;j<cnt[i][1];++j)++ptr; while(cnt[i][0]&&ptr<=i&&sum1>0)--cnt[i][0],--sum1,++ptr,++ansich,++cnt[i][1]; } for(int k=0;k<2;++k){ int ptr=0; for(int i=0;i<n;++i){ for(int j=0;j<cnt[i][k];++j)ansich+=abs(ptr-i),++ptr; } assert(ptr==n); } cout<<ansich<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...