Submission #498508

# Submission time Handle Problem Language Result Execution time Memory
498508 2021-12-25T11:08:49 Z gratus907 None (KOI16_gas) C++17
73 / 100
2000 ms 55360 KB
#include <iostream>
#include <vector>
#include <queue>
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;

const ll INF = 987654321987654321;
const int MX = 2625;

struct Edge {
    int src, dst, w;
    bool operator<(const Edge &p) const {
        return w > p.w;
    }
};
bool relax(int u, int v, int w, ll dist[])
{
    bool flag = 0;
    if (dist[v] > dist[u] + w && (dist[u] != INF)) {
        flag = true;
        dist[v] = dist[u] + w;
    }
    return flag;
}

int fuel[MX];
ll cost[MX * MX];
vector <Edge> G[MX];

void dijkstra(ll dist[], int start, vector<Edge> graph[])
{
    fill(dist,dist+MX*MX,INF);
    dist[start*2501+fuel[start]] = 0;
    priority_queue<Edge> pq;
    pq.push({0, start,0});
    while(!pq.empty()) {
        Edge x = pq.top();
        pq.pop();
        //printf("Process edge %lld -> %lld (len=%lld)\n",x.src, x.dst, x.w);
        for (auto ed : graph[x.dst]) {
            bool flag = false;
            int max_j = min(2500, fuel[ed.src]);
            for (int j = 1; j <= max_j; j++) {
                int fcost = min(fuel[ed.dst], j);
                if (relax(ed.src*2501+j, ed.dst*2501+fcost, ed.w * j, dist)) {
                    //printf("cost [%lld][%lld] relaxed to %lld\n",ed.dst, fcost, cost[ed.dst*2501+fcost]);
                    flag = true;
                }
            }
            if (flag) pq.push(ed);
        }
    }
}

int32_t main() {
    usecppio
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> fuel[i];
    for (int i = 0; i < m; i++) {
        int u, v, w; cin >> u >> v >> w;
        G[u].push_back({u, v, w});
        G[v].push_back({v, u, w});
    }
    dijkstra(cost, 1, G);
    ll ans = INF;
    for (int j = 1; j <= 2500; j++) ans = min(ans, cost[n*2501+j]);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 54256 KB Output is correct
2 Correct 20 ms 54288 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54200 KB Output is correct
6 Correct 24 ms 54256 KB Output is correct
7 Correct 23 ms 54264 KB Output is correct
8 Correct 26 ms 54284 KB Output is correct
9 Correct 21 ms 54264 KB Output is correct
10 Correct 20 ms 54252 KB Output is correct
11 Correct 20 ms 54220 KB Output is correct
12 Correct 20 ms 54268 KB Output is correct
13 Correct 22 ms 54220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 54372 KB Output is correct
2 Correct 52 ms 54364 KB Output is correct
3 Correct 40 ms 54408 KB Output is correct
4 Correct 38 ms 54428 KB Output is correct
5 Correct 45 ms 54428 KB Output is correct
6 Correct 45 ms 54432 KB Output is correct
7 Correct 47 ms 54336 KB Output is correct
8 Correct 45 ms 54400 KB Output is correct
9 Correct 48 ms 54436 KB Output is correct
10 Correct 45 ms 54408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 54312 KB Output is correct
2 Correct 24 ms 54560 KB Output is correct
3 Correct 24 ms 54568 KB Output is correct
4 Correct 26 ms 54596 KB Output is correct
5 Correct 25 ms 54532 KB Output is correct
6 Correct 24 ms 54576 KB Output is correct
7 Correct 28 ms 54564 KB Output is correct
8 Correct 26 ms 54628 KB Output is correct
9 Correct 25 ms 54472 KB Output is correct
10 Correct 23 ms 54532 KB Output is correct
11 Correct 24 ms 54452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 54256 KB Output is correct
2 Correct 20 ms 54288 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54200 KB Output is correct
6 Correct 24 ms 54256 KB Output is correct
7 Correct 23 ms 54264 KB Output is correct
8 Correct 26 ms 54284 KB Output is correct
9 Correct 21 ms 54264 KB Output is correct
10 Correct 20 ms 54252 KB Output is correct
11 Correct 20 ms 54220 KB Output is correct
12 Correct 20 ms 54268 KB Output is correct
13 Correct 22 ms 54220 KB Output is correct
14 Correct 28 ms 54328 KB Output is correct
15 Correct 26 ms 54372 KB Output is correct
16 Correct 27 ms 54300 KB Output is correct
17 Correct 636 ms 55300 KB Output is correct
18 Correct 599 ms 55360 KB Output is correct
19 Correct 64 ms 54348 KB Output is correct
20 Correct 51 ms 54332 KB Output is correct
21 Correct 61 ms 54364 KB Output is correct
22 Correct 40 ms 54356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 54256 KB Output is correct
2 Correct 20 ms 54288 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54200 KB Output is correct
6 Correct 24 ms 54256 KB Output is correct
7 Correct 23 ms 54264 KB Output is correct
8 Correct 26 ms 54284 KB Output is correct
9 Correct 21 ms 54264 KB Output is correct
10 Correct 20 ms 54252 KB Output is correct
11 Correct 20 ms 54220 KB Output is correct
12 Correct 20 ms 54268 KB Output is correct
13 Correct 22 ms 54220 KB Output is correct
14 Correct 22 ms 54372 KB Output is correct
15 Correct 52 ms 54364 KB Output is correct
16 Correct 40 ms 54408 KB Output is correct
17 Correct 38 ms 54428 KB Output is correct
18 Correct 45 ms 54428 KB Output is correct
19 Correct 45 ms 54432 KB Output is correct
20 Correct 47 ms 54336 KB Output is correct
21 Correct 45 ms 54400 KB Output is correct
22 Correct 48 ms 54436 KB Output is correct
23 Correct 45 ms 54408 KB Output is correct
24 Correct 21 ms 54312 KB Output is correct
25 Correct 24 ms 54560 KB Output is correct
26 Correct 24 ms 54568 KB Output is correct
27 Correct 26 ms 54596 KB Output is correct
28 Correct 25 ms 54532 KB Output is correct
29 Correct 24 ms 54576 KB Output is correct
30 Correct 28 ms 54564 KB Output is correct
31 Correct 26 ms 54628 KB Output is correct
32 Correct 25 ms 54472 KB Output is correct
33 Correct 23 ms 54532 KB Output is correct
34 Correct 24 ms 54452 KB Output is correct
35 Correct 28 ms 54328 KB Output is correct
36 Correct 26 ms 54372 KB Output is correct
37 Correct 27 ms 54300 KB Output is correct
38 Correct 636 ms 55300 KB Output is correct
39 Correct 599 ms 55360 KB Output is correct
40 Correct 64 ms 54348 KB Output is correct
41 Correct 51 ms 54332 KB Output is correct
42 Correct 61 ms 54364 KB Output is correct
43 Correct 40 ms 54356 KB Output is correct
44 Correct 45 ms 54432 KB Output is correct
45 Correct 83 ms 54428 KB Output is correct
46 Correct 120 ms 54424 KB Output is correct
47 Correct 1526 ms 55180 KB Output is correct
48 Correct 1642 ms 55072 KB Output is correct
49 Execution timed out 2040 ms 54776 KB Time limit exceeded
50 Halted 0 ms 0 KB -