Submission #59700

# Submission time Handle Problem Language Result Execution time Memory
59700 2018-07-22T23:20:24 Z liwi Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
767 ms 16468 KB
#include <bits/stdc++.h>

using namespace std;

int num_buildings, num_dogs, target;
int dis[30000];
unordered_set<int> buildings[30000];

int main(int argc, const char * argv[]) {
    int start = 0;
    cin>>num_buildings>>num_dogs;
    for(int i=0; i<num_dogs; i++){
        int b, p; cin>>b>>p;
        buildings[b].insert(p);
        if(i == 0)
            start = b;
        if(i == 1)
            target = b;
    }
    memset(dis,0x3f,sizeof dis); dis[start] = 0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push({0,start});
    
    while(!q.empty()){
        int current_building = q.top().second; q.pop();
        if(current_building == target)
            continue;
        
        for(int check:buildings[current_building]){
            for(int i=1; i*check+current_building<num_buildings; i++){
                int next_building = i*check+current_building;
                if(dis[next_building] > dis[current_building]+i){
                    dis[next_building] = dis[current_building]+i;
                    q.push({dis[next_building],next_building});
                    if(binary_search(buildings[next_building].begin(),buildings[next_building].end(),check))
                       break;
                }
            }
            for(int i=1; current_building-i*check>=0; i++){
                int next_building = current_building-i*check;
                if(dis[next_building] > dis[current_building]+i){
                    dis[next_building] = dis[current_building]+i;
                    q.push({dis[next_building],next_building});
                    if(binary_search(buildings[next_building].begin(),buildings[next_building].end(),check))
                        break;
                }
            }
        }
    }
    cout<<(dis[target]==0x3f3f3f3f?-1:dis[target]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 5 ms 2176 KB Output is correct
3 Correct 5 ms 2256 KB Output is correct
4 Correct 5 ms 2256 KB Output is correct
5 Correct 6 ms 2312 KB Output is correct
6 Correct 5 ms 2312 KB Output is correct
7 Correct 6 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2320 KB Output is correct
2 Correct 5 ms 2320 KB Output is correct
3 Correct 4 ms 2376 KB Output is correct
4 Correct 4 ms 2376 KB Output is correct
5 Correct 5 ms 2376 KB Output is correct
6 Correct 5 ms 2376 KB Output is correct
7 Correct 5 ms 2376 KB Output is correct
8 Correct 6 ms 2376 KB Output is correct
9 Correct 5 ms 2488 KB Output is correct
10 Correct 5 ms 2488 KB Output is correct
11 Correct 6 ms 2504 KB Output is correct
12 Correct 5 ms 2504 KB Output is correct
13 Correct 5 ms 2504 KB Output is correct
14 Correct 7 ms 2568 KB Output is correct
15 Correct 6 ms 2580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2580 KB Output is correct
2 Correct 5 ms 2580 KB Output is correct
3 Correct 5 ms 2580 KB Output is correct
4 Correct 4 ms 2580 KB Output is correct
5 Correct 4 ms 2580 KB Output is correct
6 Correct 5 ms 2612 KB Output is correct
7 Correct 5 ms 2612 KB Output is correct
8 Correct 5 ms 2612 KB Output is correct
9 Correct 5 ms 2612 KB Output is correct
10 Correct 7 ms 2612 KB Output is correct
11 Correct 8 ms 2632 KB Output is correct
12 Correct 7 ms 2632 KB Output is correct
13 Correct 5 ms 2632 KB Output is correct
14 Correct 6 ms 2684 KB Output is correct
15 Correct 7 ms 2696 KB Output is correct
16 Correct 6 ms 2696 KB Output is correct
17 Correct 6 ms 2776 KB Output is correct
18 Correct 5 ms 2776 KB Output is correct
19 Correct 6 ms 2776 KB Output is correct
20 Correct 13 ms 2776 KB Output is correct
21 Correct 6 ms 2784 KB Output is correct
22 Correct 6 ms 2796 KB Output is correct
23 Correct 7 ms 2796 KB Output is correct
24 Correct 7 ms 2816 KB Output is correct
25 Correct 7 ms 2836 KB Output is correct
26 Correct 8 ms 2836 KB Output is correct
27 Correct 6 ms 2856 KB Output is correct
28 Correct 7 ms 2872 KB Output is correct
29 Correct 9 ms 3044 KB Output is correct
30 Correct 5 ms 3044 KB Output is correct
31 Correct 7 ms 3044 KB Output is correct
32 Correct 6 ms 3044 KB Output is correct
33 Correct 10 ms 3160 KB Output is correct
34 Correct 9 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3196 KB Output is correct
2 Correct 6 ms 3196 KB Output is correct
3 Correct 5 ms 3196 KB Output is correct
4 Correct 5 ms 3196 KB Output is correct
5 Correct 5 ms 3196 KB Output is correct
6 Correct 11 ms 3196 KB Output is correct
7 Correct 5 ms 3196 KB Output is correct
8 Correct 4 ms 3196 KB Output is correct
9 Correct 5 ms 3196 KB Output is correct
10 Correct 5 ms 3196 KB Output is correct
11 Correct 7 ms 3196 KB Output is correct
12 Correct 6 ms 3196 KB Output is correct
13 Correct 7 ms 3196 KB Output is correct
14 Correct 6 ms 3196 KB Output is correct
15 Correct 6 ms 3196 KB Output is correct
16 Correct 6 ms 3196 KB Output is correct
17 Correct 8 ms 3196 KB Output is correct
18 Correct 6 ms 3196 KB Output is correct
19 Correct 5 ms 3196 KB Output is correct
20 Correct 21 ms 3196 KB Output is correct
21 Correct 6 ms 3196 KB Output is correct
22 Correct 6 ms 3196 KB Output is correct
23 Correct 7 ms 3196 KB Output is correct
24 Correct 7 ms 3252 KB Output is correct
25 Correct 8 ms 3252 KB Output is correct
26 Correct 7 ms 3252 KB Output is correct
27 Correct 8 ms 3252 KB Output is correct
28 Correct 9 ms 3252 KB Output is correct
29 Correct 8 ms 3396 KB Output is correct
30 Correct 7 ms 3396 KB Output is correct
31 Correct 19 ms 3396 KB Output is correct
32 Correct 7 ms 3396 KB Output is correct
33 Correct 10 ms 3576 KB Output is correct
34 Correct 9 ms 3576 KB Output is correct
35 Correct 45 ms 4636 KB Output is correct
36 Correct 9 ms 4636 KB Output is correct
37 Correct 30 ms 4636 KB Output is correct
38 Correct 41 ms 5244 KB Output is correct
39 Correct 42 ms 5508 KB Output is correct
40 Correct 46 ms 5772 KB Output is correct
41 Correct 43 ms 6040 KB Output is correct
42 Correct 23 ms 6040 KB Output is correct
43 Correct 22 ms 6040 KB Output is correct
44 Correct 30 ms 6040 KB Output is correct
45 Correct 39 ms 6924 KB Output is correct
46 Correct 62 ms 7328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7328 KB Output is correct
2 Correct 4 ms 7328 KB Output is correct
3 Correct 6 ms 7328 KB Output is correct
4 Correct 6 ms 7328 KB Output is correct
5 Correct 5 ms 7328 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 5 ms 7328 KB Output is correct
8 Correct 4 ms 7328 KB Output is correct
9 Correct 5 ms 7328 KB Output is correct
10 Correct 7 ms 7328 KB Output is correct
11 Correct 8 ms 7328 KB Output is correct
12 Correct 8 ms 7328 KB Output is correct
13 Correct 7 ms 7328 KB Output is correct
14 Correct 6 ms 7328 KB Output is correct
15 Correct 7 ms 7328 KB Output is correct
16 Correct 6 ms 7328 KB Output is correct
17 Correct 7 ms 7328 KB Output is correct
18 Correct 9 ms 7328 KB Output is correct
19 Correct 6 ms 7328 KB Output is correct
20 Correct 12 ms 7328 KB Output is correct
21 Correct 5 ms 7328 KB Output is correct
22 Correct 5 ms 7328 KB Output is correct
23 Correct 6 ms 7328 KB Output is correct
24 Correct 9 ms 7328 KB Output is correct
25 Correct 7 ms 7328 KB Output is correct
26 Correct 7 ms 7328 KB Output is correct
27 Correct 7 ms 7328 KB Output is correct
28 Correct 7 ms 7328 KB Output is correct
29 Correct 7 ms 7328 KB Output is correct
30 Correct 6 ms 7328 KB Output is correct
31 Correct 7 ms 7328 KB Output is correct
32 Correct 8 ms 7328 KB Output is correct
33 Correct 9 ms 7328 KB Output is correct
34 Correct 8 ms 7328 KB Output is correct
35 Correct 44 ms 7428 KB Output is correct
36 Correct 13 ms 7428 KB Output is correct
37 Correct 29 ms 7448 KB Output is correct
38 Correct 64 ms 8248 KB Output is correct
39 Correct 48 ms 8512 KB Output is correct
40 Correct 43 ms 8836 KB Output is correct
41 Correct 70 ms 9032 KB Output is correct
42 Correct 40 ms 9032 KB Output is correct
43 Correct 24 ms 9032 KB Output is correct
44 Correct 27 ms 9032 KB Output is correct
45 Correct 67 ms 9932 KB Output is correct
46 Correct 52 ms 10208 KB Output is correct
47 Correct 79 ms 10736 KB Output is correct
48 Correct 37 ms 10736 KB Output is correct
49 Correct 32 ms 10736 KB Output is correct
50 Correct 27 ms 10736 KB Output is correct
51 Correct 113 ms 12092 KB Output is correct
52 Correct 95 ms 12324 KB Output is correct
53 Correct 50 ms 12324 KB Output is correct
54 Correct 7 ms 12324 KB Output is correct
55 Correct 7 ms 12324 KB Output is correct
56 Correct 767 ms 12648 KB Output is correct
57 Correct 151 ms 13108 KB Output is correct
58 Correct 27 ms 13108 KB Output is correct
59 Correct 26 ms 13108 KB Output is correct
60 Correct 37 ms 13108 KB Output is correct
61 Correct 28 ms 13108 KB Output is correct
62 Correct 54 ms 13832 KB Output is correct
63 Correct 94 ms 14548 KB Output is correct
64 Correct 80 ms 14908 KB Output is correct
65 Correct 105 ms 16032 KB Output is correct
66 Correct 224 ms 16308 KB Output is correct
67 Correct 131 ms 16468 KB Output is correct