Submission #684134

# Submission time Handle Problem Language Result Execution time Memory
684134 2023-01-20T14:06:29 Z kusssso Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
623 ms 6860 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 30005;
const ll inf = 1e18;

int n, m;
int b[N], p[N];
ll d[N];
vector<int> power[N];
vector<pair<int, ll>> g[N];

struct kek {
    int u;
    ll du;
    bool operator < (const kek& oth) const {
        return du > oth.du;
    }  
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> b[i] >> p[i];
        power[b[i]].push_back(p[i]);
    }
    fill(begin(d), end(d), inf);
    d[b[0]] = 0;
    priority_queue<kek> pq;
    pq.push({b[0], 0});
    
    while (!pq.empty()) {
        auto [u, du] = pq.top(); pq.pop();
        if (d[u] != du) continue;
        
        // if (u == b[1]) {
            // cout << du;
            // return 0;
        // }
//         
        // cerr << "@" << u << '\n';
        
        for (auto& P : power[u]) {
            for (ll v = u + P, w = 1; v < n; v += P, w++) {
                if (d[v] > d[u] + w) {
                    d[v] = d[u] + w;
                    pq.push({v, d[v]});
                }
            }
            for (ll v = u - P, w = 1; v >= 0; v -= P, w++) {
                if (d[v] > d[u] + w) {
                    d[v] = d[u] + w;
                    pq.push({v, d[v]});
                    // cerr << u << ' ' << v << '\n';
                }
            }
        }
    }
    cout << (d[b[1]] == inf ? -1 : d[b[1]]);
    
    
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:30: warning: narrowing conversion of 'v' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   50 |                     pq.push({v, d[v]});
      |                              ^
skyscraper.cpp:56:30: warning: narrowing conversion of 'v' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   56 |                     pq.push({v, d[v]});
      |                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1856 KB Output is correct
3 Correct 2 ms 1864 KB Output is correct
4 Correct 1 ms 1860 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1860 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1860 KB Output is correct
7 Correct 1 ms 1864 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 1 ms 2004 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1860 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1856 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 2 ms 2004 KB Output is correct
15 Correct 2 ms 1996 KB Output is correct
16 Correct 1 ms 1996 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 2 ms 2004 KB Output is correct
19 Correct 1 ms 1992 KB Output is correct
20 Correct 5 ms 2124 KB Output is correct
21 Correct 2 ms 2004 KB Output is correct
22 Correct 1 ms 2004 KB Output is correct
23 Correct 2 ms 2004 KB Output is correct
24 Correct 2 ms 2004 KB Output is correct
25 Correct 2 ms 2128 KB Output is correct
26 Correct 4 ms 2004 KB Output is correct
27 Correct 4 ms 2004 KB Output is correct
28 Correct 2 ms 2004 KB Output is correct
29 Correct 3 ms 2372 KB Output is correct
30 Correct 2 ms 2132 KB Output is correct
31 Correct 2 ms 2132 KB Output is correct
32 Correct 2 ms 2120 KB Output is correct
33 Correct 3 ms 2388 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1864 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 2 ms 1856 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1856 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 2 ms 1996 KB Output is correct
15 Correct 2 ms 1996 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 3 ms 2004 KB Output is correct
18 Correct 1 ms 2004 KB Output is correct
19 Correct 1 ms 1992 KB Output is correct
20 Correct 5 ms 2132 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 2 ms 2004 KB Output is correct
23 Correct 2 ms 2000 KB Output is correct
24 Correct 2 ms 2004 KB Output is correct
25 Correct 2 ms 2132 KB Output is correct
26 Correct 4 ms 2004 KB Output is correct
27 Correct 4 ms 1996 KB Output is correct
28 Correct 2 ms 2000 KB Output is correct
29 Correct 3 ms 2388 KB Output is correct
30 Correct 2 ms 2132 KB Output is correct
31 Correct 2 ms 2132 KB Output is correct
32 Correct 2 ms 2132 KB Output is correct
33 Correct 3 ms 2388 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
35 Correct 7 ms 2668 KB Output is correct
36 Correct 3 ms 2132 KB Output is correct
37 Correct 5 ms 2644 KB Output is correct
38 Correct 8 ms 2892 KB Output is correct
39 Correct 7 ms 2828 KB Output is correct
40 Correct 8 ms 2912 KB Output is correct
41 Correct 9 ms 2900 KB Output is correct
42 Correct 42 ms 2644 KB Output is correct
43 Correct 43 ms 2636 KB Output is correct
44 Correct 44 ms 2652 KB Output is correct
45 Correct 7 ms 2900 KB Output is correct
46 Correct 7 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 2 ms 1856 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1856 KB Output is correct
8 Correct 2 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 1 ms 2004 KB Output is correct
13 Correct 1 ms 2004 KB Output is correct
14 Correct 2 ms 2004 KB Output is correct
15 Correct 2 ms 1996 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 2 ms 2004 KB Output is correct
19 Correct 1 ms 2004 KB Output is correct
20 Correct 5 ms 2132 KB Output is correct
21 Correct 2 ms 2004 KB Output is correct
22 Correct 2 ms 1992 KB Output is correct
23 Correct 2 ms 2004 KB Output is correct
24 Correct 2 ms 2004 KB Output is correct
25 Correct 2 ms 2112 KB Output is correct
26 Correct 5 ms 2004 KB Output is correct
27 Correct 4 ms 2004 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 2 ms 2388 KB Output is correct
30 Correct 3 ms 2112 KB Output is correct
31 Correct 2 ms 2112 KB Output is correct
32 Correct 3 ms 2152 KB Output is correct
33 Correct 4 ms 2380 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
35 Correct 8 ms 2668 KB Output is correct
36 Correct 4 ms 2132 KB Output is correct
37 Correct 5 ms 2684 KB Output is correct
38 Correct 8 ms 2900 KB Output is correct
39 Correct 9 ms 2896 KB Output is correct
40 Correct 10 ms 2900 KB Output is correct
41 Correct 9 ms 2856 KB Output is correct
42 Correct 44 ms 2644 KB Output is correct
43 Correct 42 ms 2632 KB Output is correct
44 Correct 46 ms 2644 KB Output is correct
45 Correct 7 ms 2948 KB Output is correct
46 Correct 9 ms 3028 KB Output is correct
47 Correct 16 ms 3912 KB Output is correct
48 Correct 6 ms 2772 KB Output is correct
49 Correct 7 ms 2900 KB Output is correct
50 Correct 4 ms 2516 KB Output is correct
51 Correct 27 ms 5320 KB Output is correct
52 Correct 20 ms 4292 KB Output is correct
53 Correct 13 ms 4300 KB Output is correct
54 Correct 3 ms 2348 KB Output is correct
55 Correct 4 ms 2264 KB Output is correct
56 Correct 621 ms 3928 KB Output is correct
57 Correct 47 ms 6340 KB Output is correct
58 Correct 623 ms 2764 KB Output is correct
59 Correct 569 ms 2900 KB Output is correct
60 Correct 580 ms 2900 KB Output is correct
61 Correct 530 ms 2900 KB Output is correct
62 Correct 9 ms 3412 KB Output is correct
63 Correct 24 ms 4816 KB Output is correct
64 Correct 24 ms 4808 KB Output is correct
65 Correct 33 ms 6860 KB Output is correct
66 Correct 46 ms 6844 KB Output is correct
67 Correct 44 ms 6852 KB Output is correct