// 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 9
#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 | 467.9 us | 5 MB + 456 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 407.64 us | 4 MB + 712 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 418.49 us | 4 MB + 840 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 438.66 us | 5 MB + 100 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 1.199 ms | 7 MB + 256 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 1.11 ms | 5 MB + 440 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 1.008 ms | 4 MB + 188 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 1.278 ms | 7 MB + 260 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 1.251 ms | 7 MB + 276 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 1.083 ms | 6 MB + 116 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 1.172 ms | 6 MB + 716 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 1.17 ms | 6 MB + 204 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 1.062 ms | 5 MB + 204 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 1.175 ms | 6 MB + 152 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 36.018 ms | 13 MB + 392 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 35.195 ms | 13 MB + 232 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 33.057 ms | 11 MB + 72 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 29.272 ms | 10 MB + 488 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 44.688 ms | 12 MB + 868 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 31.383 ms | 12 MB + 532 KB | Accepted | Score: 5 | 显示更多 |