Submission #45857

# Submission time Handle Problem Language Result Execution time Memory
45857 2018-04-16T09:29:36 Z antimirage Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
65 ms 33436 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2005, inf = 1e9 + 7;

int n, m, u[N][N], pos[N], pw[N], ans = 1e9 + 7;

vector <int> vec[N];

priority_queue < pair < int, pair <int, int> > > q;

main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &pos[i], &pw[i]);
        vec[pos[i]].pb(pw[i]);
    }
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            u[i][j] = inf;

    for (auto to : vec[ pos[0] ])
    {
        if (u[ pos[0] ][to] > 0)
        {
            q.push( mk( 0, mk(pos[0], to) ) );
            u[ pos[0] ][to] = 0;
        }
    }
    vec[ pos[0] ].clear();

    while (!q.empty() )
    {
        int v = q.top().sc.fr, cur_pow = q.top().sc.sc, cur_len = -q.top().fr;
        q.pop();

        if ( cur_len > u[v][cur_pow] ) continue;

        for (auto it : vec[v])
        {
            if (u[v][it] > u[v][cur_pow])
            {
                u[v][it] = u[v][cur_pow];
                q.push( mk(-u[v][it], mk(v, it) ) );
            }
        }
        vec[v].clear();

        if ( v - cur_pow >= 0 && u[v - cur_pow][cur_pow] > u[v][cur_pow] + 1 )
        {
            u[v - cur_pow][cur_pow] = u[v][cur_pow] + 1;
            q.push( mk(-u[v - cur_pow][cur_pow], mk(v - cur_pow, cur_pow) ) );
        }
        if ( v + cur_pow < n && u[v + cur_pow][cur_pow] > u[v][cur_pow] + 1 )
        {
            u[v + cur_pow][cur_pow] = u[v][cur_pow] + 1;

            q.push( mk( -u[v + cur_pow][cur_pow], mk(v + cur_pow, cur_pow) ) );
        }
    }
    for (int i = 0; i < m; i++)
        ans = min(ans, u[ pos[1] ][ pw[i] ] );

    if (ans == inf)
        ans = -1;

    cout << ans << endl;
}
/**
5 3
0 2
1 1
4 1
**/

Compilation message

