답안 #972743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972743 2024-05-01T05:17:36 Z Gangsta Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
222 ms 64924 KB
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define sz size()

const int N = 3e4 + 5;

using namespace std;

int n, m, b[N], p[N];

vector <pii> v[N];

priority_queue <pii> pq;

vector <int> dis(N,1e9), q[N];

map <pii,int> mp;

void f(){
    pq.push({0,b[1]});
    dis[b[1]] = 0;
    while(!pq.empty()){
        int a = pq.top().ss;
        pq.pop();
        for(auto i: v[a]){
            if(dis[a] + i.ss < dis[i.ff]){
                dis[i.ff] = dis[a] + i.ss;
                pq.push({-dis[i.ff],i.ff});
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> b[i] >> p[i];
        if(mp.find({b[i],p[i]}) == mp.end()){
            mp[{b[i],p[i]}] = 1;
            q[b[i]].pb(p[i]);
        }
    }
    for(int i = 0; i < n; i++){
        for(auto j: q[i]){
            int nd = i, cnt = 0;
            while(1){
                nd -= j;
                if(nd < 0) break;
                cnt++;
                v[i].pb({nd,cnt});
                if(mp.find({nd,j}) != mp.end()) break;
            }
            nd = i, cnt = 0;
            while(1){
                nd += j;
                if(nd > n-1) break;
                cnt++;
                v[i].pb({nd,cnt});
                if(mp.find({nd,j}) != mp.end()) break;
            }
        }
    }
    f();
    cout << (dis[b[2]] == 1e9 ? -1 : dis[b[2]]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 2136 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 2136 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 1896 KB Output is correct
4 Correct 1 ms 1988 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 2 ms 2144 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
16 Correct 2 ms 1996 KB Output is correct
17 Correct 3 ms 2140 KB Output is correct
18 Correct 2 ms 2140 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 2 ms 2136 KB Output is correct
21 Correct 2 ms 1884 KB Output is correct
22 Correct 2 ms 1884 KB Output is correct
23 Correct 2 ms 2136 KB Output is correct
24 Correct 3 ms 2136 KB Output is correct
25 Correct 3 ms 2140 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 2140 KB Output is correct
28 Correct 6 ms 2396 KB Output is correct
29 Correct 3 ms 2652 KB Output is correct
30 Correct 3 ms 2140 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2140 KB Output is correct
33 Correct 5 ms 3160 KB Output is correct
34 Correct 5 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1956 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 2156 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 4 ms 2256 KB Output is correct
18 Correct 2 ms 2000 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 2 ms 2140 KB Output is correct
21 Correct 2 ms 1884 KB Output is correct
22 Correct 2 ms 1884 KB Output is correct
23 Correct 2 ms 2140 KB Output is correct
24 Correct 4 ms 2136 KB Output is correct
25 Correct 3 ms 2140 KB Output is correct
26 Correct 2 ms 2136 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 4 ms 2652 KB Output is correct
29 Correct 3 ms 2652 KB Output is correct
30 Correct 2 ms 2140 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2140 KB Output is correct
33 Correct 5 ms 3280 KB Output is correct
34 Correct 5 ms 3420 KB Output is correct
35 Correct 28 ms 5308 KB Output is correct
36 Correct 5 ms 2396 KB Output is correct
37 Correct 37 ms 5716 KB Output is correct
38 Correct 50 ms 6228 KB Output is correct
39 Correct 41 ms 6440 KB Output is correct
40 Correct 49 ms 6228 KB Output is correct
41 Correct 41 ms 6156 KB Output is correct
42 Correct 6 ms 2396 KB Output is correct
43 Correct 5 ms 2396 KB Output is correct
44 Correct 6 ms 2652 KB Output is correct
45 Correct 30 ms 8560 KB Output is correct
46 Correct 30 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1996 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 2 ms 1884 KB Output is correct
13 Correct 2 ms 2000 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 3 ms 1996 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 4 ms 2256 KB Output is correct
18 Correct 2 ms 2140 KB Output is correct
19 Correct 2 ms 1996 KB Output is correct
20 Correct 3 ms 2140 KB Output is correct
21 Correct 2 ms 2064 KB Output is correct
22 Correct 2 ms 2140 KB Output is correct
23 Correct 2 ms 2152 KB Output is correct
24 Correct 3 ms 2152 KB Output is correct
25 Correct 3 ms 2152 KB Output is correct
26 Correct 2 ms 2152 KB Output is correct
27 Correct 2 ms 2012 KB Output is correct
28 Correct 4 ms 2408 KB Output is correct
29 Correct 3 ms 2664 KB Output is correct
30 Correct 2 ms 2300 KB Output is correct
31 Correct 3 ms 2408 KB Output is correct
32 Correct 2 ms 2256 KB Output is correct
33 Correct 5 ms 3176 KB Output is correct
34 Correct 6 ms 3288 KB Output is correct
35 Correct 31 ms 5216 KB Output is correct
36 Correct 5 ms 2536 KB Output is correct
37 Correct 38 ms 5752 KB Output is correct
38 Correct 43 ms 6352 KB Output is correct
39 Correct 47 ms 6392 KB Output is correct
40 Correct 44 ms 6240 KB Output is correct
41 Correct 45 ms 6372 KB Output is correct
42 Correct 5 ms 2340 KB Output is correct
43 Correct 5 ms 2396 KB Output is correct
44 Correct 7 ms 2680 KB Output is correct
45 Correct 33 ms 8484 KB Output is correct
46 Correct 33 ms 8592 KB Output is correct
47 Correct 145 ms 13208 KB Output is correct
48 Correct 42 ms 6576 KB Output is correct
49 Correct 34 ms 5544 KB Output is correct
50 Correct 28 ms 4980 KB Output is correct
51 Correct 81 ms 8816 KB Output is correct
52 Correct 85 ms 9304 KB Output is correct
53 Correct 37 ms 6376 KB Output is correct
54 Correct 3 ms 2396 KB Output is correct
55 Correct 5 ms 2848 KB Output is correct
56 Correct 23 ms 6200 KB Output is correct
57 Correct 69 ms 11148 KB Output is correct
58 Correct 10 ms 3144 KB Output is correct
59 Correct 11 ms 3668 KB Output is correct
60 Correct 13 ms 4312 KB Output is correct
61 Correct 11 ms 3732 KB Output is correct
62 Correct 91 ms 10284 KB Output is correct
63 Correct 81 ms 25772 KB Output is correct
64 Correct 86 ms 29024 KB Output is correct
65 Correct 110 ms 38680 KB Output is correct
66 Correct 205 ms 64924 KB Output is correct
67 Correct 222 ms 64852 KB Output is correct