提交记录 9819


用户 题目 状态 得分 用时 内存 语言 代码长度
evenbao noi19a. 【NOI2019】回家路线 Accepted 100 464.944 ms 498540 KB C++ 2.72 KB
提交时间 评测时间
2019-07-16 17:13:58 2020-08-01 01:54:07
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 100005, maxt = 1005, INF = 2147483647;
int n, m, A, B, C, T, val[maxn], f[maxn][maxt];
bool vis[maxn][maxt];
struct Route { int x, p, q; };
vector<Route> vec[maxn];
namespace Solve1 {
    inline void solve() {
        for (register int i = 0; i <= T; i++) f[1][i] = val[i];
        for (register int i = 2; i <= n; i++)
            for(register int j = 0; j <= T; j++) f[i][j] = INF;
        vector<Route>::iterator it;
        for (register int i = 2; i <= n; i++) {
            for (it = vec[i].begin(); it != vec[i].end(); it++) {
                register int x = it->x, p = it->p, q = it->q;
                if (f[x][p] == INF) continue;
                if (i < n) {
                    for (register int j = q; j <= T; j++) f[i][j] = min(f[i][j], f[x][p] + val[j - q]);
                } else {
                    for (register int j = q; j <= T; j++) f[i][j] = min(f[i][j], f[x][p]);
                }
            }
        }
        int ans = INF;
        for (register int i = 0; i <= T; i++)
            if (f[n][i] != INF) ans = min(ans, f[n][i] + i);
        printf("%d\n", ans);
    }
}
int head[maxn], tot = 1;
struct Edge { int to, st, ed, next; } edge[maxn << 1];
inline void addedge(int u, int v, int p, int q) {
    edge[tot] = (Edge) {v, p, q, head[u]};
    head[u] = tot++;
}
struct Node { int f, x, p; };
inline bool operator < (const Node &a, const Node &b) { return a.f > b.f; }
priority_queue<Node> pq;
inline void dijkstra() {
    f[1][0] = 0, pq.push((Node) {0, 1, 0});
    while (!pq.empty()) {
        int u = pq.top().x, p = pq.top().p;
		pq.pop();
        if (vis[u][p]) continue;
        vis[u][p] = 1;
        for (register int i = head[u]; i; i = edge[i].next)
            if (edge[i].st >= p) {
                int v = edge[i].to, st = edge[i].st, ed = edge[i].ed;
                if (f[v][ed] > f[u][p] + val[st - p]) {
                    f[v][ed] = f[u][p] + val[st - p];
                    pq.push((Node) {f[v][ed], v, ed});
                }
            }
    }
}
int main() {
	scanf("%d%d%d%d%d", &n, &m, &A, &B, &C);
	bool fla = true;
    for (register int i = 1; i <= m; i++) {
    	int x, y, p, q;
		scanf("%d%d%d%d", &x, &y, &p, &q);
        vec[y].push_back((Route) {x, p, q});
        addedge(x, y, p, q), T = max(T, q);
        if (x > y) fla = false;
    }
    for (register int i = 0; i <= T; i++) val[i] = A * i * i + B * i + C;
    if (fla) return Solve1::solve(), 0;
    for (register int i = 1; i <= n; i++)
        for (register int j = 0; j <= T; j++) f[i][j] = INF;
    dijkstra();
    int ans = INF;
    for (register int i = 0; i <= T; i++)
        if (f[n][i] != INF) ans = min(ans, f[n][i] + i);
    printf("%d\n", ans);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1471.93 us2 MB + 748 KBAcceptedScore: 5

Testcase #2462.85 us2 MB + 748 KBAcceptedScore: 5

Testcase #3483.78 us2 MB + 616 KBAcceptedScore: 5

Testcase #4461.56 us2 MB + 608 KBAcceptedScore: 5

Testcase #52.087 ms10 MB + 152 KBAcceptedScore: 5

Testcase #62.456 ms10 MB + 140 KBAcceptedScore: 5

Testcase #72.39 ms10 MB + 148 KBAcceptedScore: 5

Testcase #82.962 ms10 MB + 160 KBAcceptedScore: 5

Testcase #92.73 ms10 MB + 128 KBAcceptedScore: 5

Testcase #102.344 ms10 MB + 128 KBAcceptedScore: 5

Testcase #112.178 ms11 MB + 188 KBAcceptedScore: 5

Testcase #122.527 ms11 MB + 748 KBAcceptedScore: 5

Testcase #132.319 ms11 MB + 452 KBAcceptedScore: 5

Testcase #143.157 ms11 MB + 824 KBAcceptedScore: 5

Testcase #15288.672 ms473 MB + 52 KBAcceptedScore: 5

Testcase #16281.202 ms470 MB + 232 KBAcceptedScore: 5

Testcase #17202.714 ms450 MB + 656 KBAcceptedScore: 5

Testcase #18100.458 ms403 MB + 884 KBAcceptedScore: 5

Testcase #19464.944 ms486 MB + 876 KBAcceptedScore: 5

Testcase #20116.55 ms423 MB + 304 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:23:00 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