답안 #539241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539241 2022-03-18T15:27:48 Z timreizin Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 63196 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <cassert>

using namespace std;

#define short int

const short INF = 1e9;

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());
        dp[i].resize(D + canGet[i].size());
        for (int j = 0; j < canGet[i].size(); ++j) dp[i][D + j] = INF;
    }
    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:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j = 0; j < canGet[i].size(); ++j) dp[i][D + j] = INF;
      |                         ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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
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 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 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 468 KB Output is correct
17 Correct 3 ms 1492 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 3 ms 2880 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 3 ms 2504 KB Output is correct
24 Correct 4 ms 3144 KB Output is correct
25 Correct 4 ms 3272 KB Output is correct
26 Correct 2 ms 2000 KB Output is correct
27 Correct 2 ms 2388 KB Output is correct
28 Correct 4 ms 3144 KB Output is correct
29 Correct 3 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 5 ms 1864 KB Output is correct
34 Correct 4 ms 1860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 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
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 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 584 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 3 ms 2900 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 3 ms 2504 KB Output is correct
24 Correct 4 ms 3156 KB Output is correct
25 Correct 3 ms 3412 KB Output is correct
26 Correct 3 ms 2004 KB Output is correct
27 Correct 3 ms 2388 KB Output is correct
28 Correct 5 ms 3156 KB Output is correct
29 Correct 4 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 5 ms 1876 KB Output is correct
34 Correct 4 ms 1888 KB Output is correct
35 Correct 16 ms 3480 KB Output is correct
36 Correct 5 ms 2080 KB Output is correct
37 Correct 27 ms 4308 KB Output is correct
38 Correct 31 ms 4624 KB Output is correct
39 Correct 30 ms 4692 KB Output is correct
40 Correct 25 ms 4652 KB Output is correct
41 Correct 25 ms 4692 KB Output is correct
42 Correct 6 ms 2556 KB Output is correct
43 Correct 7 ms 2900 KB Output is correct
44 Correct 7 ms 2516 KB Output is correct
45 Correct 31 ms 5260 KB Output is correct
46 Correct 33 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 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
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 324 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 460 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2884 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 4 ms 2644 KB Output is correct
23 Correct 2 ms 2516 KB Output is correct
24 Correct 3 ms 3176 KB Output is correct
25 Correct 3 ms 3284 KB Output is correct
26 Correct 2 ms 1996 KB Output is correct
27 Correct 2 ms 2384 KB Output is correct
28 Correct 4 ms 3156 KB Output is correct
29 Correct 3 ms 1876 KB Output is correct
30 Correct 2 ms 1852 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 5 ms 1864 KB Output is correct
34 Correct 4 ms 1864 KB Output is correct
35 Correct 18 ms 3476 KB Output is correct
36 Correct 4 ms 2132 KB Output is correct
37 Correct 25 ms 4320 KB Output is correct
38 Correct 27 ms 4664 KB Output is correct
39 Correct 56 ms 4696 KB Output is correct
40 Correct 38 ms 4628 KB Output is correct
41 Correct 26 ms 4672 KB Output is correct
42 Correct 7 ms 2508 KB Output is correct
43 Correct 7 ms 2900 KB Output is correct
44 Correct 7 ms 2516 KB Output is correct
45 Correct 31 ms 5216 KB Output is correct
46 Correct 37 ms 5196 KB Output is correct
47 Correct 128 ms 22164 KB Output is correct
48 Correct 40 ms 36900 KB Output is correct
49 Correct 39 ms 39828 KB Output is correct
50 Correct 40 ms 43028 KB Output is correct
51 Correct 102 ms 47612 KB Output is correct
52 Correct 93 ms 47644 KB Output is correct
53 Correct 56 ms 42608 KB Output is correct
54 Correct 14 ms 23976 KB Output is correct
55 Correct 13 ms 24020 KB Output is correct
56 Correct 20 ms 25128 KB Output is correct
57 Correct 41 ms 24132 KB Output is correct
58 Correct 19 ms 24504 KB Output is correct
59 Correct 30 ms 24732 KB Output is correct
60 Correct 38 ms 35540 KB Output is correct
61 Correct 42 ms 38056 KB Output is correct
62 Correct 127 ms 48368 KB Output is correct
63 Correct 993 ms 62868 KB Output is correct
64 Execution timed out 1081 ms 63196 KB Time limit exceeded
65 Halted 0 ms 0 KB -