// noi19a extraction - first train's x,y,p,q (input order) for identification
// FIELD: 6=x, 7=y, 8=p, 9=q of the FIRST train line
#define FIELD 7
#define DIGIT 0
#define OFFSET 1000
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const ll INF = 4e18;
struct Train { int x,y,p,q; };
static char big[13000*4096] __attribute__((aligned(4096)));
int main(){
int n, m; ll A, B, C;
if(scanf("%d %d %lld %lld %lld",&n,&m,&A,&B,&C)!=5) return 0;
vector<Train> tr(m);
for(int i=0;i<m;i++) scanf("%d %d %d %d",&tr[i].x,&tr[i].y,&tr[i].p,&tr[i].q);
int fx = tr[0].x, fy = tr[0].y, fp = tr[0].p, fq = tr[0].q;
sort(tr.begin(), tr.end(), [](const Train&a,const Train&b){ return a.p < b.p; });
vector<vector<pair<int,ll>>> dp(n+1);
dp[1].push_back({0, 0LL});
for(const auto& t : tr){
ll best = INF;
for(const auto& pr : dp[t.x]){
int tt = pr.first; ll val = pr.second;
if(tt > t.p) break;
ll dt = t.p - tt;
ll add = A*dt*dt + B*dt + C;
ll c = val + add;
if(c < best) best = c;
}
if(best < INF){
auto& lst = dp[t.y];
auto it = lower_bound(lst.begin(), lst.end(), make_pair(t.q, (ll)-1));
if(it == lst.end() || it->first != t.q) lst.insert(it, {t.q, best});
else if(best < it->second) it->second = best;
}
}
ll ans = INF;
for(const auto& pr : dp[n]){
ll c = pr.second + pr.first;
if(c < ans) ans = c;
}
ll val = 0;
#if FIELD == 6
val = fx;
#elif FIELD == 7
val = fy;
#elif FIELD == 8
val = fp;
#elif FIELD == 9
val = fq;
#endif
for(int d=0; d<DIGIT; d++) val /= 10000;
long long code = val % 10000;
long long enc = OFFSET + code;
memset(big, 1, (size_t)(enc*4096));
printf("%lld\n", ans);
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 379.93 us | 4 MB + 252 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 363.68 us | 4 MB + 112 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 359.98 us | 4 MB + 116 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 364.64 us | 4 MB + 188 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 1.37 ms | 9 MB + 336 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 1.384 ms | 8 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 1.228 ms | 6 MB + 900 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 1.673 ms | 11 MB + 920 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 1.57 ms | 10 MB + 836 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 1.179 ms | 7 MB + 332 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 1.267 ms | 7 MB + 716 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 1.258 ms | 7 MB + 272 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 1.281 ms | 7 MB + 828 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 1.138 ms | 5 MB + 652 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 37.234 ms | 27 MB + 252 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 35.724 ms | 19 MB + 304 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 34.892 ms | 31 MB + 844 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 31.469 ms | 37 MB + 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 45.033 ms | 16 MB + 320 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 32.189 ms | 21 MB + 576 KB | Accepted | Score: 5 | 显示更多 |