Submission #881126

# Submission time Handle Problem Language Result Execution time Memory
881126 2023-11-30T16:01:47 Z Lobo Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 85228 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 3e4+10;

int n, m;
vector<int> dogs[maxn];

void solve() {
    cin >> n >> m;

    int b0,b1;
    for(int i = 0; i < m; i++) {
        int b,p; cin >> b >> p;
        if(i == 0) b0 = b;
        if(i == 1) b1 = b;
        dogs[b].pb(p);
    }

    vector<int> d0(n+1,inf);
    vector<map<int,int>> d(n+1);

    deque<pair<int,int>> dq;
    d0[b0] = 0;
    dq.push_back(mp(b0,0));
    while(dq.size()) {
        int i = dq.front().fr;
        int p = dq.front().sc;
        dq.pop_front();
        
        if(p == 0) {
            for(auto x : dogs[i]) {
                if(d[i].count(x) == 0 or d[i][x] > d0[i]) {
                    d[i][x] = d0[i];
                    dq.push_front(mp(i,x));
                }
            }
        }
        else {
            if(d0[i] > d[i][p]) {
                d0[i] = d[i][p];
                dq.push_front(mp(i,0));
            }
            int i1;

            i1 = i-p;
            if(i1 >= 0 && i1 <= n-1 && (d[i1].count(p) == 0 or d[i1][p] > d[i][p]+1)) {
                d[i1][p] = d[i][p]+1;
                dq.push_back(mp(i1,p));
            }
            i1 = i+p;
            if(i1 >= 0 && i1 <= n-1 && (d[i1].count(p) == 0 or d[i1][p] > d[i][p]+1)) {
                d[i1][p] = d[i][p]+1;
                dq.push_back(mp(i1,p));
            }
        }
    }

    if(d0[b1] == inf) cout << -1 << endl;
    else cout << d0[b1] << endl;
}
    
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:68:13: warning: 'b1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |     if(d0[b1] == inf) cout << -1 << endl;
      |             ^
# 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 1316 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 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 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 1348 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 3 ms 1628 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1368 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1112 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 1156 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 6 ms 2336 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 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 2 ms 1628 KB Output is correct
24 Correct 4 ms 1880 KB Output is correct
25 Correct 3 ms 1628 KB Output is correct
26 Correct 3 ms 1636 KB Output is correct
27 Correct 2 ms 1628 KB Output is correct
28 Correct 6 ms 2652 KB Output is correct
29 Correct 18 ms 5068 KB Output is correct
30 Correct 3 ms 2140 KB Output is correct
31 Correct 8 ms 3168 KB Output is correct
32 Correct 5 ms 2652 KB Output is correct
33 Correct 43 ms 8636 KB Output is correct
34 Correct 45 ms 8708 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 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 2 ms 1372 KB Output is correct
12 Correct 1 ms 1028 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 6 ms 2136 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 2 ms 1372 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 3 ms 1628 KB Output is correct
24 Correct 5 ms 1988 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 2 ms 1628 KB Output is correct
27 Correct 2 ms 1628 KB Output is correct
28 Correct 4 ms 2652 KB Output is correct
29 Correct 17 ms 5124 KB Output is correct
30 Correct 4 ms 2188 KB Output is correct
31 Correct 8 ms 3164 KB Output is correct
32 Correct 5 ms 2704 KB Output is correct
33 Correct 42 ms 8600 KB Output is correct
34 Correct 67 ms 8804 KB Output is correct
35 Correct 62 ms 8200 KB Output is correct
36 Correct 5 ms 2392 KB Output is correct
37 Correct 115 ms 12480 KB Output is correct
38 Correct 94 ms 11772 KB Output is correct
39 Correct 101 ms 11796 KB Output is correct
40 Correct 98 ms 11988 KB Output is correct
41 Correct 79 ms 11788 KB Output is correct
42 Correct 5 ms 2008 KB Output is correct
43 Correct 5 ms 2012 KB Output is correct
44 Correct 4 ms 1796 KB Output is correct
45 Correct 340 ms 32096 KB Output is correct
46 Correct 371 ms 31948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1168 KB Output is correct
3 Correct 1 ms 1164 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 1112 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 2 ms 1372 KB Output is correct
12 Correct 1 ms 1168 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1428 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 2 ms 1884 KB Output is correct
24 Correct 4 ms 1880 KB Output is correct
25 Correct 2 ms 1624 KB Output is correct
26 Correct 2 ms 1624 KB Output is correct
27 Correct 2 ms 1624 KB Output is correct
28 Correct 5 ms 2652 KB Output is correct
29 Correct 16 ms 5036 KB Output is correct
30 Correct 4 ms 2192 KB Output is correct
31 Correct 8 ms 3160 KB Output is correct
32 Correct 5 ms 2652 KB Output is correct
33 Correct 48 ms 8660 KB Output is correct
34 Correct 42 ms 8788 KB Output is correct
35 Correct 46 ms 8020 KB Output is correct
36 Correct 5 ms 2260 KB Output is correct
37 Correct 98 ms 12288 KB Output is correct
38 Correct 92 ms 11792 KB Output is correct
39 Correct 80 ms 11940 KB Output is correct
40 Correct 82 ms 11772 KB Output is correct
41 Correct 78 ms 11740 KB Output is correct
42 Correct 5 ms 2012 KB Output is correct
43 Correct 5 ms 2072 KB Output is correct
44 Correct 4 ms 1796 KB Output is correct
45 Correct 325 ms 31964 KB Output is correct
46 Correct 332 ms 31828 KB Output is correct
47 Correct 726 ms 48396 KB Output is correct
48 Correct 5 ms 3164 KB Output is correct
49 Correct 5 ms 3172 KB Output is correct
50 Correct 4 ms 3224 KB Output is correct
51 Correct 120 ms 23616 KB Output is correct
52 Correct 176 ms 25312 KB Output is correct
53 Correct 24 ms 9296 KB Output is correct
54 Correct 3 ms 3676 KB Output is correct
55 Correct 3 ms 4188 KB Output is correct
56 Correct 8 ms 5724 KB Output is correct
57 Correct 189 ms 29900 KB Output is correct
58 Correct 10 ms 7128 KB Output is correct
59 Correct 15 ms 9184 KB Output is correct
60 Correct 21 ms 10976 KB Output is correct
61 Correct 19 ms 9944 KB Output is correct
62 Correct 193 ms 34648 KB Output is correct
63 Execution timed out 1049 ms 85228 KB Time limit exceeded
64 Halted 0 ms 0 KB -