Submission #1094482

# Submission time Handle Problem Language Result Execution time Memory
1094482 2024-09-29T16:48:40 Z ShaShi Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
94 ms 74736 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;
map<int, bool> cnt[MAXN];

 
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]++;
        
        if (i == 2) val[i] = MAXN;

        if (!cnt[ind[i]][val[i]]) arr[ind[i]].pb(i), cnt[ind[i]][val[i]] = 1;
    }
 
    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 31 ms 70748 KB Output is correct
2 Correct 32 ms 70848 KB Output is correct
3 Correct 31 ms 70908 KB Output is correct
4 Correct 40 ms 70736 KB Output is correct
5 Correct 34 ms 70740 KB Output is correct
6 Correct 31 ms 70904 KB Output is correct
7 Correct 28 ms 70808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 70748 KB Output is correct
2 Correct 29 ms 70892 KB Output is correct
3 Correct 30 ms 70748 KB Output is correct
4 Correct 30 ms 70744 KB Output is correct
5 Correct 31 ms 70796 KB Output is correct
6 Correct 29 ms 70748 KB Output is correct
7 Correct 29 ms 70748 KB Output is correct
8 Correct 28 ms 70748 KB Output is correct
9 Correct 30 ms 70916 KB Output is correct
10 Correct 28 ms 70744 KB Output is correct
11 Correct 28 ms 71080 KB Output is correct
12 Correct 27 ms 70784 KB Output is correct
13 Correct 29 ms 70872 KB Output is correct
14 Correct 32 ms 71156 KB Output is correct
15 Correct 30 ms 70908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 70744 KB Output is correct
2 Correct 27 ms 70744 KB Output is correct
3 Correct 28 ms 70748 KB Output is correct
4 Correct 27 ms 70748 KB Output is correct
5 Correct 27 ms 70744 KB Output is correct
6 Correct 27 ms 70908 KB Output is correct
7 Correct 27 ms 70812 KB Output is correct
8 Correct 26 ms 70744 KB Output is correct
9 Correct 27 ms 70748 KB Output is correct
10 Correct 28 ms 70800 KB Output is correct
11 Correct 28 ms 70804 KB Output is correct
12 Correct 27 ms 70772 KB Output is correct
13 Correct 29 ms 70916 KB Output is correct
14 Correct 28 ms 71032 KB Output is correct
15 Correct 30 ms 70992 KB Output is correct
16 Correct 27 ms 70888 KB Output is correct
17 Correct 28 ms 71004 KB Output is correct
18 Correct 27 ms 71000 KB Output is correct
19 Correct 27 ms 70748 KB Output is correct
20 Correct 27 ms 70992 KB Output is correct
21 Correct 27 ms 70852 KB Output is correct
22 Correct 29 ms 71004 KB Output is correct
23 Correct 30 ms 71004 KB Output is correct
24 Correct 31 ms 70992 KB Output is correct
25 Correct 29 ms 71004 KB Output is correct
26 Correct 32 ms 70744 KB Output is correct
27 Correct 31 ms 70824 KB Output is correct
28 Correct 30 ms 70996 KB Output is correct
29 Correct 33 ms 70892 KB Output is correct
30 Correct 29 ms 70780 KB Output is correct
31 Correct 30 ms 70796 KB Output is correct
32 Correct 30 ms 70780 KB Output is correct
33 Correct 32 ms 71004 KB Output is correct
34 Correct 33 ms 71008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 70832 KB Output is correct
2 Correct 27 ms 70740 KB Output is correct
3 Correct 31 ms 70736 KB Output is correct
4 Correct 37 ms 70736 KB Output is correct
5 Correct 28 ms 70756 KB Output is correct
6 Correct 30 ms 70748 KB Output is correct
7 Correct 32 ms 70748 KB Output is correct
8 Correct 27 ms 70928 KB Output is correct
9 Correct 41 ms 70740 KB Output is correct
10 Correct 31 ms 70744 KB Output is correct
11 Correct 36 ms 70996 KB Output is correct
12 Correct 28 ms 70748 KB Output is correct
13 Correct 29 ms 70864 KB Output is correct
14 Correct 44 ms 70980 KB Output is correct
15 Correct 34 ms 70992 KB Output is correct
16 Correct 29 ms 70748 KB Output is correct
17 Correct 29 ms 71004 KB Output is correct
18 Correct 32 ms 71000 KB Output is correct
19 Correct 31 ms 70744 KB Output is correct
20 Correct 29 ms 70932 KB Output is correct
21 Correct 28 ms 70996 KB Output is correct
22 Correct 27 ms 71004 KB Output is correct
23 Correct 31 ms 71004 KB Output is correct
24 Correct 30 ms 71004 KB Output is correct
25 Correct 31 ms 70960 KB Output is correct
26 Correct 30 ms 70748 KB Output is correct
27 Correct 30 ms 70740 KB Output is correct
28 Correct 31 ms 71004 KB Output is correct
29 Correct 30 ms 71000 KB Output is correct
30 Correct 31 ms 70744 KB Output is correct
31 Correct 30 ms 70740 KB Output is correct
32 Correct 32 ms 70744 KB Output is correct
33 Correct 32 ms 71000 KB Output is correct
34 Correct 34 ms 70996 KB Output is correct
35 Correct 53 ms 73424 KB Output is correct
36 Correct 32 ms 71260 KB Output is correct
37 Correct 40 ms 72940 KB Output is correct
38 Correct 47 ms 74444 KB Output is correct
39 Correct 39 ms 73032 KB Output is correct
40 Correct 41 ms 73552 KB Output is correct
41 Correct 43 ms 74196 KB Output is correct
42 Correct 37 ms 71260 KB Output is correct
43 Correct 32 ms 71456 KB Output is correct
44 Correct 36 ms 71516 KB Output is correct
45 Correct 81 ms 74008 KB Output is correct
46 Correct 76 ms 74312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70736 KB Output is correct
2 Correct 29 ms 70748 KB Output is correct
3 Correct 40 ms 70836 KB Output is correct
4 Correct 29 ms 70748 KB Output is correct
5 Correct 31 ms 70744 KB Output is correct
6 Correct 31 ms 70744 KB Output is correct
7 Correct 32 ms 70732 KB Output is correct
8 Correct 30 ms 70932 KB Output is correct
9 Correct 32 ms 70772 KB Output is correct
10 Correct 31 ms 70844 KB Output is correct
11 Correct 31 ms 71004 KB Output is correct
12 Correct 30 ms 70920 KB Output is correct
13 Correct 32 ms 70728 KB Output is correct
14 Correct 32 ms 70992 KB Output is correct
15 Correct 32 ms 71004 KB Output is correct
16 Correct 32 ms 70744 KB Output is correct
17 Correct 34 ms 71004 KB Output is correct
18 Correct 34 ms 70996 KB Output is correct
19 Correct 31 ms 70740 KB Output is correct
20 Correct 31 ms 71000 KB Output is correct
21 Correct 30 ms 70996 KB Output is correct
22 Correct 31 ms 70916 KB Output is correct
23 Correct 31 ms 71008 KB Output is correct
24 Correct 31 ms 71128 KB Output is correct
25 Correct 30 ms 71004 KB Output is correct
26 Correct 31 ms 70748 KB Output is correct
27 Correct 33 ms 70744 KB Output is correct
28 Correct 31 ms 71000 KB Output is correct
29 Correct 30 ms 70996 KB Output is correct
30 Correct 30 ms 70736 KB Output is correct
31 Correct 30 ms 70748 KB Output is correct
32 Correct 31 ms 70736 KB Output is correct
33 Correct 34 ms 71004 KB Output is correct
34 Correct 32 ms 71004 KB Output is correct
35 Correct 54 ms 73420 KB Output is correct
36 Correct 37 ms 71260 KB Output is correct
37 Correct 40 ms 72920 KB Output is correct
38 Correct 48 ms 74124 KB Output is correct
39 Correct 42 ms 73304 KB Output is correct
40 Correct 41 ms 73556 KB Output is correct
41 Correct 46 ms 74188 KB Output is correct
42 Correct 36 ms 71260 KB Output is correct
43 Correct 33 ms 71260 KB Output is correct
44 Correct 34 ms 71508 KB Output is correct
45 Correct 83 ms 74196 KB Output is correct
46 Correct 76 ms 74200 KB Output is correct
47 Correct 45 ms 73832 KB Output is correct
48 Correct 39 ms 72784 KB Output is correct
49 Correct 39 ms 72788 KB Output is correct
50 Correct 38 ms 72280 KB Output is correct
51 Correct 49 ms 74736 KB Output is correct
52 Correct 50 ms 74040 KB Output is correct
53 Correct 42 ms 73820 KB Output is correct
54 Correct 31 ms 70744 KB Output is correct
55 Correct 30 ms 70696 KB Output is correct
56 Correct 40 ms 73772 KB Output is correct
57 Correct 32 ms 71252 KB Output is correct
58 Correct 29 ms 71248 KB Output is correct
59 Correct 30 ms 71516 KB Output is correct
60 Correct 30 ms 71424 KB Output is correct
61 Correct 31 ms 71652 KB Output is correct
62 Correct 41 ms 73940 KB Output is correct
63 Correct 60 ms 73680 KB Output is correct
64 Correct 59 ms 73604 KB Output is correct
65 Correct 71 ms 73748 KB Output is correct
66 Correct 94 ms 74188 KB Output is correct
67 Correct 89 ms 74188 KB Output is correct