Submission #939160

# Submission time Handle Problem Language Result Execution time Memory
939160 2024-03-06T06:21:11 Z Amirreza_Fakhri Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
154 ms 5008 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
 
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 3e4+5;
 
int n, m, s, t, cnt = 0, dist[maxn];
set <int> doge[maxn];
set <pii> st;
 
void dij(int v) {
    fill(dist, dist+n, inf);
    dist[v] = 0;
    st.insert(mp(0, v));
    while (st.size()) {
        int d = st.begin()->F, u = st.begin()->S;
        st.erase(st.begin());
        for (int p : doge[u]) {
            for (int j = 1; u+j*p < n; j++) {
                if (dist[u+j*p] > d+j) {
                    st.erase(mp(dist[u+j*p], u+j*p));
                    dist[u+j*p] = d+j;
                    st.insert(mp(d+j, u+j*p));
                }
                cnt++; assert(cnt < 7381230);
                if (doge[u+j*p].find(p) != doge[u+j*p].end()) break;
            }
            for (int j = 1; u-j*p >= 0; j++) {
                if (dist[u-j*p] > d+j) {
                    st.erase(mp(dist[u-j*p], u-j*p));
                    dist[u-j*p] = d+j;
                    st.insert(mp(d+j, u-j*p));
                }
                cnt++; assert(cnt < 7381230);
                if (doge[u-j*p].find(p) != doge[u-j*p].end()) break;
            }
        }
    }
}
 
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 a, b; cin >> a >> b;
        doge[a].insert(b);
        if (i == 0) s = a;
        if (i == 1) t = a;
    }
    dij(s);
    if (dist[t] != inf) assert(dist[t] <= 1000000);
    cout << (dist[t] == inf ? -1 : dist[t]) << '\n';
  	
    // int sum = 0, i;
    // for ( i = 1; sum <= maxn; i++) sum += i;
    // cout << i << '\n';
    // sum = 0;
    // for (int j = 1; j <= i; j++) sum += maxn;
    // cout << sum << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 2 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 2136 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 2 ms 1984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1624 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1708 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 2 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 2 ms 1884 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 1 ms 1672 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1872 KB Output is correct
19 Correct 1 ms 1880 KB Output is correct
20 Correct 1 ms 1880 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 2 ms 1880 KB Output is correct
24 Correct 2 ms 1880 KB Output is correct
25 Correct 2 ms 1880 KB Output is correct
26 Correct 1 ms 1880 KB Output is correct
27 Correct 1 ms 1884 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 4 ms 1884 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 2 ms 1884 KB Output is correct
32 Correct 2 ms 1884 KB Output is correct
33 Correct 6 ms 1884 KB Output is correct
34 Correct 6 ms 2072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1864 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1640 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 2 ms 1884 KB Output is correct
12 Correct 1 ms 1712 KB Output is correct
13 Correct 1 ms 2136 KB Output is correct
14 Correct 1 ms 1872 KB Output is correct
15 Correct 1 ms 1872 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 2000 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 1 ms 1872 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 2 ms 1884 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 1 ms 1884 KB Output is correct
27 Correct 1 ms 1880 KB Output is correct
28 Correct 1 ms 1884 KB Output is correct
29 Correct 4 ms 2012 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 3 ms 1884 KB Output is correct
32 Correct 2 ms 1884 KB Output is correct
33 Correct 7 ms 1872 KB Output is correct
34 Correct 6 ms 1884 KB Output is correct
35 Correct 11 ms 3164 KB Output is correct
36 Correct 3 ms 2140 KB Output is correct
37 Correct 12 ms 2908 KB Output is correct
38 Correct 18 ms 3684 KB Output is correct
39 Correct 14 ms 3420 KB Output is correct
40 Correct 15 ms 3632 KB Output is correct
41 Correct 14 ms 3420 KB Output is correct
42 Correct 4 ms 2120 KB Output is correct
43 Correct 4 ms 2140 KB Output is correct
44 Correct 4 ms 2140 KB Output is correct
45 Correct 19 ms 3588 KB Output is correct
46 Correct 15 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1760 KB Output is correct
8 Correct 1 ms 1872 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 2136 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 2068 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 2136 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 2 ms 1880 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 2 ms 1884 KB Output is correct
27 Correct 1 ms 1880 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 4 ms 2012 KB Output is correct
30 Correct 2 ms 1884 KB Output is correct
31 Correct 2 ms 1884 KB Output is correct
32 Correct 2 ms 1880 KB Output is correct
33 Correct 5 ms 1884 KB Output is correct
34 Correct 6 ms 1884 KB Output is correct
35 Correct 11 ms 3164 KB Output is correct
36 Correct 3 ms 2140 KB Output is correct
37 Correct 12 ms 3020 KB Output is correct
38 Correct 14 ms 3420 KB Output is correct
39 Correct 15 ms 3620 KB Output is correct
40 Correct 14 ms 3420 KB Output is correct
41 Correct 14 ms 3420 KB Output is correct
42 Correct 4 ms 2140 KB Output is correct
43 Correct 4 ms 2140 KB Output is correct
44 Correct 4 ms 2136 KB Output is correct
45 Correct 18 ms 3420 KB Output is correct
46 Correct 15 ms 3584 KB Output is correct
47 Correct 30 ms 3676 KB Output is correct
48 Correct 6 ms 3256 KB Output is correct
49 Correct 6 ms 3160 KB Output is correct
50 Correct 5 ms 2668 KB Output is correct
51 Correct 40 ms 4948 KB Output is correct
52 Correct 40 ms 4700 KB Output is correct
53 Correct 16 ms 4952 KB Output is correct
54 Correct 3 ms 2652 KB Output is correct
55 Correct 4 ms 2652 KB Output is correct
56 Correct 7 ms 3420 KB Output is correct
57 Correct 37 ms 2908 KB Output is correct
58 Correct 7 ms 2652 KB Output is correct
59 Correct 8 ms 2908 KB Output is correct
60 Correct 10 ms 2912 KB Output is correct
61 Correct 12 ms 3164 KB Output is correct
62 Correct 10 ms 3676 KB Output is correct
63 Correct 60 ms 5008 KB Output is correct
64 Correct 60 ms 4984 KB Output is correct
65 Correct 79 ms 5000 KB Output is correct
66 Correct 150 ms 4988 KB Output is correct
67 Correct 154 ms 4988 KB Output is correct