#include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
template <class Int> inline void read(Int& x) {
x = 0; char ch = getchar(); int f = 1;
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
x *= f;
}
struct train {
int x, y, p, q;
bool operator<(const train& rhs) const { return (x < rhs.x) || (x == rhs.x && p < rhs.p); }
} t[N];
struct subway {
int y, p, q;
subway() {}
subway(int y, int p, int q) : y(y), p(p), q(q) {}
};
struct arrival {
int u;
ll d, q;
arrival() {}
arrival(int u, ll d, ll q) : u(u), d(d), q(q) {}
};
int n, m;
ll A, B, C;
vector<subway> sub[N];
vector<arrival> f;
inline ll calc(ll x) { return A * x * x + B * x + C; }
int main() {
read(n), read(m), read(A), read(B), read(C);
for (int i = 1; i <= m; ++i) {
read(t[i].x), read(t[i].y), read(t[i].p), read(t[i].q);
}
sort(t + 1, t + m + 1);
for (int i = 1; i <= m; ++i) sub[t[i].x].push_back(subway(t[i].y, t[i].p, t[i].q));
queue<arrival> q;
q.push(arrival(1, 0, 0));
while (!q.empty()) {
arrival a = q.front(); q.pop();
for (int i = 0; i < sub[a.u].size(); ++i) {
subway tr = sub[a.u][i];
if (a.q > tr.p) continue;
arrival nxt(tr.y, a.d + calc(tr.p - a.q), tr.q);
if (tr.y == n) f.push_back(nxt);
q.push(nxt);
}
}
ll ret = 1e18;
for (int i = 0; i < f.size(); ++i) {
ret = min(ret, f[i].d + f[i].q);
}
printf("%lld\n", ret);
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 788.62 us | 4 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 793.41 us | 4 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 796.27 us | 4 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 774.37 us | 4 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 1.279 ms | 4 MB + 780 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 1.299 ms | 4 MB + 844 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 1.317 ms | 4 MB + 808 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 1.293 ms | 4 MB + 832 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 1.286 ms | 4 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 1.167 ms | 4 MB + 780 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 1.227 ms | 4 MB + 780 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 1.342 ms | 4 MB + 812 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 1.317 ms | 4 MB + 784 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 1.631 ms | 4 MB + 900 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 1 s | 218 MB + 360 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #16 | 1 s | 306 MB + 876 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #17 | 231.014 ms | 26 MB + 736 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 27.714 ms | 11 MB + 356 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 333.49 ms | 562 MB + 784 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 31.186 ms | 11 MB + 508 KB | Accepted | Score: 5 | 显示更多 |