답안 #972356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972356 2024-04-30T11:26:10 Z Halym2007 Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
277 ms 262144 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 = 2e5 + 1;

using namespace std;

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

vector <vector<pii>> v;

priority_queue <pii> pq;

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

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];
        git[b[i]] = p[i];
    }
    v.resize(n+1);
    for(int i = 1; i <= m; i++){
        int nd = b[i], cnt = 0;
        while(1){
            nd -= p[i];
            if(nd < 0) break;
            cnt++;
            v[b[i]].pb({nd,cnt});
            if(git[nd] == p[i]) break;
        }
        nd = b[i], cnt = 0;
        while(1){
            nd += p[i];
            if(nd > n-1) break;
            cnt++;
            v[b[i]].pb({nd,cnt});
            if(git[nd] == p[i]) break;
        }
    }
    // for(int i = 0; i < n; i++){
    //     cout << i << '\n';
    //     for(auto j: v[i]) cout << j.ff << ' ' << j.ss << '\n';
    // }
    f();
    cout << (dis[b[2]] == 1e9 ? -1 : dis[b[2]]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 2 ms 3416 KB Output is correct
3 Correct 1 ms 3160 KB Output is correct
4 Correct 1 ms 3160 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3304 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 4 ms 5332 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3232 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3416 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 4 ms 5332 KB Output is correct
13 Correct 1 ms 3164 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 2 ms 3320 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 1 ms 3420 KB Output is correct
20 Correct 1 ms 3420 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3420 KB Output is correct
23 Correct 1 ms 3420 KB Output is correct
24 Correct 2 ms 3420 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 47 ms 36360 KB Output is correct
27 Correct 44 ms 37048 KB Output is correct
28 Correct 2 ms 3420 KB Output is correct
29 Correct 3 ms 4084 KB Output is correct
30 Correct 3 ms 3420 KB Output is correct
31 Correct 2 ms 3676 KB Output is correct
32 Correct 2 ms 3676 KB Output is correct
33 Correct 4 ms 4848 KB Output is correct
34 Correct 4 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 2 ms 3160 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3416 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3160 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 4 ms 5332 KB Output is correct
13 Correct 1 ms 3164 KB Output is correct
14 Correct 1 ms 3320 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3416 KB Output is correct
19 Correct 1 ms 3416 KB Output is correct
20 Correct 1 ms 3420 KB Output is correct
21 Correct 1 ms 3316 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 2 ms 3416 KB Output is correct
25 Correct 2 ms 3416 KB Output is correct
26 Correct 48 ms 36276 KB Output is correct
27 Correct 46 ms 36224 KB Output is correct
28 Correct 2 ms 3420 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 2 ms 3416 KB Output is correct
31 Correct 2 ms 3672 KB Output is correct
32 Correct 2 ms 3676 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 4 ms 4700 KB Output is correct
35 Correct 6 ms 4956 KB Output is correct
36 Correct 2 ms 3568 KB Output is correct
37 Correct 8 ms 6492 KB Output is correct
38 Correct 9 ms 5980 KB Output is correct
39 Correct 9 ms 6140 KB Output is correct
40 Correct 9 ms 6236 KB Output is correct
41 Correct 9 ms 5980 KB Output is correct
42 Runtime error 277 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3308 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3316 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 4 ms 5332 KB Output is correct
13 Correct 1 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 3168 KB Output is correct
16 Correct 1 ms 3168 KB Output is correct
17 Correct 2 ms 3424 KB Output is correct
18 Correct 1 ms 3424 KB Output is correct
19 Correct 1 ms 3680 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 1 ms 3172 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3432 KB Output is correct
24 Correct 2 ms 3332 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 47 ms 37864 KB Output is correct
27 Correct 44 ms 37056 KB Output is correct
28 Correct 2 ms 3420 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 2 ms 3672 KB Output is correct
32 Correct 2 ms 3676 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 4 ms 4696 KB Output is correct
35 Correct 6 ms 4952 KB Output is correct
36 Correct 2 ms 3420 KB Output is correct
37 Correct 8 ms 6492 KB Output is correct
38 Correct 8 ms 5980 KB Output is correct
39 Correct 9 ms 5980 KB Output is correct
40 Correct 9 ms 6236 KB Output is correct
41 Correct 9 ms 6156 KB Output is correct
42 Runtime error 274 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -