比赛 |
20161223 |
评测结果 |
AAAAAAAAAA |
题目名称 |
萌化大革命 |
最终得分 |
100 |
用户昵称 |
confoo |
运行时间 |
0.218 s |
代码语言 |
C++ |
内存使用 |
15.87 MiB |
提交时间 |
2016-12-23 19:47:42 |
显示代码纯文本
//sro FarmerJohn orz
#include <cstdio>
#include <algorithm>
#include <cstring>
#define file(x) "checklist." #x
using std::min;
typedef long long ll;
const int V = 1010;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct P{int x, y;}h[V], g[V];
inline int sq(int x) {return x*x;}
inline int cost(P& a, P& b) {return sq(a.x - b.x) + sq(a.y - b.y);}
ll f[V][V][2];
int n, m;
int main() {
freopen(file(in), "r", stdin);
freopen(file(out), "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d%d", &h[i].x, &h[i].y);
for (int i = 1; i <= m; i++) scanf("%d%d", &g[i].x, &g[i].y);
memset(f, 0x3f, sizeof(f));
// f[0][0][0] = f[0][0][1] = f[1][0][0] = f[0][1][1] = 0;
f[1][0][0] = 0;
for (int i = 2; i <= n; i++) f[i][0][0] = f[i - 1][0][0] + cost(h[i], h[i - 1]);
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
f[i][j][0] = min(f[i - 1][j][0] + cost(h[i - 1], h[i]), f[i][j][0]);
f[i][j][0] = min(f[i - 1][j][1] + cost(g[j], h[i]), f[i][j][0]);
f[i][j][1] = min(f[i][j - 1][0] + cost(h[i], g[j]), f[i][j][1]);
f[i][j][1] = min(f[i][j - 1][1] + cost(g[j - 1], g[j]), f[i][j][1]);
}
// for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) printf("f[%d][%d] : %lld %lld\n", i, j, f[i][j][0] == INF ? -1 : f[i][j][0], f[i][j][1] == INF ? -1: f[i][j][1]);
printf("%lld", f[n][m][0]);
}