Submission #498509

# Submission time Handle Problem Language Result Execution time Memory
498509 2021-12-25T11:10:49 Z gratus907 None (KOI16_gas) C++17
73 / 100
2000 ms 55272 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;
    }
};
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);
                int u = ed.src*2501+j; 
                int v = ed.dst*2501+fcost;
                int w = ed.w * j;
                if (dist[v] > dist[u] + w) {
                    flag = true; 
                    dist[v] = dist[u] + 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(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 20 ms 54220 KB Output is correct
2 Correct 21 ms 54240 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54192 KB Output is correct
5 Correct 20 ms 54236 KB Output is correct
6 Correct 20 ms 54244 KB Output is correct
7 Correct 21 ms 54216 KB Output is correct
8 Correct 21 ms 54264 KB Output is correct
9 Correct 20 ms 54220 KB Output is correct
10 Correct 20 ms 54220 KB Output is correct
11 Correct 22 ms 54220 KB Output is correct
12 Correct 19 ms 54200 KB Output is correct
13 Correct 21 ms 54200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 54348 KB Output is correct
2 Correct 36 ms 54272 KB Output is correct
3 Correct 33 ms 54344 KB Output is correct
4 Correct 37 ms 54340 KB Output is correct
5 Correct 39 ms 54336 KB Output is correct
6 Correct 39 ms 54380 KB Output is correct
7 Correct 39 ms 54384 KB Output is correct
8 Correct 37 ms 54384 KB Output is correct
9 Correct 37 ms 54404 KB Output is correct
10 Correct 36 ms 54388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 54348 KB Output is correct
2 Correct 25 ms 54576 KB Output is correct
3 Correct 24 ms 54488 KB Output is correct
4 Correct 25 ms 54496 KB Output is correct
5 Correct 25 ms 54568 KB Output is correct
6 Correct 24 ms 54556 KB Output is correct
7 Correct 23 ms 54476 KB Output is correct
8 Correct 24 ms 54516 KB Output is correct
9 Correct 24 ms 54460 KB Output is correct
10 Correct 23 ms 54476 KB Output is correct
11 Correct 23 ms 54416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 54220 KB Output is correct
2 Correct 21 ms 54240 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54192 KB Output is correct
5 Correct 20 ms 54236 KB Output is correct
6 Correct 20 ms 54244 KB Output is correct
7 Correct 21 ms 54216 KB Output is correct
8 Correct 21 ms 54264 KB Output is correct
9 Correct 20 ms 54220 KB Output is correct
10 Correct 20 ms 54220 KB Output is correct
11 Correct 22 ms 54220 KB Output is correct
12 Correct 19 ms 54200 KB Output is correct
13 Correct 21 ms 54200 KB Output is correct
14 Correct 25 ms 54300 KB Output is correct
15 Correct 25 ms 54220 KB Output is correct
16 Correct 27 ms 54388 KB Output is correct
17 Correct 491 ms 55240 KB Output is correct
18 Correct 421 ms 55272 KB Output is correct
19 Correct 51 ms 54356 KB Output is correct
20 Correct 41 ms 54348 KB Output is correct
21 Correct 46 ms 54352 KB Output is correct
22 Correct 32 ms 54360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 54220 KB Output is correct
2 Correct 21 ms 54240 KB Output is correct
3 Correct 20 ms 54252 KB Output is correct
4 Correct 20 ms 54192 KB Output is correct
5 Correct 20 ms 54236 KB Output is correct
6 Correct 20 ms 54244 KB Output is correct
7 Correct 21 ms 54216 KB Output is correct
8 Correct 21 ms 54264 KB Output is correct
9 Correct 20 ms 54220 KB Output is correct
10 Correct 20 ms 54220 KB Output is correct
11 Correct 22 ms 54220 KB Output is correct
12 Correct 19 ms 54200 KB Output is correct
13 Correct 21 ms 54200 KB Output is correct
14 Correct 21 ms 54348 KB Output is correct
15 Correct 36 ms 54272 KB Output is correct
16 Correct 33 ms 54344 KB Output is correct
17 Correct 37 ms 54340 KB Output is correct
18 Correct 39 ms 54336 KB Output is correct
19 Correct 39 ms 54380 KB Output is correct
20 Correct 39 ms 54384 KB Output is correct
21 Correct 37 ms 54384 KB Output is correct
22 Correct 37 ms 54404 KB Output is correct
23 Correct 36 ms 54388 KB Output is correct
24 Correct 22 ms 54348 KB Output is correct
25 Correct 25 ms 54576 KB Output is correct
26 Correct 24 ms 54488 KB Output is correct
27 Correct 25 ms 54496 KB Output is correct
28 Correct 25 ms 54568 KB Output is correct
29 Correct 24 ms 54556 KB Output is correct
30 Correct 23 ms 54476 KB Output is correct
31 Correct 24 ms 54516 KB Output is correct
32 Correct 24 ms 54460 KB Output is correct
33 Correct 23 ms 54476 KB Output is correct
34 Correct 23 ms 54416 KB Output is correct
35 Correct 25 ms 54300 KB Output is correct
36 Correct 25 ms 54220 KB Output is correct
37 Correct 27 ms 54388 KB Output is correct
38 Correct 491 ms 55240 KB Output is correct
39 Correct 421 ms 55272 KB Output is correct
40 Correct 51 ms 54356 KB Output is correct
41 Correct 41 ms 54348 KB Output is correct
42 Correct 46 ms 54352 KB Output is correct
43 Correct 32 ms 54360 KB Output is correct
44 Correct 38 ms 54404 KB Output is correct
45 Correct 64 ms 54344 KB Output is correct
46 Correct 116 ms 54388 KB Output is correct
47 Correct 1081 ms 54952 KB Output is correct
48 Correct 1109 ms 54968 KB Output is correct
49 Execution timed out 2076 ms 54640 KB Time limit exceeded
50 Halted 0 ms 0 KB -