답안 #545744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545744 2022-04-05T10:38:50 Z AJ00 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
233 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9;
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";
      |             ^
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 5324 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
# 결과 실행 시간 메모리 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 1 ms 1236 KB Output is correct
12 Correct 6 ms 5212 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 1 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 2 ms 1236 KB Output is correct
23 Correct 1 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 85 ms 67036 KB Output is correct
27 Correct 88 ms 66972 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 2 ms 2004 KB Output is correct
32 Correct 2 ms 1748 KB Output is correct
33 Correct 7 ms 4048 KB Output is correct
34 Correct 6 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 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
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 1 ms 1236 KB Output is correct
24 Correct 2 ms 1552 KB Output is correct
25 Correct 2 ms 1492 KB Output is correct
26 Correct 85 ms 67068 KB Output is correct
27 Correct 85 ms 67120 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 2 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 6 ms 4048 KB Output is correct
35 Correct 16 ms 4760 KB Output is correct
36 Correct 3 ms 1632 KB Output is correct
37 Correct 20 ms 6388 KB Output is correct
38 Correct 22 ms 6436 KB Output is correct
39 Correct 22 ms 6484 KB Output is correct
40 Correct 22 ms 6484 KB Output is correct
41 Correct 22 ms 6500 KB Output is correct
42 Runtime error 231 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 5 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 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 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 2 ms 1492 KB Output is correct
26 Correct 87 ms 67116 KB Output is correct
27 Correct 83 ms 66936 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 2 ms 2004 KB Output is correct
32 Correct 2 ms 1824 KB Output is correct
33 Correct 7 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 20 ms 6436 KB Output is correct
38 Correct 22 ms 6500 KB Output is correct
39 Correct 22 ms 6580 KB Output is correct
40 Correct 23 ms 6540 KB Output is correct
41 Correct 24 ms 6476 KB Output is correct
42 Runtime error 233 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -