답안 #857784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857784 2023-10-07T00:23:32 Z 12345678 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
990 ms 66140 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=3e4+5, tx=180;

int n, m, st, ed, s[nx], p[nx], dp[tx][nx], dp2[nx][2*tx];
vector<int> v[nx];
priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<tuple<int, int, int, int>>> q;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m>>s[0]>>p[0]>>s[1]>>p[1]; v[s[1]].push_back(1);
    for (int i=1; i<m-1; i++) cin>>s[i+1]>>p[i+1], v[s[i+1]].push_back(i+1);
    for (int i=0; i<tx; i++) for (int j=0; j<nx; j++) dp[i][j]=INT_MAX;
    for (int i=0; i<nx; i++) for (int j=0; j<2*tx; j++) dp2[i][j]=INT_MAX;
    int t=sqrt(n);
    if (p[0]>=t) dp2[0][tx]=0;
    else dp[p[0]][s[0]]=0;
    q.push({0, p[0], s[0], 0});
    while (!q.empty())
    {
        auto [w, c, l, idx]=q.top();
        //printf("%d %d %d %d\n", w, c, l, idx);
        q.pop();
        if (c>=t)
        {
            if (l+c<n&&w+1<dp2[idx][(l+c-s[idx])/p[idx]+tx]) dp2[idx][(l+c-s[idx])/p[idx]+tx]=w+1, q.push({w+1, c, l+c, idx});
            if (l-c>=0&&w+1<dp2[idx][(l-c-s[idx])/p[idx]+tx]) dp2[idx][(l-c-s[idx])/p[idx]+tx]=w+1, q.push({w+1, c, l-c, idx});
        }
        else
        {
            if (l+c<n&&w+1<dp[c][l+c]) dp[c][l+c]=w+1, q.push({w+1, c, l+c, idx});
            if (l-c>=0&&w+1<dp[c][l-c]) dp[c][l-c]=w+1, q.push({w+1, c, l-c, idx});
        }
        for (auto nw:v[l])
        {
            if (nw==1)
            {
                cout<<w;
                return 0;
            }
            if (p[nw]>=t&&w<dp2[nw][tx]) dp2[nw][tx]=w, q.push({w, p[nw], l, nw});
            if (p[nw]<t&&w<dp[p[nw]][l]) dp[p[nw]][l]=w, q.push({w, p[nw], l, nw});
        }
    }
    cout<<-1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 64344 KB Output is correct
2 Correct 13 ms 64584 KB Output is correct
3 Correct 13 ms 64344 KB Output is correct
4 Correct 12 ms 64532 KB Output is correct
5 Correct 12 ms 64348 KB Output is correct
6 Correct 12 ms 64512 KB Output is correct
7 Correct 12 ms 64348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 64564 KB Output is correct
2 Correct 12 ms 64348 KB Output is correct
3 Correct 12 ms 64428 KB Output is correct
4 Correct 15 ms 64344 KB Output is correct
5 Correct 16 ms 64344 KB Output is correct
6 Correct 13 ms 64348 KB Output is correct
7 Correct 12 ms 64348 KB Output is correct
8 Correct 12 ms 64348 KB Output is correct
9 Correct 12 ms 64416 KB Output is correct
10 Correct 12 ms 64600 KB Output is correct
11 Correct 14 ms 64604 KB Output is correct
12 Correct 12 ms 64608 KB Output is correct
13 Correct 12 ms 64604 KB Output is correct
14 Correct 13 ms 64604 KB Output is correct
15 Correct 13 ms 64760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 64348 KB Output is correct
2 Correct 12 ms 64548 KB Output is correct
3 Correct 12 ms 64416 KB Output is correct
4 Correct 12 ms 64348 KB Output is correct
5 Correct 12 ms 64344 KB Output is correct
6 Correct 12 ms 64348 KB Output is correct
7 Correct 12 ms 64344 KB Output is correct
8 Correct 12 ms 64348 KB Output is correct
9 Correct 14 ms 64524 KB Output is correct
10 Correct 12 ms 64816 KB Output is correct
11 Correct 12 ms 64604 KB Output is correct
12 Correct 12 ms 64456 KB Output is correct
13 Correct 12 ms 64600 KB Output is correct
14 Correct 14 ms 64608 KB Output is correct
15 Correct 12 ms 64604 KB Output is correct
16 Correct 12 ms 64440 KB Output is correct
17 Correct 15 ms 64604 KB Output is correct
18 Correct 15 ms 64596 KB Output is correct
19 Correct 12 ms 64604 KB Output is correct
20 Correct 12 ms 64604 KB Output is correct
21 Correct 12 ms 64604 KB Output is correct
22 Correct 12 ms 64600 KB Output is correct
23 Correct 12 ms 64596 KB Output is correct
24 Correct 13 ms 64600 KB Output is correct
25 Correct 12 ms 64604 KB Output is correct
26 Correct 12 ms 64604 KB Output is correct
27 Correct 13 ms 64604 KB Output is correct
28 Correct 13 ms 64668 KB Output is correct
29 Correct 17 ms 64604 KB Output is correct
30 Correct 13 ms 64344 KB Output is correct
31 Correct 16 ms 64572 KB Output is correct
32 Correct 14 ms 64604 KB Output is correct
33 Correct 24 ms 64440 KB Output is correct
34 Correct 20 ms 64604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 64344 KB Output is correct
2 Correct 12 ms 64348 KB Output is correct
3 Correct 12 ms 64344 KB Output is correct
4 Correct 15 ms 64348 KB Output is correct
5 Correct 12 ms 64348 KB Output is correct
6 Correct 12 ms 64348 KB Output is correct
7 Correct 12 ms 64344 KB Output is correct
8 Correct 12 ms 64592 KB Output is correct
9 Correct 12 ms 64348 KB Output is correct
10 Correct 14 ms 64604 KB Output is correct
11 Correct 12 ms 64604 KB Output is correct
12 Correct 12 ms 64456 KB Output is correct
13 Correct 12 ms 64624 KB Output is correct
14 Correct 13 ms 64568 KB Output is correct
15 Correct 12 ms 64604 KB Output is correct
16 Correct 12 ms 64604 KB Output is correct
17 Correct 12 ms 64688 KB Output is correct
18 Correct 16 ms 64604 KB Output is correct
19 Correct 15 ms 64600 KB Output is correct
20 Correct 14 ms 64600 KB Output is correct
21 Correct 12 ms 64604 KB Output is correct
22 Correct 12 ms 64564 KB Output is correct
23 Correct 13 ms 64600 KB Output is correct
24 Correct 13 ms 64604 KB Output is correct
25 Correct 13 ms 64600 KB Output is correct
26 Correct 12 ms 64604 KB Output is correct
27 Correct 13 ms 64452 KB Output is correct
28 Correct 15 ms 64604 KB Output is correct
29 Correct 19 ms 64604 KB Output is correct
30 Correct 13 ms 64344 KB Output is correct
31 Correct 16 ms 64600 KB Output is correct
32 Correct 14 ms 64600 KB Output is correct
33 Correct 24 ms 64604 KB Output is correct
34 Correct 20 ms 64604 KB Output is correct
35 Correct 24 ms 65496 KB Output is correct
36 Correct 12 ms 64604 KB Output is correct
37 Correct 16 ms 65260 KB Output is correct
38 Correct 18 ms 65256 KB Output is correct
39 Correct 22 ms 64900 KB Output is correct
40 Correct 16 ms 65116 KB Output is correct
41 Correct 19 ms 65620 KB Output is correct
42 Correct 14 ms 64860 KB Output is correct
43 Correct 17 ms 64860 KB Output is correct
44 Correct 18 ms 64928 KB Output is correct
45 Correct 111 ms 65592 KB Output is correct
46 Correct 72 ms 65492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 64344 KB Output is correct
2 Correct 12 ms 64348 KB Output is correct
3 Correct 15 ms 64540 KB Output is correct
4 Correct 12 ms 64420 KB Output is correct
5 Correct 12 ms 64348 KB Output is correct
6 Correct 12 ms 64344 KB Output is correct
7 Correct 12 ms 64348 KB Output is correct
8 Correct 12 ms 64348 KB Output is correct
9 Correct 12 ms 64348 KB Output is correct
10 Correct 12 ms 64604 KB Output is correct
11 Correct 12 ms 64604 KB Output is correct
12 Correct 12 ms 64448 KB Output is correct
13 Correct 12 ms 64604 KB Output is correct
14 Correct 13 ms 64456 KB Output is correct
15 Correct 15 ms 64596 KB Output is correct
16 Correct 12 ms 64348 KB Output is correct
17 Correct 14 ms 64452 KB Output is correct
18 Correct 13 ms 64604 KB Output is correct
19 Correct 12 ms 64604 KB Output is correct
20 Correct 13 ms 64628 KB Output is correct
21 Correct 12 ms 64604 KB Output is correct
22 Correct 12 ms 64600 KB Output is correct
23 Correct 12 ms 64856 KB Output is correct
24 Correct 13 ms 64640 KB Output is correct
25 Correct 12 ms 64604 KB Output is correct
26 Correct 12 ms 64620 KB Output is correct
27 Correct 13 ms 64600 KB Output is correct
28 Correct 15 ms 64600 KB Output is correct
29 Correct 18 ms 64600 KB Output is correct
30 Correct 13 ms 64348 KB Output is correct
31 Correct 15 ms 64604 KB Output is correct
32 Correct 14 ms 64604 KB Output is correct
33 Correct 27 ms 64552 KB Output is correct
34 Correct 19 ms 64688 KB Output is correct
35 Correct 21 ms 65496 KB Output is correct
36 Correct 13 ms 64684 KB Output is correct
37 Correct 21 ms 65240 KB Output is correct
38 Correct 19 ms 65336 KB Output is correct
39 Correct 16 ms 64860 KB Output is correct
40 Correct 16 ms 64976 KB Output is correct
41 Correct 18 ms 65496 KB Output is correct
42 Correct 15 ms 65052 KB Output is correct
43 Correct 16 ms 64860 KB Output is correct
44 Correct 17 ms 64808 KB Output is correct
45 Correct 100 ms 65496 KB Output is correct
46 Correct 96 ms 65484 KB Output is correct
47 Correct 19 ms 65372 KB Output is correct
48 Correct 16 ms 65372 KB Output is correct
49 Correct 16 ms 65364 KB Output is correct
50 Correct 14 ms 65116 KB Output is correct
51 Correct 26 ms 66024 KB Output is correct
52 Correct 29 ms 66140 KB Output is correct
53 Correct 18 ms 65628 KB Output is correct
54 Correct 12 ms 64348 KB Output is correct
55 Correct 14 ms 64348 KB Output is correct
56 Correct 18 ms 65884 KB Output is correct
57 Correct 15 ms 64604 KB Output is correct
58 Correct 16 ms 65112 KB Output is correct
59 Correct 17 ms 65120 KB Output is correct
60 Correct 16 ms 65116 KB Output is correct
61 Correct 18 ms 65136 KB Output is correct
62 Correct 38 ms 66060 KB Output is correct
63 Correct 330 ms 65856 KB Output is correct
64 Correct 415 ms 65896 KB Output is correct
65 Correct 632 ms 65748 KB Output is correct
66 Correct 990 ms 65840 KB Output is correct
67 Correct 601 ms 65860 KB Output is correct