Submission #1116042

#TimeUsernameProblemLanguageResultExecution timeMemory
1116042Dan4LifeCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = (int)2e3+10; const int LINF = (int)2e18; int n, dp[N][N]; array<int,2> a[2][N], loc[N]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; n*=2; for(int i = 1; i <= n; i++) cin >> loc[i][0] >> loc[i][1]; sort(loc,loc+n); for(int i = 1; i <= n/2; i++) a[0][i] = {i,1}, a[1][i] = {i,2}; for(int i = 0; i <= n/2; i++) for(int j = 0; j <= n/2; j++) dp[i][j]=LINF; 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(i-loc[i+j][0])+abs(1-loc[i+j][1])); if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] +abs(i-loc[i+j][0])+abs(2-loc[i+j][1])); } } cout << dp[n/2][n/2] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...