답안 #1019188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019188 2024-07-10T14:57:21 Z amine_aroua Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
894 ms 41420 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
int sz;
vector<vector<int>> p;
vector<vector<int>> dist;
vector<vector<bool>> vis;
priority_queue<tuple<int ,int , int>, vector<tuple<int ,int , int>> , greater<tuple<int,int ,int>>> q;
vector<bool> reach;
int n ;
void process(int P , int tp , int last)
{
    if(P == 0)
        return;
    if(P > sz)
    {
        for(int k = 1 ; tp + k * P < n || tp - k * P >= 0 ; k++)
        {
            if(k*P + tp < n && reach[k * P + tp] && dist[k * P + tp][0] > dist[tp][last] + k)
            {
                dist[k * P + tp][0] = dist[tp][last] + k;
                q.push({dist[k * P + tp][0] , k * P + tp , 0});
            }
            if(tp - k * P >= 0 && reach[tp - k * P] &&dist[tp - k * P][0] > dist[tp][last] + k)
            {
                dist[tp - k * P][0] = dist[tp][last] + k;
                q.push({dist[tp - k * P][0] , tp - k * P , 0});
            }
        }
    }
    else
    {
        if(P + tp < n)
        {
            if(dist[P + tp][P] > dist[tp][last] + 1)
            {
                dist[P + tp][P] = dist[tp][last] + 1;
                q.push({dist[P + tp][P] , P + tp , P});
            }
        }
        if(tp - P >= 0)
        {
            if(dist[tp - P][P] > dist[tp][last] + 1)
            {
                dist[tp - P][P] = dist[tp][last] + 1;
                q.push({dist[tp - P][P] , tp - P , P});
            }
        }
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int  m;
    cin>>n>>m;
    sz = 300;
    reach.assign(n , 0);
    p = vector<vector<int>> (n);
    dist = vector<vector<int>> (n , vector<int>(sz +1 , INT32_MAX));
    vis = vector<vector<bool>> (n , vector<bool>(sz + 1 , 0));
    int trg = 0;
    for(int i = 0 ; i < m; i++)
    {
        int a , b;
        cin>>a>>b;
        reach[a] = 1;
        if(i == 0)
        {
            dist[a][0] = 0;
            q.push({0 , a , 0});
        }
        if(i == 1)
        {
            trg = a;
        }
        p[a].push_back(b);
    }
    while(!q.empty())
    {
        auto [d , tp , last] = q.top();
        q.pop();
        if(vis[tp][last])
            continue;
        vis[tp][last] = 1;
        for(auto P : p[tp])
        {
            process(P , tp , last);
        }
        process(last , tp , last);
    }
    int mn = INT32_MAX;
    for(int i = 0 ; i <= sz ; i++)
    {
        mn = min(mn , dist[trg][i]);
    }
    cout<<(mn == INT32_MAX ? -1 : mn);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 448 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 3 ms 1624 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 3 ms 3284 KB Output is correct
26 Correct 3 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 3 ms 3176 KB Output is correct
29 Correct 8 ms 2908 KB Output is correct
30 Correct 3 ms 2904 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 12 ms 3164 KB Output is correct
34 Correct 12 ms 3224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 2 ms 2980 KB Output is correct
20 Correct 2 ms 3184 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 4 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 2 ms 2904 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 3 ms 3040 KB Output is correct
29 Correct 7 ms 2908 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 13 ms 3212 KB Output is correct
34 Correct 13 ms 3164 KB Output is correct
35 Correct 22 ms 2908 KB Output is correct
36 Correct 4 ms 1880 KB Output is correct
37 Correct 38 ms 3652 KB Output is correct
38 Correct 34 ms 3868 KB Output is correct
39 Correct 36 ms 3864 KB Output is correct
40 Correct 43 ms 3868 KB Output is correct
41 Correct 34 ms 3808 KB Output is correct
42 Correct 5 ms 3420 KB Output is correct
43 Correct 4 ms 3420 KB Output is correct
44 Correct 5 ms 3516 KB Output is correct
45 Correct 162 ms 4340 KB Output is correct
46 Correct 86 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 712 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 2 ms 3164 KB Output is correct
26 Correct 2 ms 2904 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 3 ms 3164 KB Output is correct
29 Correct 6 ms 3160 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 13 ms 3164 KB Output is correct
34 Correct 12 ms 3224 KB Output is correct
35 Correct 25 ms 2908 KB Output is correct
36 Correct 4 ms 1880 KB Output is correct
37 Correct 37 ms 3612 KB Output is correct
38 Correct 33 ms 3868 KB Output is correct
39 Correct 33 ms 3868 KB Output is correct
40 Correct 35 ms 3868 KB Output is correct
41 Correct 34 ms 3868 KB Output is correct
42 Correct 5 ms 3416 KB Output is correct
43 Correct 4 ms 3420 KB Output is correct
44 Correct 4 ms 3524 KB Output is correct
45 Correct 102 ms 4444 KB Output is correct
46 Correct 91 ms 4440 KB Output is correct
47 Correct 167 ms 17688 KB Output is correct
48 Correct 21 ms 31836 KB Output is correct
49 Correct 23 ms 34648 KB Output is correct
50 Correct 23 ms 37724 KB Output is correct
51 Correct 72 ms 41316 KB Output is correct
52 Correct 77 ms 41308 KB Output is correct
53 Correct 31 ms 41040 KB Output is correct
54 Correct 22 ms 39916 KB Output is correct
55 Correct 22 ms 40024 KB Output is correct
56 Correct 28 ms 41300 KB Output is correct
57 Correct 84 ms 40252 KB Output is correct
58 Correct 29 ms 40276 KB Output is correct
59 Correct 27 ms 40540 KB Output is correct
60 Correct 30 ms 40532 KB Output is correct
61 Correct 29 ms 40520 KB Output is correct
62 Correct 54 ms 41420 KB Output is correct
63 Correct 171 ms 40480 KB Output is correct
64 Correct 269 ms 40644 KB Output is correct
65 Correct 584 ms 40976 KB Output is correct
66 Correct 894 ms 41400 KB Output is correct
67 Correct 855 ms 41308 KB Output is correct