Submission #699346

# Submission time Handle Problem Language Result Execution time Memory
699346 2023-02-16T15:32:11 Z nguyentunglam Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
254 ms 112396 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 3e4 + 10, M = 1e9;
bitset<M> dd;
vector<int> lst[N];
int cnt;
bool mark[N];
bool id(int x, int y) {
    int code = x * (3e4 + 1) + y;
    if (dd[code]) return 1;
    dd[code] = 1;
    return 0;
}
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n, m; cin >> n >> m;
    pair<int, int> st, ed;
    for(int i = 0; i < m; i++) {
        int b, p; cin >> b >> p;
        lst[b].push_back(p);
        if (i == 0) st = make_pair(b, p);
        if (i == 1) ed = make_pair(b, p);
    }
    deque<tuple<int, int, int> > dq;
    id(st.fi, st.se);
    dq.push_back({0, st.fi, st.se});

    while (!dq.empty()) {
        auto [cost, pos, jump] = dq.front(); dq.pop_front();
        if (pos == ed.fi) return cout << cost, 0;
        if (!mark[pos]) {
            for(auto &j : lst[pos]) {
                if (!id(pos, j)) dq.push_front({cost, pos, j});
            }
            mark[pos] = 1;
        }
        if (pos + jump < n) {
            if (!id(pos + jump, jump)) dq.push_back({cost + 1, pos + jump, jump});
        }
        if (pos - jump >= 0) {
            if (!id(pos - jump, jump)) dq.push_back({cost + 1, pos - jump, jump});
        }
    }
    cout << -1;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:26:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1040 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 1044 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1044 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1304 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1404 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 2 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3748 KB Output is correct
18 Correct 1 ms 1056 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1052 KB Output is correct
23 Correct 4 ms 6300 KB Output is correct
24 Correct 5 ms 7584 KB Output is correct
25 Correct 2 ms 2496 KB Output is correct
26 Correct 4 ms 7252 KB Output is correct
27 Correct 5 ms 7708 KB Output is correct
28 Correct 6 ms 8356 KB Output is correct
29 Correct 6 ms 8276 KB Output is correct
30 Correct 8 ms 8276 KB Output is correct
31 Correct 6 ms 8276 KB Output is correct
32 Correct 5 ms 8336 KB Output is correct
33 Correct 7 ms 8404 KB Output is correct
34 Correct 6 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1040 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1308 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 2 ms 1436 KB Output is correct
15 Correct 2 ms 1492 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3668 KB Output is correct
18 Correct 1 ms 1048 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 4 ms 6356 KB Output is correct
24 Correct 5 ms 7508 KB Output is correct
25 Correct 2 ms 2516 KB Output is correct
26 Correct 5 ms 7252 KB Output is correct
27 Correct 4 ms 7636 KB Output is correct
28 Correct 6 ms 8404 KB Output is correct
29 Correct 6 ms 8344 KB Output is correct
30 Correct 5 ms 8308 KB Output is correct
31 Correct 7 ms 8276 KB Output is correct
32 Correct 5 ms 8392 KB Output is correct
33 Correct 7 ms 8348 KB Output is correct
34 Correct 7 ms 8404 KB Output is correct
35 Correct 9 ms 6808 KB Output is correct
36 Correct 3 ms 3412 KB Output is correct
37 Correct 9 ms 8640 KB Output is correct
38 Correct 10 ms 8916 KB Output is correct
39 Correct 6 ms 2204 KB Output is correct
40 Correct 10 ms 7764 KB Output is correct
41 Correct 10 ms 8532 KB Output is correct
42 Correct 9 ms 7720 KB Output is correct
43 Correct 8 ms 8148 KB Output is correct
44 Correct 8 ms 8740 KB Output is correct
45 Correct 18 ms 9064 KB Output is correct
46 Correct 15 ms 9076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1036 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 1044 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1048 KB Output is correct
8 Correct 1 ms 1048 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 3668 KB Output is correct
18 Correct 1 ms 1048 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 5 ms 8352 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 4 ms 6356 KB Output is correct
24 Correct 5 ms 7580 KB Output is correct
25 Correct 2 ms 2464 KB Output is correct
26 Correct 4 ms 7324 KB Output is correct
27 Correct 5 ms 7712 KB Output is correct
28 Correct 6 ms 8404 KB Output is correct
29 Correct 6 ms 8344 KB Output is correct
30 Correct 5 ms 8276 KB Output is correct
31 Correct 5 ms 8356 KB Output is correct
32 Correct 5 ms 8276 KB Output is correct
33 Correct 7 ms 8404 KB Output is correct
34 Correct 7 ms 8344 KB Output is correct
35 Correct 9 ms 6820 KB Output is correct
36 Correct 3 ms 3412 KB Output is correct
37 Correct 9 ms 8732 KB Output is correct
38 Correct 10 ms 8972 KB Output is correct
39 Correct 6 ms 2208 KB Output is correct
40 Correct 9 ms 7696 KB Output is correct
41 Correct 10 ms 8660 KB Output is correct
42 Correct 10 ms 7748 KB Output is correct
43 Correct 8 ms 8092 KB Output is correct
44 Correct 8 ms 8796 KB Output is correct
45 Correct 18 ms 9044 KB Output is correct
46 Correct 14 ms 9044 KB Output is correct
47 Correct 19 ms 26728 KB Output is correct
48 Correct 5 ms 1644 KB Output is correct
49 Correct 5 ms 1748 KB Output is correct
50 Correct 4 ms 1564 KB Output is correct
51 Correct 55 ms 88776 KB Output is correct
52 Correct 62 ms 94940 KB Output is correct
53 Correct 17 ms 18720 KB Output is correct
54 Correct 33 ms 61208 KB Output is correct
55 Correct 42 ms 77836 KB Output is correct
56 Correct 64 ms 112280 KB Output is correct
57 Correct 2 ms 2636 KB Output is correct
58 Correct 70 ms 111416 KB Output is correct
59 Correct 61 ms 103972 KB Output is correct
60 Correct 59 ms 103884 KB Output is correct
61 Correct 57 ms 98772 KB Output is correct
62 Correct 84 ms 112396 KB Output is correct
63 Correct 129 ms 111820 KB Output is correct
64 Correct 144 ms 111780 KB Output is correct
65 Correct 181 ms 111912 KB Output is correct
66 Correct 254 ms 111908 KB Output is correct
67 Correct 168 ms 112080 KB Output is correct