// noi19a extraction - computes answer, encodes a selected value into dirty pages
// FIELD: 0=answer, 1=n, 2=m, 3=A, 4=B, 5=C
// DIGIT: base-10000 digit. OFFSET = constant pages.
#define FIELD 4
#define DIGIT 1
#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);
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 == 0
val = ans;
#elif FIELD == 1
val = n;
#elif FIELD == 2
val = m;
#elif FIELD == 3
val = A;
#elif FIELD == 4
val = B;
#elif FIELD == 5
val = C;
#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 | 355.16 us | 3 MB + 968 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 345.93 us | 3 MB + 968 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 345.73 us | 3 MB + 968 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 348.83 us | 3 MB + 968 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 959.47 us | 4 MB + 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 1.029 ms | 4 MB + 88 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 1.024 ms | 4 MB + 80 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 1.057 ms | 4 MB + 96 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 1.012 ms | 4 MB + 84 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 937.31 us | 4 MB + 96 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 977.44 us | 4 MB + 136 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 1.03 ms | 4 MB + 352 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 1.003 ms | 4 MB + 240 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 1.024 ms | 4 MB + 108 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 36.27 ms | 10 MB + 500 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 35.507 ms | 10 MB + 560 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 33.591 ms | 10 MB + 112 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 29.786 ms | 9 MB + 452 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 45.082 ms | 11 MB + 104 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 31.593 ms | 9 MB + 672 KB | Accepted | Score: 5 | 显示更多 |