Submission #939142

# Submission time Handle Problem Language Result Execution time Memory
939142 2024-03-06T06:13:08 Z a_l_i_r_e_z_a Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 10908 KB
// In the name of God
// Hope is last to die
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
 
const int maxn = 3e4 + 5;
const int inf = 1e9 + 7;
int n, m, s, t, d[maxn];
vector<int> vec[maxn];
vector<pii> adj[maxn];
bool mark[maxn];
set<pii> st;

void dij(){
    memset(d, 63, sizeof d);
    d[s] = 0;
    st.insert(mp(0, s));
    while(st.size()){
        int v = (*st.begin()).S, dist = (*st.begin()).F;
        st.erase(st.begin());
        for(auto [u, w]: adj[v]){
            if(d[u] > dist + w){
                st.erase(mp(d[u], u));
                d[u] = dist + w;
                st.insert(mp(d[u], u));
            }
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int b, p; cin >> b >> p;
        if(p < n) vec[p].pb(b);
        if(i == 0) s = b;
        if(i == 1) t = b;
    }
    for(int p = 1; p < n; p++){
        for(auto u: vec[p]) mark[u] = 1;
        for(int i = 0; i < n; i++){
            if(!mark[i]) continue;
            for(int j = i - p; j >= 0; j -= p){
                adj[i].pb(mp(j, (i - j) / p));
                if(mark[j]) break;
            }
            for(int j = i + p; j < n; j += p){
                adj[i].pb(mp(j, (j - i) / p));
                if(mark[j]) break;
            }
        }
        for(auto u: vec[p]) mark[u] = 0;
    }
    dij();
    if(d[t] >= inf) cout << -1 << '\n';
    else cout << d[t] << '\n';
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
18 Correct 4 ms 1884 KB Output is correct
19 Correct 4 ms 1880 KB Output is correct
20 Correct 5 ms 1884 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 3 ms 1884 KB Output is correct
23 Correct 3 ms 1884 KB Output is correct
24 Correct 5 ms 2140 KB Output is correct
25 Correct 4 ms 2140 KB Output is correct
26 Correct 4 ms 2004 KB Output is correct
27 Correct 4 ms 1880 KB Output is correct
28 Correct 4 ms 2116 KB Output is correct
29 Correct 9 ms 2728 KB Output is correct
30 Correct 5 ms 2136 KB Output is correct
31 Correct 5 ms 2240 KB Output is correct
32 Correct 5 ms 2140 KB Output is correct
33 Correct 9 ms 3164 KB Output is correct
34 Correct 9 ms 3112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 2140 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 4 ms 1940 KB Output is correct
20 Correct 4 ms 1892 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 3 ms 1884 KB Output is correct
23 Correct 3 ms 1884 KB Output is correct
24 Correct 4 ms 2140 KB Output is correct
25 Correct 4 ms 2136 KB Output is correct
26 Correct 5 ms 2140 KB Output is correct
27 Correct 4 ms 1884 KB Output is correct
28 Correct 4 ms 2140 KB Output is correct
29 Correct 7 ms 2652 KB Output is correct
30 Correct 5 ms 2140 KB Output is correct
31 Correct 5 ms 2396 KB Output is correct
32 Correct 5 ms 2140 KB Output is correct
33 Correct 9 ms 3268 KB Output is correct
34 Correct 9 ms 3164 KB Output is correct
35 Correct 9 ms 2908 KB Output is correct
36 Correct 3 ms 2140 KB Output is correct
37 Correct 9 ms 3928 KB Output is correct
38 Correct 14 ms 3760 KB Output is correct
39 Correct 11 ms 3932 KB Output is correct
40 Correct 11 ms 3932 KB Output is correct
41 Correct 11 ms 3932 KB Output is correct
42 Correct 6 ms 2112 KB Output is correct
43 Correct 7 ms 2136 KB Output is correct
44 Correct 6 ms 2136 KB Output is correct
45 Correct 19 ms 6232 KB Output is correct
46 Correct 20 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1880 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 2140 KB Output is correct
18 Correct 3 ms 1968 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 3 ms 1960 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 4 ms 2140 KB Output is correct
25 Correct 6 ms 2140 KB Output is correct
26 Correct 4 ms 2140 KB Output is correct
27 Correct 4 ms 1880 KB Output is correct
28 Correct 6 ms 2140 KB Output is correct
29 Correct 7 ms 2532 KB Output is correct
30 Correct 5 ms 2140 KB Output is correct
31 Correct 5 ms 2392 KB Output is correct
32 Correct 5 ms 2140 KB Output is correct
33 Correct 9 ms 3164 KB Output is correct
34 Correct 9 ms 3164 KB Output is correct
35 Correct 10 ms 2908 KB Output is correct
36 Correct 3 ms 2140 KB Output is correct
37 Correct 9 ms 3932 KB Output is correct
38 Correct 11 ms 3932 KB Output is correct
39 Correct 15 ms 3932 KB Output is correct
40 Correct 11 ms 3932 KB Output is correct
41 Correct 11 ms 3932 KB Output is correct
42 Correct 6 ms 2240 KB Output is correct
43 Correct 6 ms 2140 KB Output is correct
44 Correct 6 ms 2140 KB Output is correct
45 Correct 16 ms 6352 KB Output is correct
46 Correct 16 ms 6492 KB Output is correct
47 Correct 129 ms 10908 KB Output is correct
48 Correct 341 ms 4556 KB Output is correct
49 Correct 424 ms 4332 KB Output is correct
50 Correct 610 ms 3860 KB Output is correct
51 Correct 596 ms 7360 KB Output is correct
52 Correct 597 ms 7488 KB Output is correct
53 Execution timed out 1076 ms 3164 KB Time limit exceeded
54 Halted 0 ms 0 KB -