Submission #498512

# Submission time Handle Problem Language Result Execution time Memory
498512 2021-12-25T11:13:17 Z gratus907 None (KOI16_gas) C++17
73 / 100
2000 ms 55220 KB
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cstdlib>
#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;
    }
};
int fuel[MX];
ll cost[MX][MX];
vector <Edge> G[MX];

void dijkstra(int start, vector<Edge> graph[])
{
    memset(cost, 0x7f, sizeof(cost));
    cost[start][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);
                int u = ed.src;
                int v = ed.dst;
                int w = ed.w * j;
                if (cost[v][fcost] > cost[u][j] + w) {
                    flag = true;
                    cost[v][fcost] = cost[u][j] + w;
                }
            }
            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(1, G);
    ll ans = INF;
    for (int j = 1; j <= 2500; j++) ans = min(ans, cost[n][j]);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 54268 KB Output is correct
2 Correct 26 ms 54276 KB Output is correct
3 Correct 22 ms 54224 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54292 KB Output is correct
6 Correct 20 ms 54256 KB Output is correct
7 Correct 20 ms 54224 KB Output is correct
8 Correct 19 ms 54240 KB Output is correct
9 Correct 24 ms 54316 KB Output is correct
10 Correct 23 ms 54280 KB Output is correct
11 Correct 22 ms 54216 KB Output is correct
12 Correct 26 ms 54188 KB Output is correct
13 Correct 23 ms 54232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 54348 KB Output is correct
2 Correct 36 ms 54408 KB Output is correct
3 Correct 34 ms 54296 KB Output is correct
4 Correct 33 ms 54384 KB Output is correct
5 Correct 39 ms 54396 KB Output is correct
6 Correct 38 ms 54288 KB Output is correct
7 Correct 44 ms 54324 KB Output is correct
8 Correct 38 ms 54384 KB Output is correct
9 Correct 39 ms 54400 KB Output is correct
10 Correct 39 ms 54372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 54348 KB Output is correct
2 Correct 26 ms 54604 KB Output is correct
3 Correct 26 ms 54556 KB Output is correct
4 Correct 25 ms 54580 KB Output is correct
5 Correct 30 ms 54496 KB Output is correct
6 Correct 26 ms 54480 KB Output is correct
7 Correct 26 ms 54496 KB Output is correct
8 Correct 25 ms 54516 KB Output is correct
9 Correct 25 ms 54468 KB Output is correct
10 Correct 28 ms 54476 KB Output is correct
11 Correct 24 ms 54436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 54268 KB Output is correct
2 Correct 26 ms 54276 KB Output is correct
3 Correct 22 ms 54224 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54292 KB Output is correct
6 Correct 20 ms 54256 KB Output is correct
7 Correct 20 ms 54224 KB Output is correct
8 Correct 19 ms 54240 KB Output is correct
9 Correct 24 ms 54316 KB Output is correct
10 Correct 23 ms 54280 KB Output is correct
11 Correct 22 ms 54216 KB Output is correct
12 Correct 26 ms 54188 KB Output is correct
13 Correct 23 ms 54232 KB Output is correct
14 Correct 26 ms 54332 KB Output is correct
15 Correct 30 ms 54216 KB Output is correct
16 Correct 26 ms 54200 KB Output is correct
17 Correct 453 ms 55204 KB Output is correct
18 Correct 449 ms 55220 KB Output is correct
19 Correct 50 ms 54356 KB Output is correct
20 Correct 51 ms 54360 KB Output is correct
21 Correct 46 ms 54352 KB Output is correct
22 Correct 30 ms 54348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 54268 KB Output is correct
2 Correct 26 ms 54276 KB Output is correct
3 Correct 22 ms 54224 KB Output is correct
4 Correct 20 ms 54220 KB Output is correct
5 Correct 20 ms 54292 KB Output is correct
6 Correct 20 ms 54256 KB Output is correct
7 Correct 20 ms 54224 KB Output is correct
8 Correct 19 ms 54240 KB Output is correct
9 Correct 24 ms 54316 KB Output is correct
10 Correct 23 ms 54280 KB Output is correct
11 Correct 22 ms 54216 KB Output is correct
12 Correct 26 ms 54188 KB Output is correct
13 Correct 23 ms 54232 KB Output is correct
14 Correct 22 ms 54348 KB Output is correct
15 Correct 36 ms 54408 KB Output is correct
16 Correct 34 ms 54296 KB Output is correct
17 Correct 33 ms 54384 KB Output is correct
18 Correct 39 ms 54396 KB Output is correct
19 Correct 38 ms 54288 KB Output is correct
20 Correct 44 ms 54324 KB Output is correct
21 Correct 38 ms 54384 KB Output is correct
22 Correct 39 ms 54400 KB Output is correct
23 Correct 39 ms 54372 KB Output is correct
24 Correct 23 ms 54348 KB Output is correct
25 Correct 26 ms 54604 KB Output is correct
26 Correct 26 ms 54556 KB Output is correct
27 Correct 25 ms 54580 KB Output is correct
28 Correct 30 ms 54496 KB Output is correct
29 Correct 26 ms 54480 KB Output is correct
30 Correct 26 ms 54496 KB Output is correct
31 Correct 25 ms 54516 KB Output is correct
32 Correct 25 ms 54468 KB Output is correct
33 Correct 28 ms 54476 KB Output is correct
34 Correct 24 ms 54436 KB Output is correct
35 Correct 26 ms 54332 KB Output is correct
36 Correct 30 ms 54216 KB Output is correct
37 Correct 26 ms 54200 KB Output is correct
38 Correct 453 ms 55204 KB Output is correct
39 Correct 449 ms 55220 KB Output is correct
40 Correct 50 ms 54356 KB Output is correct
41 Correct 51 ms 54360 KB Output is correct
42 Correct 46 ms 54352 KB Output is correct
43 Correct 30 ms 54348 KB Output is correct
44 Correct 42 ms 54348 KB Output is correct
45 Correct 84 ms 54512 KB Output is correct
46 Correct 90 ms 54384 KB Output is correct
47 Correct 1113 ms 54968 KB Output is correct
48 Correct 1149 ms 55056 KB Output is correct
49 Execution timed out 2085 ms 54656 KB Time limit exceeded
50 Halted 0 ms 0 KB -