This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e15) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
EmiliaMyWife
return 48763;
}();
signed main() {
int n;
cin >> n;
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LINF));
vector<pair<ll, ll>> arr(n * 2);
for(int i = 0; i < n * 2; i++)
cin >> arr[i].first >> arr[i].second;
sort(arr.begin(), arr.end());
dp[0][0] = 0;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
int x = i + j;
if(i < n)
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + abs(arr[x].first - (i + 1)) + abs(arr[x].second - 2));
if(j < n)
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + abs(arr[x].first - (j + 1)) + abs(arr[x].second - 1));
}
}
cout << dp[n][n] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |