Submission #559952

#TimeUsernameProblemLanguageResultExecution timeMemory
559952karriganCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms328 KiB
#include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr); using namespace std; const int maxn=1e6; using ll=long long int; int a[100009][3]; struct lena{ int x,y; }; bool cmp(const lena &p, const lena &q){ return ((p.x<q.x)||(p.x==q.x&&p.y<q.y)); } int main() { fastio //freopen(".INP","r",stdin); //freopen(".OUT","w",stdout); //solve(); int n; cin>>n; long long ans=0; for (int i=1;i<=n*2;i++){ long long x,y; cin>>x>>y; long long x2,y2; if (x>=n)x2=n; else if (x<=1)x2=1; else x2=x; if (y>=2)y2=2; else y2=1; ans=ans+abs(x-x2)+abs(y-y2); a[x2][y2]++; //cout<<x2<<" "<<y2<<'\n'; } vector<lena>lp; for (int i=1;i<=n;i++){ for (int j=1;j<=2;j++){ if (a[i][j]>1)lp.push_back({i,j}); } } for (int i=1;i<=n;i++){ for (int j=1;j<=2;j++){ if (a[i][j]==0){ int x=1e9,y=1e9; for (int k=0;k<(int)lp.size();k++){ int u=lp[k].x,v=lp[k].y; if (a[u][v]>1&&abs(i-x)+abs(j-y)>abs(i-u)+abs(j-v)){ x=u; y=v; } } ans=ans+abs(i-x)+abs(j-y); a[x][y]--; } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...