Submission #545745

# Submission time Handle Problem Language Result Execution time Memory
545745 2022-04-05T10:40:54 Z AJ00 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
248 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
vector<vector<pair<int,int>>> adj(30000);
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1,n,k,st,fin; 
    cin >> n >> k;
    pair<int,int> doge[k];
    vector<set<int>> doges(n);
    vector<int> dist(n);
   // memset(dist, 0x3f, sizeof dist);
    for (int i = 0; i < k; i++){
        cin >> doge[i].first >> doge[i].second;
        doges[doge[i].first].insert(doge[i].second);
        if (i == 0){
            st = doge[i].first;
        }
        if (i == 1){
            fin = doge[i].first;
        }
    }
    sort(doge,doge+k);
    for (int i = 0; i < k; i++){
        for (int j = doge[i].first+doge[i].second; j < n; j += doge[i].second){
            adj[doge[i].first].push_back({j,((j-doge[i].first)/doge[i].second)});
            if (doges[j].find(doge[i].second) != doges[j].end()){
                break;
            }
        }
        for (int j = doge[i].first-doge[i].second; j >= 0; j -= doge[i].second){
            adj[doge[i].first].push_back({j,((doge[i].first-j)/doge[i].second)});
            if (doges[j].find(doge[i].second) != doges[j].end()){
                break;
            }
        }
    }
    for (int i = 0; i < n; i++){
        dist[i] = INF;
    }
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({0,st});
    dist[st] = 0;
    while(!pq.empty()){
        int distp = pq.top().first;
        int p = pq.top().second;
        pq.pop();
        if (distp != dist[p]){
            continue;
        }
        for (auto ch: adj[p]){
            if (dist[p] + ch.second < dist[ch.first]){
                dist[ch.first] = dist[p] + ch.second;
                pq.push({dist[ch.first],ch.first});
            }
        }
    }
    dist[fin] >= INF ? cout << "-1\n" : cout << dist[fin] << "\n";
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:10:9: warning: unused variable 't' [-Wunused-variable]
   10 |     int t=1,n,k,st,fin;
      |         ^
skyscraper.cpp:46:12: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     dist[st] = 0;
      |            ^
skyscraper.cpp:61:13: warning: 'fin' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |     dist[fin] >= INF ? cout << "-1\n" : cout << dist[fin] << "\n";
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 956 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 6 ms 5196 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 7 ms 5260 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 3 ms 1492 KB Output is correct
25 Correct 2 ms 1492 KB Output is correct
26 Correct 99 ms 67056 KB Output is correct
27 Correct 93 ms 66908 KB Output is correct
28 Correct 2 ms 1620 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 3 ms 2004 KB Output is correct
32 Correct 2 ms 1748 KB Output is correct
33 Correct 6 ms 4048 KB Output is correct
34 Correct 7 ms 4048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 3 ms 1492 KB Output is correct
26 Correct 91 ms 67064 KB Output is correct
27 Correct 90 ms 66940 KB Output is correct
28 Correct 2 ms 1620 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 3 ms 2004 KB Output is correct
32 Correct 2 ms 1748 KB Output is correct
33 Correct 8 ms 4048 KB Output is correct
34 Correct 7 ms 4048 KB Output is correct
35 Correct 17 ms 4692 KB Output is correct
36 Correct 3 ms 1748 KB Output is correct
37 Correct 19 ms 6436 KB Output is correct
38 Correct 22 ms 6540 KB Output is correct
39 Correct 22 ms 6588 KB Output is correct
40 Correct 22 ms 6616 KB Output is correct
41 Correct 27 ms 6496 KB Output is correct
42 Runtime error 248 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 6 ms 5300 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 2 ms 1492 KB Output is correct
26 Correct 87 ms 67088 KB Output is correct
27 Correct 83 ms 67012 KB Output is correct
28 Correct 2 ms 1620 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 3 ms 2004 KB Output is correct
32 Correct 2 ms 1748 KB Output is correct
33 Correct 6 ms 4048 KB Output is correct
34 Correct 7 ms 4048 KB Output is correct
35 Correct 17 ms 4676 KB Output is correct
36 Correct 3 ms 1748 KB Output is correct
37 Correct 19 ms 6484 KB Output is correct
38 Correct 22 ms 6476 KB Output is correct
39 Correct 22 ms 6556 KB Output is correct
40 Correct 22 ms 6468 KB Output is correct
41 Correct 25 ms 6464 KB Output is correct
42 Runtime error 243 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -