Submission #108886

# Submission time Handle Problem Language Result Execution time Memory
108886 2019-05-02T11:11:17 Z kuroni Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
210 ms 79140 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#define fi first
#define se second
using namespace std;
    
const int N = 30005, D = 180, MX = 5E5 + 5, INF = 1E9 + 7;
    
int n, m, d, b, p, st, en, dis[N][D];
vector<int> dif[N];
vector<pair<int, int>> ve[MX];
    
void mini(pair<int, int> u, int v)
{
    if (dis[u.fi][u.se] > v)
    {
        dis[u.fi][u.se] = v;
        ve[v].push_back(u);
    }
}
    
void dijkstra()
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < d; j++)
            dis[i][j] = INF;
    dis[st][0] = 0; ve[0].push_back({st, 0});
    for (int i = 0; i < MX; i++)
        while (!ve[i].empty())
        {
            pair<int, int> u = ve[i].back(); ve[i].pop_back();
            if (u.se == 0)
            {
                for (int &v : dif[u.fi])
                {
                    if (v < d)
                        mini({u.fi, v}, i);
                    else
                        for (int j = u.fi % v; j < n; j += v)
                            mini({j, 0}, i + abs(u.fi - j) / v);
                }
            }
            else
            {
                mini({u.fi, 0}, i);
                if (u.fi + u.se < n)
                    mini({u.fi + u.se, u.se}, i + 1);
                if (u.fi - u.se >= 0)
                    mini({u.fi - u.se, u.se}, i + 1);
            }
        }
    printf("%d\n", dis[en][0] == INF ? -1 : dis[en][0]);
}
    
int main()
{
    scanf("%d%d", &n, &m);
    d = sqrt(n - 1) + 1;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &b, &p);
        if (i == 0)
            st = b;
        else if (i == 1)
            en = b;
        dif[b].push_back(p);
    }
    for (int i = 0; i < n; i++)
    {
        sort(dif[i].begin(), dif[i].end());
        dif[i].erase(unique(dif[i].begin(), dif[i].end()), dif[i].end());
    }
    dijkstra();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60: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:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &b, &p);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12800 KB Output is correct
2 Correct 17 ms 12800 KB Output is correct
3 Correct 16 ms 12800 KB Output is correct
4 Correct 16 ms 12800 KB Output is correct
5 Correct 17 ms 12800 KB Output is correct
6 Correct 16 ms 12800 KB Output is correct
7 Correct 15 ms 12800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 12816 KB Output is correct
2 Correct 15 ms 12800 KB Output is correct
3 Correct 16 ms 12800 KB Output is correct
4 Correct 16 ms 12800 KB Output is correct
5 Correct 18 ms 12800 KB Output is correct
6 Correct 15 ms 12800 KB Output is correct
7 Correct 16 ms 12800 KB Output is correct
8 Correct 16 ms 12800 KB Output is correct
9 Correct 16 ms 12800 KB Output is correct
10 Correct 16 ms 12800 KB Output is correct
11 Correct 16 ms 12928 KB Output is correct
12 Correct 14 ms 12800 KB Output is correct
13 Correct 15 ms 12928 KB Output is correct
14 Correct 15 ms 12928 KB Output is correct
15 Correct 17 ms 12800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12800 KB Output is correct
2 Correct 16 ms 12800 KB Output is correct
3 Correct 14 ms 12800 KB Output is correct
4 Correct 14 ms 12800 KB Output is correct
5 Correct 16 ms 12800 KB Output is correct
6 Correct 15 ms 12800 KB Output is correct
7 Correct 15 ms 12800 KB Output is correct
8 Correct 15 ms 12800 KB Output is correct
9 Correct 15 ms 12800 KB Output is correct
10 Correct 14 ms 12800 KB Output is correct
11 Correct 17 ms 12928 KB Output is correct
12 Correct 16 ms 12672 KB Output is correct
13 Correct 16 ms 12928 KB Output is correct
14 Correct 17 ms 12808 KB Output is correct
15 Correct 17 ms 12800 KB Output is correct
16 Correct 15 ms 12928 KB Output is correct
17 Correct 17 ms 13440 KB Output is correct
18 Correct 17 ms 13952 KB Output is correct
19 Correct 16 ms 14208 KB Output is correct
20 Correct 16 ms 14336 KB Output is correct
21 Correct 16 ms 13056 KB Output is correct
22 Correct 15 ms 14080 KB Output is correct
23 Correct 18 ms 13952 KB Output is correct
24 Correct 16 ms 14208 KB Output is correct
25 Correct 17 ms 14336 KB Output is correct
26 Correct 18 ms 14336 KB Output is correct
27 Correct 18 ms 14296 KB Output is correct
28 Correct 20 ms 14720 KB Output is correct
29 Correct 19 ms 14976 KB Output is correct
30 Correct 21 ms 14460 KB Output is correct
31 Correct 17 ms 14720 KB Output is correct
32 Correct 18 ms 14388 KB Output is correct
33 Correct 18 ms 15104 KB Output is correct
34 Correct 26 ms 15104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12800 KB Output is correct
2 Correct 18 ms 12800 KB Output is correct
3 Correct 14 ms 12800 KB Output is correct
4 Correct 18 ms 12800 KB Output is correct
5 Correct 15 ms 12800 KB Output is correct
6 Correct 15 ms 12800 KB Output is correct
7 Correct 17 ms 12800 KB Output is correct
8 Correct 17 ms 12800 KB Output is correct
9 Correct 18 ms 12800 KB Output is correct
10 Correct 16 ms 12928 KB Output is correct
11 Correct 17 ms 12928 KB Output is correct
12 Correct 18 ms 12900 KB Output is correct
13 Correct 14 ms 12928 KB Output is correct
14 Correct 15 ms 12904 KB Output is correct
15 Correct 16 ms 12928 KB Output is correct
16 Correct 15 ms 12928 KB Output is correct
17 Correct 16 ms 13440 KB Output is correct
18 Correct 16 ms 14080 KB Output is correct
19 Correct 16 ms 14208 KB Output is correct
20 Correct 19 ms 14336 KB Output is correct
21 Correct 14 ms 13056 KB Output is correct
22 Correct 17 ms 14052 KB Output is correct
23 Correct 17 ms 13952 KB Output is correct
24 Correct 20 ms 14208 KB Output is correct
25 Correct 17 ms 14336 KB Output is correct
26 Correct 16 ms 14336 KB Output is correct
27 Correct 23 ms 14336 KB Output is correct
28 Correct 21 ms 14720 KB Output is correct
29 Correct 19 ms 14996 KB Output is correct
30 Correct 17 ms 14336 KB Output is correct
31 Correct 17 ms 14592 KB Output is correct
32 Correct 17 ms 14336 KB Output is correct
33 Correct 19 ms 15104 KB Output is correct
34 Correct 18 ms 15104 KB Output is correct
35 Correct 23 ms 14464 KB Output is correct
36 Correct 16 ms 13696 KB Output is correct
37 Correct 24 ms 14976 KB Output is correct
38 Correct 26 ms 15104 KB Output is correct
39 Correct 33 ms 15104 KB Output is correct
40 Correct 29 ms 15224 KB Output is correct
41 Correct 27 ms 15232 KB Output is correct
42 Correct 22 ms 14592 KB Output is correct
43 Correct 23 ms 14720 KB Output is correct
44 Correct 23 ms 14712 KB Output is correct
45 Correct 26 ms 15444 KB Output is correct
46 Correct 27 ms 15488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12764 KB Output is correct
2 Correct 14 ms 12800 KB Output is correct
3 Correct 13 ms 12800 KB Output is correct
4 Correct 14 ms 12800 KB Output is correct
5 Correct 16 ms 12800 KB Output is correct
6 Correct 15 ms 12800 KB Output is correct
7 Correct 15 ms 12800 KB Output is correct
8 Correct 20 ms 12800 KB Output is correct
9 Correct 17 ms 12800 KB Output is correct
10 Correct 17 ms 12928 KB Output is correct
11 Correct 17 ms 12800 KB Output is correct
12 Correct 15 ms 12800 KB Output is correct
13 Correct 17 ms 12920 KB Output is correct
14 Correct 14 ms 12800 KB Output is correct
15 Correct 15 ms 12800 KB Output is correct
16 Correct 16 ms 12928 KB Output is correct
17 Correct 19 ms 13440 KB Output is correct
18 Correct 18 ms 13952 KB Output is correct
19 Correct 19 ms 14208 KB Output is correct
20 Correct 19 ms 14208 KB Output is correct
21 Correct 16 ms 13056 KB Output is correct
22 Correct 15 ms 14080 KB Output is correct
23 Correct 17 ms 13952 KB Output is correct
24 Correct 16 ms 14208 KB Output is correct
25 Correct 17 ms 14336 KB Output is correct
26 Correct 18 ms 14336 KB Output is correct
27 Correct 18 ms 14336 KB Output is correct
28 Correct 18 ms 14720 KB Output is correct
29 Correct 19 ms 14840 KB Output is correct
30 Correct 19 ms 14464 KB Output is correct
31 Correct 22 ms 14592 KB Output is correct
32 Correct 16 ms 14336 KB Output is correct
33 Correct 19 ms 15224 KB Output is correct
34 Correct 19 ms 15104 KB Output is correct
35 Correct 26 ms 14472 KB Output is correct
36 Correct 18 ms 13696 KB Output is correct
37 Correct 29 ms 14948 KB Output is correct
38 Correct 26 ms 15232 KB Output is correct
39 Correct 35 ms 15104 KB Output is correct
40 Correct 29 ms 15096 KB Output is correct
41 Correct 31 ms 15224 KB Output is correct
42 Correct 27 ms 14592 KB Output is correct
43 Correct 24 ms 14584 KB Output is correct
44 Correct 22 ms 14584 KB Output is correct
45 Correct 30 ms 15444 KB Output is correct
46 Correct 28 ms 15480 KB Output is correct
47 Correct 66 ms 25928 KB Output is correct
48 Correct 39 ms 29744 KB Output is correct
49 Correct 41 ms 31400 KB Output is correct
50 Correct 38 ms 32888 KB Output is correct
51 Correct 70 ms 37388 KB Output is correct
52 Correct 79 ms 37552 KB Output is correct
53 Correct 53 ms 35960 KB Output is correct
54 Correct 34 ms 34432 KB Output is correct
55 Correct 37 ms 34688 KB Output is correct
56 Correct 57 ms 36124 KB Output is correct
57 Correct 69 ms 38764 KB Output is correct
58 Correct 58 ms 35944 KB Output is correct
59 Correct 65 ms 36984 KB Output is correct
60 Correct 58 ms 36728 KB Output is correct
61 Correct 55 ms 36728 KB Output is correct
62 Correct 109 ms 43996 KB Output is correct
63 Correct 76 ms 35832 KB Output is correct
64 Correct 77 ms 36088 KB Output is correct
65 Correct 161 ms 46944 KB Output is correct
66 Correct 210 ms 79140 KB Output is correct
67 Correct 207 ms 78748 KB Output is correct