Submission #700886

# Submission time Handle Problem Language Result Execution time Memory
700886 2023-02-19T10:24:51 Z nguyentunglam Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
336 ms 225980 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;
bool dd[M];
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 1044 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 1048 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 1040 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1296 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 1508 KB Output is correct
15 Correct 2 ms 1492 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 1040 KB Output is correct
5 Correct 1 ms 1048 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 1168 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 2 ms 1304 KB Output is correct
12 Correct 2 ms 1364 KB Output is correct
13 Correct 2 ms 1364 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 4 ms 4180 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1052 KB Output is correct
20 Correct 5 ms 9172 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 6 ms 7760 KB Output is correct
24 Correct 8 ms 9668 KB Output is correct
25 Correct 2 ms 2772 KB Output is correct
26 Correct 6 ms 7840 KB Output is correct
27 Correct 5 ms 8532 KB Output is correct
28 Correct 9 ms 11424 KB Output is correct
29 Correct 10 ms 9236 KB Output is correct
30 Correct 6 ms 9172 KB Output is correct
31 Correct 6 ms 9172 KB Output is correct
32 Correct 8 ms 9172 KB Output is correct
33 Correct 12 ms 9248 KB Output is correct
34 Correct 8 ms 9172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1032 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 1048 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 1172 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 2 ms 1364 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 4132 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 5 ms 9120 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 5 ms 7764 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 3 ms 2748 KB Output is correct
26 Correct 5 ms 7836 KB Output is correct
27 Correct 5 ms 8532 KB Output is correct
28 Correct 7 ms 11348 KB Output is correct
29 Correct 7 ms 9172 KB Output is correct
30 Correct 6 ms 9112 KB Output is correct
31 Correct 8 ms 9236 KB Output is correct
32 Correct 7 ms 9240 KB Output is correct
33 Correct 7 ms 9268 KB Output is correct
34 Correct 6 ms 9172 KB Output is correct
35 Correct 11 ms 10020 KB Output is correct
36 Correct 3 ms 3924 KB Output is correct
37 Correct 11 ms 10952 KB Output is correct
38 Correct 13 ms 12320 KB Output is correct
39 Correct 7 ms 2388 KB Output is correct
40 Correct 11 ms 9044 KB Output is correct
41 Correct 11 ms 10780 KB Output is correct
42 Correct 9 ms 8400 KB Output is correct
43 Correct 9 ms 8924 KB Output is correct
44 Correct 9 ms 9556 KB Output is correct
45 Correct 18 ms 10304 KB Output is correct
46 Correct 14 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 1 ms 1044 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 1044 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1168 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 2 ms 1304 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 2 ms 1432 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 2 ms 1432 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 4 ms 4128 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1044 KB Output is correct
20 Correct 6 ms 9156 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 2 ms 980 KB Output is correct
23 Correct 6 ms 7704 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 2 ms 2772 KB Output is correct
26 Correct 5 ms 7892 KB Output is correct
27 Correct 5 ms 8532 KB Output is correct
28 Correct 11 ms 11348 KB Output is correct
29 Correct 6 ms 9172 KB Output is correct
30 Correct 6 ms 9172 KB Output is correct
31 Correct 7 ms 9220 KB Output is correct
32 Correct 6 ms 9172 KB Output is correct
33 Correct 9 ms 9248 KB Output is correct
34 Correct 8 ms 9172 KB Output is correct
35 Correct 18 ms 10068 KB Output is correct
36 Correct 4 ms 3924 KB Output is correct
37 Correct 13 ms 10904 KB Output is correct
38 Correct 13 ms 12184 KB Output is correct
39 Correct 8 ms 2368 KB Output is correct
40 Correct 12 ms 9044 KB Output is correct
41 Correct 12 ms 10828 KB Output is correct
42 Correct 8 ms 8276 KB Output is correct
43 Correct 8 ms 8916 KB Output is correct
44 Correct 9 ms 9556 KB Output is correct
45 Correct 27 ms 10316 KB Output is correct
46 Correct 15 ms 10196 KB Output is correct
47 Correct 26 ms 32288 KB Output is correct
48 Correct 6 ms 1748 KB Output is correct
49 Correct 6 ms 1748 KB Output is correct
50 Correct 4 ms 1492 KB Output is correct
51 Correct 113 ms 186120 KB Output is correct
52 Correct 137 ms 213204 KB Output is correct
53 Correct 20 ms 24080 KB Output is correct
54 Correct 35 ms 62668 KB Output is correct
55 Correct 45 ms 82724 KB Output is correct
56 Correct 71 ms 123920 KB Output is correct
57 Correct 3 ms 2888 KB Output is correct
58 Correct 69 ms 123300 KB Output is correct
59 Correct 72 ms 114148 KB Output is correct
60 Correct 76 ms 114036 KB Output is correct
61 Correct 82 ms 111140 KB Output is correct
62 Correct 156 ms 225980 KB Output is correct
63 Correct 217 ms 140704 KB Output is correct
64 Correct 264 ms 134808 KB Output is correct
65 Correct 259 ms 132780 KB Output is correct
66 Correct 336 ms 130724 KB Output is correct
67 Correct 222 ms 127128 KB Output is correct