답안 #297589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297589 2020-09-11T16:11:14 Z AaronNaidu Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
99 ms 75524 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, m, b, p;
vector<int> doges[50000];
int matrix[3000][3000];
int powers[50000];
int positions[50000];
priority_queue<pair<int, int> > q;
int dists[50000];
bool visited[50000];
bool visited2[3000][3000]; //position then power
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> b >> p;
        powers[i] = p;
        positions[i] = b;
        doges[b].push_back(i);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            matrix[i][j] = 1000000009;
        }
        dists[i] = 1000000000;
    }
    for (int i = 0; i < m; i++)
    {
        int jumpCount = -1;
        for (int j = positions[i]; j < n; j+=powers[i])
        {
            jumpCount++;
            matrix[positions[i]][j] = min(matrix[positions[i]][j], jumpCount);
        }
        jumpCount = 0;
        for (int j = positions[i]-powers[i]; j >= 0; j-=powers[i])
        {
            jumpCount++;
            matrix[positions[i]][j] = min(matrix[positions[i]][j], jumpCount);
        }
        
    }
    /*for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << matrix[i][j] << " ";
        }
        cout << "\n";
    }*/
    
    q.push({0, positions[0]});
    dists[positions[0]] = 0;
    while (!q.empty()) 
    {
        int x = q.top().second;
        //cout << "At node " << x << " which is " << dists[x] << " away\n";
        if (x == positions[1])
        {
            int ans = dists[positions[1]];
            cout << ans << "\n";
            return 0;
        }
        q.pop();
        if (visited[x])
        {
            continue;
        }
        visited[x] = true;
        for (int i = 0; i < n; i++)
        {
            if (!visited[i] and dists[x] + matrix[x][i] < dists[i])
            {
                dists[i] = dists[x] + matrix[x][i];
                q.push({-dists[i], i});
                //cout << "Pushing " << 
            }
        }   
    }
    cout << "-1\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 2 ms 1536 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 2 ms 1568 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 1 ms 1664 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 2 ms 2048 KB Output is correct
11 Correct 2 ms 2048 KB Output is correct
12 Correct 2 ms 2048 KB Output is correct
13 Correct 2 ms 2048 KB Output is correct
14 Correct 2 ms 2048 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1568 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 2 ms 1664 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 1 ms 1696 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 2048 KB Output is correct
11 Correct 2 ms 2048 KB Output is correct
12 Correct 2 ms 2048 KB Output is correct
13 Correct 2 ms 2024 KB Output is correct
14 Correct 2 ms 2048 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 7 ms 6784 KB Output is correct
18 Correct 13 ms 20480 KB Output is correct
19 Correct 16 ms 25088 KB Output is correct
20 Correct 26 ms 25208 KB Output is correct
21 Correct 3 ms 3712 KB Output is correct
22 Correct 14 ms 21140 KB Output is correct
23 Correct 18 ms 17920 KB Output is correct
24 Correct 25 ms 23424 KB Output is correct
25 Correct 18 ms 25088 KB Output is correct
26 Correct 24 ms 25088 KB Output is correct
27 Correct 26 ms 25216 KB Output is correct
28 Correct 23 ms 25088 KB Output is correct
29 Correct 21 ms 25088 KB Output is correct
30 Correct 21 ms 25088 KB Output is correct
31 Correct 24 ms 25216 KB Output is correct
32 Correct 22 ms 25088 KB Output is correct
33 Correct 21 ms 25216 KB Output is correct
34 Correct 21 ms 25216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1568 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 1 ms 1664 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 2 ms 2048 KB Output is correct
11 Correct 2 ms 2176 KB Output is correct
12 Correct 2 ms 2048 KB Output is correct
13 Correct 2 ms 2048 KB Output is correct
14 Correct 2 ms 2048 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 6 ms 6784 KB Output is correct
18 Correct 13 ms 20480 KB Output is correct
19 Correct 16 ms 25088 KB Output is correct
20 Correct 26 ms 25216 KB Output is correct
21 Correct 4 ms 3712 KB Output is correct
22 Correct 13 ms 21120 KB Output is correct
23 Correct 16 ms 17920 KB Output is correct
24 Correct 23 ms 23424 KB Output is correct
25 Correct 19 ms 25088 KB Output is correct
26 Correct 26 ms 25216 KB Output is correct
27 Correct 24 ms 25088 KB Output is correct
28 Correct 24 ms 25088 KB Output is correct
29 Correct 24 ms 25204 KB Output is correct
30 Correct 20 ms 25088 KB Output is correct
31 Correct 21 ms 25088 KB Output is correct
32 Correct 21 ms 25088 KB Output is correct
33 Correct 21 ms 25344 KB Output is correct
34 Correct 23 ms 25216 KB Output is correct
35 Correct 27 ms 16000 KB Output is correct
36 Correct 10 ms 10752 KB Output is correct
37 Correct 25 ms 24576 KB Output is correct
38 Correct 32 ms 25856 KB Output is correct
39 Correct 26 ms 25728 KB Output is correct
40 Correct 26 ms 25848 KB Output is correct
41 Correct 31 ms 25856 KB Output is correct
42 Correct 94 ms 25856 KB Output is correct
43 Correct 90 ms 25772 KB Output is correct
44 Correct 97 ms 25704 KB Output is correct
45 Correct 27 ms 25728 KB Output is correct
46 Correct 32 ms 25728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 1 ms 1664 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 2048 KB Output is correct
11 Correct 2 ms 2048 KB Output is correct
12 Correct 2 ms 2048 KB Output is correct
13 Correct 2 ms 2048 KB Output is correct
14 Correct 2 ms 2048 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 6 ms 6760 KB Output is correct
18 Correct 13 ms 20480 KB Output is correct
19 Correct 16 ms 25088 KB Output is correct
20 Correct 26 ms 25216 KB Output is correct
21 Correct 3 ms 3712 KB Output is correct
22 Correct 14 ms 21120 KB Output is correct
23 Correct 16 ms 17920 KB Output is correct
24 Correct 21 ms 23440 KB Output is correct
25 Correct 17 ms 25088 KB Output is correct
26 Correct 25 ms 25088 KB Output is correct
27 Correct 24 ms 25088 KB Output is correct
28 Correct 24 ms 25120 KB Output is correct
29 Correct 21 ms 25216 KB Output is correct
30 Correct 22 ms 25088 KB Output is correct
31 Correct 22 ms 25088 KB Output is correct
32 Correct 21 ms 25088 KB Output is correct
33 Correct 23 ms 25216 KB Output is correct
34 Correct 21 ms 25216 KB Output is correct
35 Correct 21 ms 16000 KB Output is correct
36 Correct 9 ms 10676 KB Output is correct
37 Correct 25 ms 24576 KB Output is correct
38 Correct 31 ms 25856 KB Output is correct
39 Correct 25 ms 25880 KB Output is correct
40 Correct 26 ms 25856 KB Output is correct
41 Correct 34 ms 25856 KB Output is correct
42 Correct 89 ms 25728 KB Output is correct
43 Correct 90 ms 25772 KB Output is correct
44 Correct 93 ms 25764 KB Output is correct
45 Correct 28 ms 25720 KB Output is correct
46 Correct 30 ms 25720 KB Output is correct
47 Runtime error 99 ms 75524 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -