Submission #411724

# Submission time Handle Problem Language Result Execution time Memory
411724 2021-05-25T19:15:00 Z MasterTaster Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
371 ms 262148 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define INF 1000000000010LL
#define MAXN 30010

using namespace std;

ll d[MAXN];
int n, m;
vector<int> g[MAXN];
vector<ll> w[MAXN];

void dijkstra(int s)
{
    for (int i=0; i<n; i++) d[i]=INF;
    d[s]=0;

    set< pair<int, ll> > q;
    q.insert({0, s});

    while (!q.empty())
    {
        int u=q.begin()->second;
        q.erase(q.begin());

        for (int i=0; i<g[u].size(); i++)
        {
            int v=g[u][i];
            if (d[u]+w[u][i]<d[v])
            {
                q.erase({d[v], v});

                d[v]=d[u]+w[u][i];
                q.insert({d[v], v});
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>>n>>m;

    int poc, kraj;
    for (int i=0; i<m; i++)
    {
        int u; cin>>u;
        int p; cin>>p;

        if (i==0) poc=u;
        if (i==1) kraj=u;

        for (int j=1; u-j*p>=0; j++) { g[u].pb(u-j*p); w[u].pb(j); }
        for (int j=1; u+j*p<n; j++) { g[u].pb(u+j*p); w[u].pb(j); }
    }

    dijkstra(poc);
    if (d[kraj]==INF) cout<<-1;
    else cout<<d[kraj];
}

Compilation message

skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int i=0; i<g[u].size(); i++)
      |                       ~^~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:64:15: warning: 'kraj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     if (d[kraj]==INF) cout<<-1;
      |         ~~~~~~^
skyscraper.cpp:63:13: warning: 'poc' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |     dijkstra(poc);
      |     ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 3 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 6 ms 4472 KB Output is correct
13 Correct 6 ms 4484 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 8 ms 4536 KB Output is correct
13 Correct 6 ms 4484 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 4 ms 2124 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 73 ms 49960 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 2 ms 1740 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 4 ms 1996 KB Output is correct
25 Correct 3 ms 1992 KB Output is correct
26 Correct 85 ms 44224 KB Output is correct
27 Correct 80 ms 42932 KB Output is correct
28 Correct 4 ms 1996 KB Output is correct
29 Correct 6 ms 2764 KB Output is correct
30 Correct 4 ms 2124 KB Output is correct
31 Correct 4 ms 2392 KB Output is correct
32 Correct 3 ms 2124 KB Output is correct
33 Correct 9 ms 3660 KB Output is correct
34 Correct 8 ms 3660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1700 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 6 ms 4536 KB Output is correct
13 Correct 6 ms 4484 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 3 ms 2124 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 73 ms 49924 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 3 ms 1740 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 5 ms 1996 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 84 ms 44212 KB Output is correct
27 Correct 79 ms 42964 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 6 ms 2764 KB Output is correct
30 Correct 4 ms 2124 KB Output is correct
31 Correct 4 ms 2380 KB Output is correct
32 Correct 3 ms 2124 KB Output is correct
33 Correct 8 ms 3660 KB Output is correct
34 Correct 10 ms 3744 KB Output is correct
35 Correct 15 ms 4060 KB Output is correct
36 Correct 4 ms 1984 KB Output is correct
37 Correct 16 ms 6476 KB Output is correct
38 Correct 20 ms 5452 KB Output is correct
39 Correct 17 ms 5712 KB Output is correct
40 Correct 17 ms 5580 KB Output is correct
41 Correct 17 ms 5432 KB Output is correct
42 Runtime error 371 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 3 ms 1868 KB Output is correct
12 Correct 7 ms 4536 KB Output is correct
13 Correct 8 ms 4484 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 3 ms 2124 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 74 ms 50072 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 3 ms 1740 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 4 ms 1996 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 95 ms 44236 KB Output is correct
27 Correct 81 ms 42980 KB Output is correct
28 Correct 4 ms 1996 KB Output is correct
29 Correct 6 ms 2764 KB Output is correct
30 Correct 4 ms 2124 KB Output is correct
31 Correct 4 ms 2388 KB Output is correct
32 Correct 3 ms 2124 KB Output is correct
33 Correct 8 ms 3660 KB Output is correct
34 Correct 10 ms 3660 KB Output is correct
35 Correct 12 ms 4060 KB Output is correct
36 Correct 5 ms 1996 KB Output is correct
37 Correct 16 ms 6512 KB Output is correct
38 Correct 20 ms 5452 KB Output is correct
39 Correct 17 ms 5708 KB Output is correct
40 Correct 17 ms 5608 KB Output is correct
41 Correct 21 ms 5392 KB Output is correct
42 Runtime error 356 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -