# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127709 | arnold518 | Coin Collecting (JOI19_ho_t4) | C++14 | 20 ms | 8312 KiB |
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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const ll INF = 1e17;
struct Point
{
ll x, y;
bool operator < (const Point& p) { return x<p.x; }
};
ll dist(Point p, Point q) { return abs(p.x-q.x)+abs(p.y-q.y); }
int N;
Point coin[2*MAXN+10];
ll dp[MAXN+10][MAXN+10];
int main()
{
int i, j;
scanf("%d", &N);
for(i=1; i<=2*N; i++) scanf("%lld%lld", &coin[i].x, &coin[i].y);
sort(coin+1, coin+2*N+1);
for(i=0; i<=N; i++) for(j=0; j<=N; j++)
{
if(i==0 && j==0) continue;
dp[i][j]=INF;
if(i!=0) dp[i][j]=min(dp[i][j], dist(coin[i+j], {i, 1})+dp[i-1][j]);
if(j!=0) dp[i][j]=min(dp[i][j], dist(coin[i+j], {j, 2})+dp[i][j-1]);
}
printf("%lld", dp[N][N]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |