Submission #704111

#TimeUsernameProblemLanguageResultExecution timeMemory
7041111075508020060209tcCoin Collecting (JOI19_ho_t4)C++14
37 / 100
953 ms50032 KiB
//#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int n; pair<int,int>ar[500005]; int dp[2010][1010]; int cst(pair<int,int>pt,int x,int y){ return abs(pt.X-x)+abs(pt.Y-y); } signed main(){ cin>>n; for(int i=1;i<=n+n;i++){ cin>>ar[i].X>>ar[i].Y; } for(int i=0;i<=2000;i++){ for(int j=0;j<=1000;j++){ dp[i][j]=1e16; } } sort(ar+1,ar+n+n+1); dp[1][0]=cst(ar[1],1,1); dp[1][1]=cst(ar[1],1,2); for(int i=1;i<=n+n;i++){ for(int j=0;j<=n;j++){ dp[i+1][j]=min(dp[i+1][j],dp[i][j]+cst(ar[i+1],i+1-j,1)); dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+cst(ar[i+1],j+1,2)); } } cout<<dp[n+n][n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...