Submission #1094448

# Submission time Handle Problem Language Result Execution time Memory
1094448 2024-09-29T16:13:10 Z ShaShi Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 26320 KB
#include <bits/stdc++.h>
 
//#define int long long 
 
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
 
#define F first 
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define pll pair<long long, long long>
#define endl "\n"
 
 
 
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;

 
const int MAXN = (int)1e6 + 7;
const int MOD = 998244353;
const ll INF = (ll)1e9 + 7;

 
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, N, l, r, mid;
int dis[MAXN], ind[MAXN], val[MAXN];
vector<int> arr[MAXN];
priority_queue<pii, vector<pii>, greater<pii>> pq;


inline void relax(int v, int u) {
    if (val[v] == val[u]) return;
    if (dis[u] <= dis[v]+abs(ind[u]-ind[v])/val[v]) return;

    dis[u] = dis[v] + abs(ind[u]-ind[v])/val[v];

    pq.push({dis[u], u});
}


int32_t main() {
    #ifdef LOCAL
    freopen("inp.in", "r", stdin);
    freopen("res.out", "w", stdout);
    #else
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif


    cin >> n >> m;

    for (int i=1; i<=m; i++) {
        cin >> ind[i] >> val[i]; ind[i]++; arr[ind[i]].pb(i);
    }

    val[2] = MAXN;

    fill_n(dis, m+7, INF); 

    dis[1] = 0; pq.push({0, 1});

    while (pq.size()) {
        auto cur = pq.top(); pq.pop();

        if (dis[cur.S] != cur.F) continue;

        // cout << "! " << cur.S << " " << cur.F << endl;

        v = cur.S;

        if (v == 2) kill(dis[v]);

        for (int i=ind[v]; i<=n; i+=val[v]) for (auto cur:arr[i]) relax(v, cur);
        for (int i=ind[v]; i>0; i-=val[v]) for (auto cur:arr[i]) relax(v, cur);
    }

    kill(-1);

    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 4 ms 23900 KB Output is correct
3 Correct 5 ms 23808 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23908 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23944 KB Output is correct
6 Correct 4 ms 23900 KB Output is correct
7 Correct 4 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 24020 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 7 ms 23900 KB Output is correct
6 Correct 4 ms 23900 KB Output is correct
7 Correct 6 ms 23900 KB Output is correct
8 Correct 4 ms 23900 KB Output is correct
9 Correct 4 ms 23900 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 5 ms 23900 KB Output is correct
12 Correct 5 ms 23924 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 6 ms 24120 KB Output is correct
15 Correct 6 ms 23896 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 5 ms 23896 KB Output is correct
19 Correct 6 ms 23900 KB Output is correct
20 Correct 5 ms 23900 KB Output is correct
21 Correct 5 ms 23900 KB Output is correct
22 Correct 4 ms 23900 KB Output is correct
23 Correct 5 ms 23920 KB Output is correct
24 Correct 5 ms 23900 KB Output is correct
25 Correct 5 ms 23900 KB Output is correct
26 Correct 5 ms 23900 KB Output is correct
27 Correct 5 ms 23924 KB Output is correct
28 Correct 5 ms 23900 KB Output is correct
29 Correct 5 ms 24024 KB Output is correct
30 Correct 5 ms 23900 KB Output is correct
31 Correct 5 ms 23900 KB Output is correct
32 Correct 5 ms 23900 KB Output is correct
33 Correct 6 ms 23900 KB Output is correct
34 Correct 7 ms 23944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 7 ms 23900 KB Output is correct
4 Correct 5 ms 23928 KB Output is correct
5 Correct 6 ms 23936 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23740 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23932 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 6 ms 23932 KB Output is correct
15 Correct 6 ms 23896 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 5 ms 24072 KB Output is correct
18 Correct 5 ms 23896 KB Output is correct
19 Correct 5 ms 23900 KB Output is correct
20 Correct 5 ms 23916 KB Output is correct
21 Correct 8 ms 23884 KB Output is correct
22 Correct 4 ms 23900 KB Output is correct
23 Correct 5 ms 23896 KB Output is correct
24 Correct 6 ms 23900 KB Output is correct
25 Correct 5 ms 23900 KB Output is correct
26 Correct 5 ms 23900 KB Output is correct
27 Correct 5 ms 23940 KB Output is correct
28 Correct 5 ms 23980 KB Output is correct
29 Correct 5 ms 23948 KB Output is correct
30 Correct 5 ms 23896 KB Output is correct
31 Correct 5 ms 23900 KB Output is correct
32 Correct 5 ms 23900 KB Output is correct
33 Correct 6 ms 23900 KB Output is correct
34 Correct 6 ms 24156 KB Output is correct
35 Correct 21 ms 25300 KB Output is correct
36 Correct 7 ms 24152 KB Output is correct
37 Correct 11 ms 25048 KB Output is correct
38 Correct 16 ms 25840 KB Output is correct
39 Correct 9 ms 24668 KB Output is correct
40 Correct 12 ms 25208 KB Output is correct
41 Correct 12 ms 25812 KB Output is correct
42 Correct 7 ms 24668 KB Output is correct
43 Correct 7 ms 24924 KB Output is correct
44 Correct 8 ms 24668 KB Output is correct
45 Correct 46 ms 25872 KB Output is correct
46 Correct 44 ms 25812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23900 KB Output is correct
2 Correct 4 ms 23900 KB Output is correct
3 Correct 5 ms 23932 KB Output is correct
4 Correct 5 ms 23804 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 4 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 4 ms 23900 KB Output is correct
10 Correct 5 ms 23988 KB Output is correct
11 Correct 5 ms 23900 KB Output is correct
12 Correct 5 ms 23984 KB Output is correct
13 Correct 5 ms 23920 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 24116 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 5 ms 23924 KB Output is correct
18 Correct 5 ms 23900 KB Output is correct
19 Correct 6 ms 23900 KB Output is correct
20 Correct 5 ms 24056 KB Output is correct
21 Correct 5 ms 23900 KB Output is correct
22 Correct 5 ms 23900 KB Output is correct
23 Correct 5 ms 23968 KB Output is correct
24 Correct 5 ms 23900 KB Output is correct
25 Correct 5 ms 23896 KB Output is correct
26 Correct 5 ms 23900 KB Output is correct
27 Correct 5 ms 23936 KB Output is correct
28 Correct 7 ms 23900 KB Output is correct
29 Correct 5 ms 23900 KB Output is correct
30 Correct 5 ms 23896 KB Output is correct
31 Correct 5 ms 23900 KB Output is correct
32 Correct 5 ms 23900 KB Output is correct
33 Correct 6 ms 23900 KB Output is correct
34 Correct 6 ms 24128 KB Output is correct
35 Correct 20 ms 25216 KB Output is correct
36 Correct 5 ms 24156 KB Output is correct
37 Correct 10 ms 25048 KB Output is correct
38 Correct 16 ms 25792 KB Output is correct
39 Correct 8 ms 24668 KB Output is correct
40 Correct 9 ms 25176 KB Output is correct
41 Correct 14 ms 25812 KB Output is correct
42 Correct 8 ms 24668 KB Output is correct
43 Correct 8 ms 24984 KB Output is correct
44 Correct 9 ms 24664 KB Output is correct
45 Correct 55 ms 25808 KB Output is correct
46 Correct 43 ms 25812 KB Output is correct
47 Correct 14 ms 25812 KB Output is correct
48 Correct 9 ms 24920 KB Output is correct
49 Correct 8 ms 24668 KB Output is correct
50 Correct 7 ms 24668 KB Output is correct
51 Correct 20 ms 26320 KB Output is correct
52 Correct 18 ms 25816 KB Output is correct
53 Correct 13 ms 25520 KB Output is correct
54 Correct 5 ms 23900 KB Output is correct
55 Correct 4 ms 23900 KB Output is correct
56 Correct 9 ms 25436 KB Output is correct
57 Correct 6 ms 24156 KB Output is correct
58 Execution timed out 1098 ms 24924 KB Time limit exceeded
59 Halted 0 ms 0 KB -