Submission #847247

# Submission time Handle Problem Language Result Execution time Memory
847247 2023-09-09T10:16:02 Z LaziChicken Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
425 ms 28624 KB
#include <bits/stdc++.h>
using namespace std;
 
using pii = pair<int, int>;
 
const int N = 3e4 + 5;
const int oo = 1e9;
 
#define eb emplace_back
 
struct node {
    int w, u, s;
 
    node() {
        w = u = s = 0;
    }
 
    node(int w, int u, int s) : w(w), u(u), s(s) {}
 
    friend bool operator > (node a, node b) {
        return a.w > b.w;
    }
};
 
int n, m;
int dist[N][200];
vector<int> adj[N];
priority_queue<node, vector<node>, greater<node>> Q;
int ans = oo;
int start, finish;
bool vis[N];
 
void update(int u, int v, int w, int cur, int siu) {
    if(dist[v][siu] > dist[u][cur] + w) {
        dist[v][siu] = dist[u][cur] + w;
        Q.emplace(dist[v][siu], v, siu);
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    int SQRT = sqrt(n);
 
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v);
 
        if(i == 0)
            start = u;
 
        if(i == 1)
            finish = u;
    }
 
    memset(dist, 0x3f, sizeof dist);
 
    dist[start][0] = 0;
    Q.emplace(0, start, 0);
 
    while(!Q.empty()) {
        node top = Q.top();
        Q.pop();
 
        int u = top.u;
        int cur = top.s;
 
        if(dist[u][cur] != top.w)
            continue;
 
        if(u == finish)
            return cout << dist[finish][cur], 0;
 
        if(cur) {
            if(u + cur < n)
                update(u, u + cur, 1, cur, cur);
 
            if(u - cur >= 0)
                update(u, u - cur, 1, cur, cur);
        }
 
        if(vis[u])
            continue;
 
        vis[u] = true;
 
        for(int v : adj[u]) {
            if(v >= SQRT) {
                for(int j = 1; u + j * v < n; j++)
                    update(u, u + j * v, j, cur, 0);
 
                for(int j = 1; u - j * v >= 0; j++)
                    update(u, u - j * v, j, cur, 0);
 
            } else {
                if(u + v < n)
                    update(u, u + v, 1, cur, v);
 
                if(u - v >= 0)
                    update(u, u - v, 1, cur, v);
            }
        }
    }
 
    cout << -1;
}
/*
5 3
0 2
1 1
4 1
*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 24408 KB Output is correct
2 Correct 4 ms 24412 KB Output is correct
3 Correct 4 ms 24412 KB Output is correct
4 Correct 3 ms 24408 KB Output is correct
5 Correct 4 ms 24408 KB Output is correct
6 Correct 4 ms 24408 KB Output is correct
7 Correct 4 ms 24408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 24408 KB Output is correct
2 Correct 4 ms 24408 KB Output is correct
3 Correct 3 ms 24408 KB Output is correct
4 Correct 4 ms 24412 KB Output is correct
5 Correct 4 ms 24408 KB Output is correct
6 Correct 4 ms 24408 KB Output is correct
7 Correct 4 ms 24408 KB Output is correct
8 Correct 3 ms 24408 KB Output is correct
9 Correct 3 ms 24408 KB Output is correct
10 Correct 4 ms 24408 KB Output is correct
11 Correct 4 ms 24664 KB Output is correct
12 Correct 4 ms 24408 KB Output is correct
13 Correct 4 ms 24664 KB Output is correct
14 Correct 4 ms 24664 KB Output is correct
15 Correct 4 ms 24668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 24408 KB Output is correct
2 Correct 3 ms 24412 KB Output is correct
3 Correct 3 ms 24408 KB Output is correct
4 Correct 4 ms 24408 KB Output is correct
5 Correct 4 ms 24408 KB Output is correct
6 Correct 4 ms 24408 KB Output is correct
7 Correct 4 ms 24408 KB Output is correct
8 Correct 4 ms 24408 KB Output is correct
9 Correct 4 ms 24408 KB Output is correct
10 Correct 4 ms 24408 KB Output is correct
11 Correct 4 ms 24664 KB Output is correct
12 Correct 4 ms 24664 KB Output is correct
13 Correct 4 ms 24664 KB Output is correct
14 Correct 4 ms 24664 KB Output is correct
15 Correct 4 ms 24664 KB Output is correct
16 Correct 4 ms 24412 KB Output is correct
17 Correct 4 ms 24664 KB Output is correct
18 Correct 4 ms 24668 KB Output is correct
19 Correct 4 ms 24664 KB Output is correct
20 Correct 4 ms 24664 KB Output is correct
21 Correct 4 ms 24464 KB Output is correct
22 Correct 4 ms 24664 KB Output is correct
23 Correct 4 ms 24668 KB Output is correct
24 Correct 5 ms 24668 KB Output is correct
25 Correct 5 ms 24664 KB Output is correct
26 Correct 4 ms 24664 KB Output is correct
27 Correct 4 ms 24664 KB Output is correct
28 Correct 4 ms 24664 KB Output is correct
29 Correct 7 ms 24664 KB Output is correct
30 Correct 4 ms 24408 KB Output is correct
31 Correct 6 ms 24664 KB Output is correct
32 Correct 5 ms 24668 KB Output is correct
33 Correct 9 ms 24664 KB Output is correct
34 Correct 7 ms 24664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 24408 KB Output is correct
2 Correct 4 ms 24412 KB Output is correct
3 Correct 3 ms 24408 KB Output is correct
4 Correct 4 ms 24408 KB Output is correct
5 Correct 4 ms 24408 KB Output is correct
6 Correct 4 ms 24408 KB Output is correct
7 Correct 4 ms 24408 KB Output is correct
8 Correct 4 ms 24408 KB Output is correct
9 Correct 4 ms 24408 KB Output is correct
10 Correct 4 ms 24408 KB Output is correct
11 Correct 4 ms 24664 KB Output is correct
12 Correct 4 ms 24664 KB Output is correct
13 Correct 4 ms 24664 KB Output is correct
14 Correct 5 ms 24664 KB Output is correct
15 Correct 4 ms 24664 KB Output is correct
16 Correct 4 ms 24664 KB Output is correct
17 Correct 4 ms 24668 KB Output is correct
18 Correct 4 ms 24664 KB Output is correct
19 Correct 4 ms 24664 KB Output is correct
20 Correct 4 ms 24664 KB Output is correct
21 Correct 5 ms 24664 KB Output is correct
22 Correct 4 ms 24668 KB Output is correct
23 Correct 4 ms 24664 KB Output is correct
24 Correct 4 ms 24664 KB Output is correct
25 Correct 4 ms 24664 KB Output is correct
26 Correct 4 ms 24664 KB Output is correct
27 Correct 4 ms 24664 KB Output is correct
28 Correct 4 ms 24668 KB Output is correct
29 Correct 7 ms 24664 KB Output is correct
30 Correct 5 ms 24668 KB Output is correct
31 Correct 6 ms 24664 KB Output is correct
32 Correct 6 ms 24664 KB Output is correct
33 Correct 9 ms 24664 KB Output is correct
34 Correct 7 ms 24664 KB Output is correct
35 Correct 8 ms 24920 KB Output is correct
36 Correct 4 ms 24664 KB Output is correct
37 Correct 7 ms 24920 KB Output is correct
38 Correct 8 ms 24920 KB Output is correct
39 Correct 7 ms 24664 KB Output is correct
40 Correct 8 ms 24920 KB Output is correct
41 Correct 8 ms 24784 KB Output is correct
42 Correct 6 ms 24664 KB Output is correct
43 Correct 6 ms 24664 KB Output is correct
44 Correct 7 ms 24664 KB Output is correct
45 Correct 15 ms 25180 KB Output is correct
46 Correct 10 ms 24924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 24408 KB Output is correct
2 Correct 4 ms 24408 KB Output is correct
3 Correct 4 ms 24408 KB Output is correct
4 Correct 4 ms 24408 KB Output is correct
5 Correct 3 ms 24408 KB Output is correct
6 Correct 3 ms 24412 KB Output is correct
7 Correct 4 ms 24412 KB Output is correct
8 Correct 4 ms 24412 KB Output is correct
9 Correct 3 ms 24408 KB Output is correct
10 Correct 4 ms 24408 KB Output is correct
11 Correct 4 ms 24664 KB Output is correct
12 Correct 4 ms 24664 KB Output is correct
13 Correct 4 ms 24664 KB Output is correct
14 Correct 4 ms 24668 KB Output is correct
15 Correct 4 ms 24664 KB Output is correct
16 Correct 4 ms 24412 KB Output is correct
17 Correct 4 ms 24664 KB Output is correct
18 Correct 4 ms 24664 KB Output is correct
19 Correct 4 ms 24664 KB Output is correct
20 Correct 4 ms 24664 KB Output is correct
21 Correct 4 ms 24408 KB Output is correct
22 Correct 4 ms 24664 KB Output is correct
23 Correct 4 ms 24664 KB Output is correct
24 Correct 4 ms 24664 KB Output is correct
25 Correct 4 ms 24664 KB Output is correct
26 Correct 4 ms 24664 KB Output is correct
27 Correct 4 ms 24664 KB Output is correct
28 Correct 4 ms 24664 KB Output is correct
29 Correct 7 ms 24664 KB Output is correct
30 Correct 5 ms 24408 KB Output is correct
31 Correct 6 ms 24668 KB Output is correct
32 Correct 5 ms 24668 KB Output is correct
33 Correct 9 ms 24664 KB Output is correct
34 Correct 7 ms 24664 KB Output is correct
35 Correct 8 ms 24920 KB Output is correct
36 Correct 4 ms 24664 KB Output is correct
37 Correct 7 ms 24920 KB Output is correct
38 Correct 8 ms 24920 KB Output is correct
39 Correct 8 ms 24676 KB Output is correct
40 Correct 8 ms 24920 KB Output is correct
41 Correct 10 ms 24920 KB Output is correct
42 Correct 7 ms 24668 KB Output is correct
43 Correct 6 ms 24664 KB Output is correct
44 Correct 6 ms 24664 KB Output is correct
45 Correct 13 ms 24920 KB Output is correct
46 Correct 10 ms 24920 KB Output is correct
47 Correct 11 ms 25368 KB Output is correct
48 Correct 8 ms 24920 KB Output is correct
49 Correct 8 ms 24920 KB Output is correct
50 Correct 6 ms 24920 KB Output is correct
51 Correct 14 ms 25624 KB Output is correct
52 Correct 15 ms 25624 KB Output is correct
53 Correct 10 ms 25176 KB Output is correct
54 Correct 5 ms 24664 KB Output is correct
55 Correct 4 ms 24664 KB Output is correct
56 Correct 10 ms 25432 KB Output is correct
57 Correct 4 ms 24664 KB Output is correct
58 Correct 8 ms 24920 KB Output is correct
59 Correct 8 ms 24920 KB Output is correct
60 Correct 8 ms 24920 KB Output is correct
61 Correct 8 ms 24920 KB Output is correct
62 Correct 20 ms 25688 KB Output is correct
63 Correct 30 ms 26580 KB Output is correct
64 Correct 30 ms 26324 KB Output is correct
65 Correct 152 ms 26580 KB Output is correct
66 Correct 425 ms 27852 KB Output is correct
67 Correct 206 ms 28624 KB Output is correct