Submission #132198

# Submission time Handle Problem Language Result Execution time Memory
132198 2019-07-18T12:56:10 Z shafinalam Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
595 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;
const int mxn = 3e4+5;
typedef pair<int,int>pii;
vector<pii>adj[mxn];
vector<pii>tmp;
int dis[mxn];
int n, m;
int dijkstra(int src, int des)
{
    priority_queue<pii, vector<pii>, greater<pii> >pq;
    for(int i = 0; i < n; i++) dis[i] = 999999999;
    dis[src] = 0;
    pq.push(make_pair(0, src));

    while(!pq.empty())
    {
        pii cur = pq.top();
        int u = cur.second;
        int cost = cur.first;
        pq.pop();
        for(pii x : adj[u])
        {
            int v = x.first;
            int w = x.second;
            if(dis[v]>w+cost)
            {
                dis[v] = w+cost;
                pq.push(make_pair(dis[v], v));
            }
        }
    }
    return dis[des];
}
int main()
{
    scanf("%d%d", &n, &m);

    int src, des;
    for(int i = 0; i < m; i++)
    {
        int b, p;
        scanf("%d%d", &b, &p);
        if(i==0) src = b;
        if(i==1) des = b;
        tmp.push_back(make_pair(b, p));
    }
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for(int i = 0; i < tmp.size(); i++)
    {
        int b = tmp[i].first;
        int p = tmp[i].second;

        int x = b+p, k = 1;
        while(x<n)
        {
            adj[b].push_back(make_pair(x, k));
            x+=p;
            k++;
        }
        x = b-p, k = 1;
        while(x>=0)
        {
            adj[b].push_back(make_pair(x, k));
            x-=p;
            k++;
        }
    }
    int ans = dijkstra(src, des);
    if(ans==999999999) cout << -1 << '\n';
    else cout << ans << '\n';
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < tmp.size(); i++)
                    ~~^~~~~~~~~~~~
skyscraper.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &b, &p);
         ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:71:32: warning: 'des' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ans = dijkstra(src, des);
                                ^
skyscraper.cpp:71:32: warning: 'src' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 2 ms 1016 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 1016 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 2 ms 1020 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 1016 KB Output is correct
7 Correct 2 ms 1020 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 78 ms 33144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1144 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 6 ms 1912 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 4 ms 1500 KB Output is correct
32 Correct 4 ms 1400 KB Output is correct
33 Correct 10 ms 2552 KB Output is correct
34 Correct 10 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 2 ms 1020 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 2 ms 1148 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 77 ms 33144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1144 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 6 ms 1912 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 5 ms 1528 KB Output is correct
32 Correct 5 ms 1400 KB Output is correct
33 Correct 9 ms 2552 KB Output is correct
34 Correct 10 ms 2556 KB Output is correct
35 Correct 16 ms 2804 KB Output is correct
36 Correct 6 ms 1272 KB Output is correct
37 Correct 17 ms 4340 KB Output is correct
38 Correct 20 ms 3828 KB Output is correct
39 Correct 20 ms 3956 KB Output is correct
40 Correct 20 ms 3956 KB Output is correct
41 Correct 22 ms 3700 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 9 ms 1656 KB Output is correct
44 Correct 77 ms 33652 KB Output is correct
45 Correct 25 ms 6136 KB Output is correct
46 Correct 25 ms 6132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 77 ms 33144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1144 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 6 ms 1912 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 4 ms 1528 KB Output is correct
32 Correct 4 ms 1400 KB Output is correct
33 Correct 9 ms 2552 KB Output is correct
34 Correct 9 ms 2552 KB Output is correct
35 Correct 15 ms 2808 KB Output is correct
36 Correct 5 ms 1272 KB Output is correct
37 Correct 18 ms 4312 KB Output is correct
38 Correct 20 ms 3828 KB Output is correct
39 Correct 21 ms 4084 KB Output is correct
40 Correct 20 ms 3828 KB Output is correct
41 Correct 20 ms 3700 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 9 ms 1656 KB Output is correct
44 Correct 78 ms 33648 KB Output is correct
45 Correct 25 ms 6004 KB Output is correct
46 Correct 25 ms 6132 KB Output is correct
47 Correct 54 ms 12852 KB Output is correct
48 Correct 17 ms 3956 KB Output is correct
49 Correct 15 ms 3060 KB Output is correct
50 Correct 12 ms 2940 KB Output is correct
51 Correct 47 ms 6704 KB Output is correct
52 Correct 47 ms 6648 KB Output is correct
53 Correct 21 ms 3316 KB Output is correct
54 Correct 5 ms 1656 KB Output is correct
55 Correct 6 ms 2040 KB Output is correct
56 Runtime error 595 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -