이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e18;
pair<int, int> a[100001];
int dp[4000][2000];
signed main()
{
int n;
cin >> n;
for(int i = 0; i < 2 * n; i++)
{
cin >> a[i].first >> a[i].second;
}
sort(a, a + 2 * n);
for(int i = 1; i <= n; i++)
{
dp[0][i] = N;
}
dp[0][0] = 0;
for(int i = 1; i <= 2 * n; i++)
{
for(int j = 0; j <= n; j++)
{
dp[i][j] = N;
}
for(int j = max(0LL, i - n); j <= i && j <= n; j++)
{
dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(a[i - 1].first - i + j) + abs(a[i - 1].second - 1));
if(j)
{
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + abs(a[i - 1].first - j) + abs(a[i - 1].second - 2));
}
}
}
cout << dp[n * 2][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... |