Submission #879551

# Submission time Handle Problem Language Result Execution time Memory
879551 2023-11-27T16:13:14 Z Shayan86 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
501 ms 4056 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

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

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 3e4 + 50;
const ll inf = 15e8;

int n, m, b[N], dist[N];

bool mark[N];
vector<int> pw[N];

void dijk(int v){
    fill(dist, dist + N, inf);

    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(Mp(0, v)); dist[v] = 0;

    while(!pq.empty()){
        int v = pq.top().S; pq.pop();
        if(mark[v]) continue;
        mark[v] = true;

        for(int p: pw[v]){
            for(int u = v+p, i = 1; u < n; u += p, i++){
                if(dist[u] > dist[v] + i){
                    dist[u] = dist[v] + i;
                    pq.push(Mp(dist[u], u));
                }
            }
            for(int u = v-p, i = 1; u >= 0; u -= p, i++){
                if(dist[u] > dist[v] + i){
                    dist[u] = dist[v] + i;
                    pq.push(Mp(dist[u], u));
                }
            }
        }
    }
}

int main(){
    fast_io;

    cin >> n >> m;

    int p;
    for(int i = 0; i < m; i++){
        cin >> b[i] >> p;
        pw[b[i]].pb(p);
    }

    dijk(b[0]);

    if(dist[b[1]] >= inf) kill(-1);
    kill(dist[b[1]]);

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1180 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1200 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 3 ms 1420 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 2 ms 1184 KB Output is correct
26 Correct 3 ms 1352 KB Output is correct
27 Correct 3 ms 1112 KB Output is correct
28 Correct 1 ms 1368 KB Output is correct
29 Correct 2 ms 1372 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1172 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1188 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 3 ms 1372 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 2 ms 1372 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 3 ms 1372 KB Output is correct
34 Correct 2 ms 1568 KB Output is correct
35 Correct 5 ms 1884 KB Output is correct
36 Correct 2 ms 1444 KB Output is correct
37 Correct 4 ms 1696 KB Output is correct
38 Correct 6 ms 2132 KB Output is correct
39 Correct 6 ms 1884 KB Output is correct
40 Correct 6 ms 2004 KB Output is correct
41 Correct 6 ms 1884 KB Output is correct
42 Correct 36 ms 1872 KB Output is correct
43 Correct 36 ms 1844 KB Output is correct
44 Correct 36 ms 1692 KB Output is correct
45 Correct 5 ms 1880 KB Output is correct
46 Correct 5 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1136 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1168 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 3 ms 1372 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1112 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 2 ms 1372 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 1 ms 1436 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 3 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 5 ms 1792 KB Output is correct
36 Correct 2 ms 1368 KB Output is correct
37 Correct 4 ms 1628 KB Output is correct
38 Correct 6 ms 1956 KB Output is correct
39 Correct 6 ms 1884 KB Output is correct
40 Correct 6 ms 1868 KB Output is correct
41 Correct 6 ms 1884 KB Output is correct
42 Correct 38 ms 1704 KB Output is correct
43 Correct 35 ms 1624 KB Output is correct
44 Correct 36 ms 1624 KB Output is correct
45 Correct 5 ms 1880 KB Output is correct
46 Correct 5 ms 1884 KB Output is correct
47 Correct 12 ms 2520 KB Output is correct
48 Correct 6 ms 1968 KB Output is correct
49 Correct 4 ms 1884 KB Output is correct
50 Correct 3 ms 1884 KB Output is correct
51 Correct 19 ms 3284 KB Output is correct
52 Correct 18 ms 2776 KB Output is correct
53 Correct 10 ms 2776 KB Output is correct
54 Correct 2 ms 1372 KB Output is correct
55 Correct 2 ms 1372 KB Output is correct
56 Correct 496 ms 2952 KB Output is correct
57 Correct 34 ms 3532 KB Output is correct
58 Correct 481 ms 1884 KB Output is correct
59 Correct 479 ms 1912 KB Output is correct
60 Correct 501 ms 2012 KB Output is correct
61 Correct 458 ms 2012 KB Output is correct
62 Correct 6 ms 2708 KB Output is correct
63 Correct 23 ms 2856 KB Output is correct
64 Correct 24 ms 4048 KB Output is correct
65 Correct 35 ms 4056 KB Output is correct
66 Correct 40 ms 3788 KB Output is correct
67 Correct 40 ms 3980 KB Output is correct