比赛 |
2022级DP专题练习赛8 |
评测结果 |
AAAWAEEEEEEEEEE |
题目名称 |
Springboards |
最终得分 |
26 |
用户昵称 |
op_组撒头屯 |
运行时间 |
1.882 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2023-03-01 20:56:21 |
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=1000+5;
const ll inf=0x3f3f3f3f3f3f;
ll m,n;
ll x_1[N],y_1[N],x_2[N],y_2[N],f[N];
int main(){
freopen ("usaco_Jan_boards.in","r",stdin);
freopen ("usaco_Jan_boards.out","w",stdout);
scanf("%lld%lld",&m,&n);
for (int i=1;i<=n;i++){
scanf("%lld%lld%lld%lld",&x_1[i],&y_1[i],&x_2[i],&y_2[i]);
f[i]=inf;
}x_2[0]=y_2[0]=0;
n++;x_1[n]=y_1[n]=m;x_2[n]=y_2[n]=m+1;f[n]=inf;
for (int i=1;i<=n;i++){
for (int j=0;j<=n;j++){
if (x_2[j]<=x_1[i]&&y_2[j]<=y_1[i]){
f[i]=std::min(f[i],f[j]+(x_1[i]-x_2[j])+(y_1[i]-y_2[j]));
}
}
}
printf("%lld\n",f[n]);
}