skyscraper.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &pos[i], &pw[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16120 KB Output is correct
2 Correct 15 ms 16120 KB Output is correct
3 Correct 15 ms 16156 KB Output is correct
4 Correct 15 ms 16188 KB Output is correct
5 Correct 16 ms 16188 KB Output is correct
6 Correct 17 ms 16232 KB Output is correct
7 Correct 14 ms 16360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16360 KB Output is correct
2 Correct 15 ms 16360 KB Output is correct
3 Correct 14 ms 16360 KB Output is correct
4 Correct 14 ms 16360 KB Output is correct
5 Correct 19 ms 16360 KB Output is correct
6 Correct 18 ms 16360 KB Output is correct
7 Correct 14 ms 16360 KB Output is correct
8 Correct 15 ms 16360 KB Output is correct
9 Correct 14 ms 16360 KB Output is correct
10 Correct 15 ms 16360 KB Output is correct
11 Correct 15 ms 16360 KB Output is correct
12 Correct 15 ms 16360 KB Output is correct
13 Correct 19 ms 16360 KB Output is correct
14 Correct 16 ms 16360 KB Output is correct
15 Correct 19 ms 16360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16360 KB Output is correct
2 Correct 19 ms 16360 KB Output is correct
3 Correct 15 ms 16360 KB Output is correct
4 Correct 16 ms 16380 KB Output is correct
5 Correct 15 ms 16380 KB Output is correct
6 Correct 15 ms 16380 KB Output is correct
7 Correct 17 ms 16380 KB Output is correct
8 Correct 15 ms 16452 KB Output is correct
9 Correct 19 ms 16452 KB Output is correct
10 Correct 15 ms 16452 KB Output is correct
11 Correct 16 ms 16452 KB Output is correct
12 Correct 15 ms 16452 KB Output is correct
13 Correct 15 ms 16452 KB Output is correct
14 Correct 18 ms 16452 KB Output is correct
15 Correct 16 ms 16452 KB Output is correct
16 Correct 15 ms 16452 KB Output is correct
17 Correct 19 ms 16492 KB Output is correct
18 Correct 16 ms 16492 KB Output is correct
19 Correct 14 ms 16492 KB Output is correct
20 Correct 16 ms 16492 KB Output is correct
21 Correct 15 ms 16492 KB Output is correct
22 Correct 15 ms 16492 KB Output is correct
23 Correct 16 ms 16492 KB Output is correct
24 Correct 17 ms 16492 KB Output is correct
25 Correct 18 ms 16492 KB Output is correct
26 Correct 20 ms 16492 KB Output is correct
27 Correct 15 ms 16492 KB Output is correct
28 Correct 18 ms 16492 KB Output is correct
29 Correct 22 ms 16492 KB Output is correct
30 Correct 17 ms 16492 KB Output is correct
31 Correct 19 ms 16492 KB Output is correct
32 Correct 20 ms 16492 KB Output is correct
33 Correct 32 ms 16492 KB Output is correct
34 Correct 35 ms 16492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16492 KB Output is correct
2 Correct 19 ms 16492 KB Output is correct
3 Correct 16 ms 16492 KB Output is correct
4 Correct 15 ms 16492 KB Output is correct
5 Correct 18 ms 16508 KB Output is correct
6 Correct 15 ms 16508 KB Output is correct
7 Correct 15 ms 16508 KB Output is correct
8 Correct 18 ms 16508 KB Output is correct
9 Correct 14 ms 16508 KB Output is correct
10 Correct 15 ms 16508 KB Output is correct
11 Correct 21 ms 16508 KB Output is correct
12 Correct 17 ms 16508 KB Output is correct
13 Correct 19 ms 16508 KB Output is correct
14 Correct 18 ms 16508 KB Output is correct
15 Correct 17 ms 16508 KB Output is correct
16 Correct 15 ms 16508 KB Output is correct
17 Correct 21 ms 16508 KB Output is correct
18 Correct 16 ms 16508 KB Output is correct
19 Correct 16 ms 16508 KB Output is correct
20 Correct 19 ms 16508 KB Output is correct
21 Correct 18 ms 16508 KB Output is correct
22 Correct 19 ms 16508 KB Output is correct
23 Correct 16 ms 16508 KB Output is correct
24 Correct 24 ms 16508 KB Output is correct
25 Correct 17 ms 16508 KB Output is correct
26 Correct 20 ms 16508 KB Output is correct
27 Correct 17 ms 16508 KB Output is correct
28 Correct 18 ms 16508 KB Output is correct
29 Correct 31 ms 16508 KB Output is correct
30 Correct 22 ms 16508 KB Output is correct
31 Correct 19 ms 16508 KB Output is correct
32 Correct 17 ms 16508 KB Output is correct
33 Correct 37 ms 16508 KB Output is correct
34 Correct 33 ms 16508 KB Output is correct
35 Runtime error 63 ms 33336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 33336 KB Output is correct
2 Correct 17 ms 33336 KB Output is correct
3 Correct 15 ms 33336 KB Output is correct
4 Correct 14 ms 33336 KB Output is correct
5 Correct 15 ms 33336 KB Output is correct
6 Correct 16 ms 33336 KB Output is correct
7 Correct 15 ms 33336 KB Output is correct
8 Correct 14 ms 33336 KB Output is correct
9 Correct 15 ms 33336 KB Output is correct
10 Correct 15 ms 33336 KB Output is correct
11 Correct 15 ms 33336 KB Output is correct
12 Correct 15 ms 33336 KB Output is correct
13 Correct 14 ms 33336 KB Output is correct
14 Correct 16 ms 33336 KB Output is correct
15 Correct 15 ms 33336 KB Output is correct
16 Correct 15 ms 33336 KB Output is correct
17 Correct 18 ms 33336 KB Output is correct
18 Correct 18 ms 33336 KB Output is correct
19 Correct 14 ms 33336 KB Output is correct
20 Correct 15 ms 33336 KB Output is correct
21 Correct 16 ms 33336 KB Output is correct
22 Correct 14 ms 33336 KB Output is correct
23 Correct 16 ms 33336 KB Output is correct
24 Correct 19 ms 33336 KB Output is correct
25 Correct 15 ms 33336 KB Output is correct
26 Correct 15 ms 33336 KB Output is correct
27 Correct 16 ms 33336 KB Output is correct
28 Correct 17 ms 33336 KB Output is correct
29 Correct 22 ms 33336 KB Output is correct
30 Correct 16 ms 33336 KB Output is correct
31 Correct 18 ms 33336 KB Output is correct
32 Correct 18 ms 33336 KB Output is correct
33 Correct 31 ms 33336 KB Output is correct
34 Correct 31 ms 33336 KB Output is correct
35 Runtime error 65 ms 33436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -