Submission #889933

#TimeUsernameProblemLanguageResultExecution timeMemory
889933vjudge1Coin Collecting (JOI19_ho_t4)C++17
8 / 100
3 ms4444 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int N=501; ll dp[N][N]; int main() { int n; cin>>n; n*=2; vector<pair<ll, ll>> a(n); for(int i=0; i<n; i++) { cin>>a[i].first>>a[i].second; } sort(a.begin(), a.end()); for (int i=0; i<=n/2; i++){ fill(dp[i], dp[i] + N, 1e18); } dp[0][0]=0; for(int i=0; i<=n/2; i++){ for (int j=0; j<=n/2; j++) { if(i){ dp[i][j]=min(dp[i][j], dp[i-1][j] + abs(a[i+j-1].first-i)+abs(a[i+j-1].second-1)); } if(j){ dp[i][j]=min(dp[i][j],dp[i][j-1]+abs(a[i+j-1].first-j)+abs(a[i+j-1].second-2)); } } } cout<<dp[n/2][n/2]<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...