Submission #883560

# Submission time Handle Problem Language Result Execution time Memory
883560 2023-12-05T12:19:47 Z SalihSahin Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
567 ms 7884 KB
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
 
using namespace std;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int N = 3e4 + 5;
 
vector<int> adj[N];
 
int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie();
    int n, m;
    cin>>n>>m;
    int start = 0, finish = 0;
    for(int i = 0; i < m; i++){
        int b, p;
        cin>>b>>p;
        if(i == 0) start = b;
        if(i == 1) finish = b;
 
        adj[b].pb(p);
    }
 
    priority_queue<pair<int, int> > pq;
    vector<int> best(N, inf), vis(N);
    best[start] = 0;
    pq.push(mp(0, start));
    
    while(pq.size()){
        int node = pq.top().second;
        int len = pq.top().first * (-1);
        pq.pop();
        
        if(vis[node]) continue;
        vis[node] = 1;
 
        for(auto itr: adj[node]){
            int dis = 1;
            for(int i = node + itr; i < n; i += itr){
                if(best[i] > best[node] + dis){
                    pq.push(mp(-(best[node] + dis), i));
                    best[i] = best[node] + dis;
                }
                dis++;
            }
            dis = 1;
            for(int i = node - itr; i >= 0; i -= itr){
                if(best[i] > best[node] + dis){
                    pq.push(mp(-(best[node] + dis), i));
                    best[i] = best[node] + dis;
                }
                dis++;
            }
        }
    }
 
    if(best[finish] == inf) cout<<-1<<endl;
    else cout<<best[finish]<<endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:34:13: warning: unused variable 'len' [-Wunused-variable]
   34 |         int len = pq.top().first * (-1);
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1624 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1624 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 2 ms 1676 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1624 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1624 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1880 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 1 ms 1628 KB Output is correct
20 Correct 4 ms 1624 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1628 KB Output is correct
24 Correct 1 ms 1688 KB Output is correct
25 Correct 2 ms 1640 KB Output is correct
26 Correct 3 ms 1632 KB Output is correct
27 Correct 3 ms 1624 KB Output is correct
28 Correct 1 ms 1628 KB Output is correct
29 Correct 2 ms 1880 KB Output is correct
30 Correct 2 ms 1628 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 2 ms 1884 KB Output is correct
34 Correct 2 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1424 KB Output is correct
8 Correct 1 ms 1780 KB Output is correct
9 Correct 1 ms 1624 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 1 ms 1624 KB Output is correct
18 Correct 1 ms 1644 KB Output is correct
19 Correct 1 ms 1624 KB Output is correct
20 Correct 4 ms 1624 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 1 ms 1628 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 1 ms 1704 KB Output is correct
29 Correct 2 ms 1884 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
31 Correct 1 ms 1628 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 2 ms 1884 KB Output is correct
34 Correct 2 ms 1884 KB Output is correct
35 Correct 5 ms 2140 KB Output is correct
36 Correct 2 ms 1684 KB Output is correct
37 Correct 5 ms 2140 KB Output is correct
38 Correct 7 ms 2396 KB Output is correct
39 Correct 7 ms 2396 KB Output is correct
40 Correct 7 ms 2396 KB Output is correct
41 Correct 6 ms 2536 KB Output is correct
42 Correct 41 ms 2020 KB Output is correct
43 Correct 40 ms 2020 KB Output is correct
44 Correct 39 ms 2224 KB Output is correct
45 Correct 6 ms 2400 KB Output is correct
46 Correct 6 ms 2400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1424 KB Output is correct
2 Correct 2 ms 1632 KB Output is correct
3 Correct 1 ms 1632 KB Output is correct
4 Correct 1 ms 1632 KB Output is correct
5 Correct 1 ms 1892 KB Output is correct
6 Correct 1 ms 1636 KB Output is correct
7 Correct 1 ms 1640 KB Output is correct
8 Correct 1 ms 1640 KB Output is correct
9 Correct 1 ms 1636 KB Output is correct
10 Correct 1 ms 1640 KB Output is correct
11 Correct 1 ms 1640 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 2 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 1 ms 1628 KB Output is correct
20 Correct 4 ms 1628 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 1 ms 1628 KB Output is correct
29 Correct 2 ms 1880 KB Output is correct
30 Correct 1 ms 1672 KB Output is correct
31 Correct 1 ms 1628 KB Output is correct
32 Correct 1 ms 1624 KB Output is correct
33 Correct 2 ms 1884 KB Output is correct
34 Correct 2 ms 1884 KB Output is correct
35 Correct 5 ms 2140 KB Output is correct
36 Correct 2 ms 1628 KB Output is correct
37 Correct 5 ms 2140 KB Output is correct
38 Correct 7 ms 2568 KB Output is correct
39 Correct 6 ms 2396 KB Output is correct
40 Correct 9 ms 2648 KB Output is correct
41 Correct 7 ms 2396 KB Output is correct
42 Correct 41 ms 2008 KB Output is correct
43 Correct 39 ms 2012 KB Output is correct
44 Correct 40 ms 2052 KB Output is correct
45 Correct 5 ms 2396 KB Output is correct
46 Correct 5 ms 2456 KB Output is correct
47 Correct 13 ms 3292 KB Output is correct
48 Correct 5 ms 2224 KB Output is correct
49 Correct 5 ms 2136 KB Output is correct
50 Correct 4 ms 2136 KB Output is correct
51 Correct 20 ms 4564 KB Output is correct
52 Correct 20 ms 3544 KB Output is correct
53 Correct 14 ms 3544 KB Output is correct
54 Correct 2 ms 2012 KB Output is correct
55 Correct 3 ms 2016 KB Output is correct
56 Correct 545 ms 3396 KB Output is correct
57 Correct 42 ms 7884 KB Output is correct
58 Correct 567 ms 2348 KB Output is correct
59 Correct 556 ms 2648 KB Output is correct
60 Correct 548 ms 2644 KB Output is correct
61 Correct 474 ms 2524 KB Output is correct
62 Correct 11 ms 2904 KB Output is correct
63 Correct 19 ms 4440 KB Output is correct
64 Correct 23 ms 4336 KB Output is correct
65 Correct 21 ms 4304 KB Output is correct
66 Correct 28 ms 7376 KB Output is correct
67 Correct 30 ms 7632 KB Output is correct