답안 #328619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
328619 2020-11-17T11:07:36 Z Mahdi_Shokoufi Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
541 ms 7268 KB
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())

const int N = 2000 + 10;
const int M = 50000 + 10;
const ll inf = 1e18 + 10;

ll b[M], P[M], d[M];
vector < ll > vec[M];
priority_queue < pll , vector < pll > , greater < pll > > pq;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i < m; i ++){
        cin >> b[i] >> P[i];
        vec[b[i]].pb(P[i]);
    }
    fill(d, d + M, inf);
    d[b[0]] = 0;
    pq.push(mp(0, b[0]));
    while (!pq.empty()){
        ll x = pq.top().Y, c = pq.top().X;
        pq.pop();
        if (d[x] < c)
            continue;
        for (ll p : vec[x]){
            for (ll y = x, t = 0; y < n; y += p, t ++){
                if (c + t < d[y]){
                    d[y] = c + t;
                    pq.push(mp(d[y], y));
                }
            }
            for (ll y = x, t = 0; 0 <= y; y -= p, t ++){
                if (c + t < d[y]){
                    d[y] = c + t;
                    pq.push(mp(d[y], y));
                }
            }
        }
    }
    cout << (d[b[1]] >= inf ? -1 : d[b[1]]) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 2 ms 2028 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 2 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 2028 KB Output is correct
12 Correct 2 ms 2028 KB Output is correct
13 Correct 2 ms 2028 KB Output is correct
14 Correct 3 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 2 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 2 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 2028 KB Output is correct
12 Correct 2 ms 2028 KB Output is correct
13 Correct 2 ms 2028 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 4 ms 2028 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 2028 KB Output is correct
24 Correct 3 ms 2028 KB Output is correct
25 Correct 2 ms 2156 KB Output is correct
26 Correct 5 ms 2028 KB Output is correct
27 Correct 4 ms 2028 KB Output is correct
28 Correct 2 ms 2028 KB Output is correct
29 Correct 4 ms 2284 KB Output is correct
30 Correct 2 ms 2176 KB Output is correct
31 Correct 3 ms 2156 KB Output is correct
32 Correct 2 ms 2156 KB Output is correct
33 Correct 4 ms 2412 KB Output is correct
34 Correct 4 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 2 ms 1900 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 2 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 2028 KB Output is correct
12 Correct 3 ms 2028 KB Output is correct
13 Correct 2 ms 2028 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1900 KB Output is correct
19 Correct 1 ms 1900 KB Output is correct
20 Correct 6 ms 2156 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 2028 KB Output is correct
24 Correct 3 ms 2156 KB Output is correct
25 Correct 3 ms 2156 KB Output is correct
26 Correct 4 ms 2028 KB Output is correct
27 Correct 4 ms 2028 KB Output is correct
28 Correct 2 ms 2028 KB Output is correct
29 Correct 3 ms 2284 KB Output is correct
30 Correct 2 ms 2156 KB Output is correct
31 Correct 3 ms 2156 KB Output is correct
32 Correct 3 ms 2176 KB Output is correct
33 Correct 4 ms 2412 KB Output is correct
34 Correct 4 ms 2412 KB Output is correct
35 Correct 8 ms 2924 KB Output is correct
36 Correct 3 ms 2156 KB Output is correct
37 Correct 8 ms 2924 KB Output is correct
38 Correct 10 ms 3180 KB Output is correct
39 Correct 10 ms 3232 KB Output is correct
40 Correct 10 ms 3180 KB Output is correct
41 Correct 10 ms 3180 KB Output is correct
42 Correct 41 ms 2924 KB Output is correct
43 Correct 41 ms 2924 KB Output is correct
44 Correct 44 ms 2836 KB Output is correct
45 Correct 9 ms 3308 KB Output is correct
46 Correct 9 ms 3308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 28 ms 1900 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 2 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 2 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 2028 KB Output is correct
12 Correct 2 ms 2028 KB Output is correct
13 Correct 2 ms 2028 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 5 ms 2028 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 2028 KB Output is correct
24 Correct 3 ms 2028 KB Output is correct
25 Correct 3 ms 2156 KB Output is correct
26 Correct 5 ms 2028 KB Output is correct
27 Correct 4 ms 2028 KB Output is correct
28 Correct 2 ms 2028 KB Output is correct
29 Correct 3 ms 2284 KB Output is correct
30 Correct 2 ms 2156 KB Output is correct
31 Correct 3 ms 2156 KB Output is correct
32 Correct 2 ms 2156 KB Output is correct
33 Correct 4 ms 2412 KB Output is correct
34 Correct 4 ms 2412 KB Output is correct
35 Correct 8 ms 2924 KB Output is correct
36 Correct 7 ms 2156 KB Output is correct
37 Correct 9 ms 2796 KB Output is correct
38 Correct 12 ms 3180 KB Output is correct
39 Correct 10 ms 3180 KB Output is correct
40 Correct 21 ms 3180 KB Output is correct
41 Correct 116 ms 3180 KB Output is correct
42 Correct 43 ms 2924 KB Output is correct
43 Correct 41 ms 2924 KB Output is correct
44 Correct 40 ms 2836 KB Output is correct
45 Correct 9 ms 3308 KB Output is correct
46 Correct 9 ms 3308 KB Output is correct
47 Correct 19 ms 3948 KB Output is correct
48 Correct 8 ms 2924 KB Output is correct
49 Correct 8 ms 2796 KB Output is correct
50 Correct 6 ms 2668 KB Output is correct
51 Correct 39 ms 5348 KB Output is correct
52 Correct 30 ms 4584 KB Output is correct
53 Correct 19 ms 4608 KB Output is correct
54 Correct 4 ms 2288 KB Output is correct
55 Correct 3 ms 2288 KB Output is correct
56 Correct 531 ms 4208 KB Output is correct
57 Correct 54 ms 6236 KB Output is correct
58 Correct 488 ms 3184 KB Output is correct
59 Correct 541 ms 3184 KB Output is correct
60 Correct 495 ms 3184 KB Output is correct
61 Correct 471 ms 3308 KB Output is correct
62 Correct 12 ms 3692 KB Output is correct
63 Correct 38 ms 5216 KB Output is correct
64 Correct 39 ms 7268 KB Output is correct
65 Correct 51 ms 7260 KB Output is correct
66 Correct 68 ms 7264 KB Output is correct
67 Correct 64 ms 7264 KB Output is correct