Submission #539226

# Submission time Handle Problem Language Result Execution time Memory
539226 2022-03-18T15:19:50 Z timreizin Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
722 ms 262144 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <cassert>

using namespace std;

const short INF = 32767;


int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> doges(m);
    for (auto &[b, p] : doges) cin >> b >> p;
    const short D = 180;
    vector<vector<short>> dp(n, vector<short>(D, INF));
    vector<vector<short>> canGet(n), starts(n);
    for (auto &[b, p] : doges)
    {
        starts[b].push_back(p);
        if (p >= D) for (int i = b % p; i < n; i += p) canGet[i].push_back(p);
    }
    for (int i = 0; i < n; ++i)
    {
        sort(canGet[i].begin(), canGet[i].end());
        canGet[i].erase(unique(canGet[i].begin(), canGet[i].end()), canGet[i].end());
        sort(starts[i].begin(), starts[i].end());
        starts[i].erase(unique(starts[i].begin(), starts[i].end()), starts[i].end());
        for (int j = 0; j < canGet.size(); ++j) dp[i].push_back(INF);
    }
    if (n <= 2000)
    {
    auto getInd = [&canGet, &D](short v, short p) -> short
    {
        if (p < D) return p;
        return (short)distance(canGet[v].begin(), lower_bound(canGet[v].begin(), canGet[v].end(), p)) + (short)D;
    };
    short ind = getInd(doges[0].first, doges[0].second);
    dp[doges[0].first][ind] = 0;
    deque<pair<short, short>> dq;
    dq.emplace_back(doges[0].first, doges[0].second);
    while (!dq.empty())
    {
        auto [i, p] = dq.front();
        dq.pop_front();
        short ind = getInd(i, p);
        for (int j : starts[i])
        {
            int ind2 = getInd(i, j);
            if (dp[i][ind2] > dp[i][ind])
            {
                dp[i][ind2] = dp[i][ind];
                dq.emplace_front(i, j);
            }
        }
        starts[i].clear();
        if (i - p >= 0)
        {
            short ind2 = getInd(i - p, p);
            if (dp[i - p][ind2] > dp[i][ind] + 1)
            {
                dp[i - p][ind2] = dp[i][ind] + 1;
                dq.emplace_back(i - p, p);
            }
        }
        if (i + p < n)
        {
            short ind2 = getInd(i + p, p);
            if (dp[i + p][ind2] > dp[i][ind] + 1)
            {
                dp[i + p][ind2] = dp[i][ind] + 1;
                dq.emplace_back(i + p, p);
            }
        }
    }
    ind = getInd(doges[1].first, doges[1].second);
    if (dp[doges[1].first][ind] == INF) cout << -1;
    else cout << dp[doges[1].first][ind];
    }
    return 0;
}
//47

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<short int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (int j = 0; j < canGet.size(); ++j) dp[i].push_back(INF);
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 6 ms 2516 KB Output is correct
18 Correct 21 ms 10324 KB Output is correct
19 Correct 26 ms 11700 KB Output is correct
20 Correct 25 ms 11820 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 20 ms 10496 KB Output is correct
23 Correct 17 ms 9496 KB Output is correct
24 Correct 25 ms 11288 KB Output is correct
25 Correct 25 ms 11852 KB Output is correct
26 Correct 26 ms 11776 KB Output is correct
27 Correct 26 ms 11732 KB Output is correct
28 Correct 28 ms 11888 KB Output is correct
29 Correct 27 ms 11744 KB Output is correct
30 Correct 26 ms 11732 KB Output is correct
31 Correct 25 ms 11660 KB Output is correct
32 Correct 24 ms 11672 KB Output is correct
33 Correct 27 ms 11712 KB Output is correct
34 Correct 28 ms 11724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 396 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 616 KB Output is correct
17 Correct 6 ms 2516 KB Output is correct
18 Correct 22 ms 10324 KB Output is correct
19 Correct 30 ms 11728 KB Output is correct
20 Correct 27 ms 11744 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 20 ms 10512 KB Output is correct
23 Correct 19 ms 9472 KB Output is correct
24 Correct 26 ms 11260 KB Output is correct
25 Correct 28 ms 11776 KB Output is correct
26 Correct 27 ms 11704 KB Output is correct
27 Correct 28 ms 11696 KB Output is correct
28 Correct 30 ms 11888 KB Output is correct
29 Correct 29 ms 11716 KB Output is correct
30 Correct 26 ms 11752 KB Output is correct
31 Correct 28 ms 11728 KB Output is correct
32 Correct 27 ms 11732 KB Output is correct
33 Correct 32 ms 11732 KB Output is correct
34 Correct 28 ms 11724 KB Output is correct
35 Correct 30 ms 9088 KB Output is correct
36 Correct 10 ms 3584 KB Output is correct
37 Correct 44 ms 11992 KB Output is correct
38 Correct 49 ms 12492 KB Output is correct
39 Correct 50 ms 12420 KB Output is correct
40 Correct 49 ms 12448 KB Output is correct
41 Correct 48 ms 12492 KB Output is correct
42 Correct 30 ms 11972 KB Output is correct
43 Correct 30 ms 11988 KB Output is correct
44 Correct 29 ms 12004 KB Output is correct
45 Correct 62 ms 12812 KB Output is correct
46 Correct 57 ms 12816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 6 ms 2644 KB Output is correct
18 Correct 22 ms 10332 KB Output is correct
19 Correct 25 ms 11720 KB Output is correct
20 Correct 28 ms 11820 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 23 ms 10444 KB Output is correct
23 Correct 19 ms 9452 KB Output is correct
24 Correct 27 ms 11196 KB Output is correct
25 Correct 28 ms 11752 KB Output is correct
26 Correct 27 ms 11756 KB Output is correct
27 Correct 28 ms 11760 KB Output is correct
28 Correct 28 ms 11892 KB Output is correct
29 Correct 29 ms 11696 KB Output is correct
30 Correct 28 ms 11688 KB Output is correct
31 Correct 28 ms 11748 KB Output is correct
32 Correct 25 ms 11724 KB Output is correct
33 Correct 28 ms 11724 KB Output is correct
34 Correct 30 ms 11704 KB Output is correct
35 Correct 31 ms 9044 KB Output is correct
36 Correct 11 ms 3540 KB Output is correct
37 Correct 48 ms 12032 KB Output is correct
38 Correct 46 ms 12480 KB Output is correct
39 Correct 50 ms 12516 KB Output is correct
40 Correct 52 ms 12492 KB Output is correct
41 Correct 52 ms 12492 KB Output is correct
42 Correct 32 ms 12040 KB Output is correct
43 Correct 31 ms 12036 KB Output is correct
44 Correct 29 ms 12116 KB Output is correct
45 Correct 75 ms 12752 KB Output is correct
46 Correct 53 ms 12748 KB Output is correct
47 Runtime error 722 ms 262144 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -