| 比赛 |
寒假集训2 |
评测结果 |
AAAAAAWAAAWAAAAAAAAA |
| 题目名称 |
回家路线 |
最终得分 |
90 |
| 用户昵称 |
郑霁桓 |
运行时间 |
4.267 s |
| 代码语言 |
C++ |
内存使用 |
10.39 MiB |
| 提交时间 |
2026-02-25 11:23:15 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long as,a,b,C,dp[200005];
struct cr{
int x,y,p,q;
}c[200005];
inline bool cp(cr x,cr y){
return x.q<y.q;
}
vector<int>v[200005];
inline int read(){
int xx=0;
char ch=getchar();
while(ch<'0'||'9'<ch) ch=getchar();
while('0'<=ch&&ch<='9') xx=(xx<<1)+(xx<<3)+(ch-'0'),ch=getchar();
return xx;
}
int main(){
freopen("rout.in","r",stdin);
freopen("rout.out","w",stdout);
n=read();
m=read();
a=read();
b=read();
C=read();
for(int i=1;i<=m;i++){
c[i].x=read();
c[i].y=read();
c[i].p=read();
c[i].q=read();
}
sort(c+1,c+m+1,cp);
for(int i=1;i<=m;i++){
v[c[i].y].push_back(i);
}
as=1e18;
for(int i=1;i<=m;i++){
if(c[i].x==1) dp[i]=a*c[i].p*c[i].p+b*c[i].p+C;
else dp[i]=1e18;
for(int j=0;j<v[c[i].x].size();j++){
if(j>4000) break;
int pj=v[c[i].x][j];
if(c[i].p<c[pj].q) break;
int ds=c[i].p-c[pj].q;
dp[i]=min(dp[i],dp[pj]+a*ds*ds+b*ds+C);
}
if(c[i].y==n) as=min(as,dp[i]+c[i].q);
}
cout<<as<<"\n";
return 0;
}