Submission #969703

# Submission time Handle Problem Language Result Execution time Memory
969703 2024-04-25T13:28:46 Z Pring Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
523 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;

const int MXN = 30005, MXM = 10000005, INF = 1e9;
int n, m;
map<pii, int> M;

namespace GRAPH {
    int rt[MXM], dis[MXM], nc;
    // vector<p3i> edge;
    vector<pii> edge;
    bitset<MXM * 2> ew, b;

    int new_node() {
        rt[nc] = -1;
        return nc++;
    }

    void add_edge(int u, int v, int w) { 
        // debug(u, v, w);
        ew[edge.size()] = w;
        edge.push_back(mp(v, rt[u]));
        rt[u] = edge.size() - 1;
    }

    int ADD_CHAIN(int mod, int r) {
        if (M.find(mp(mod, r)) != M.end()) return M[mp(mod, r)];
        vector<int> v;
        for (int i = r; i < n; i += mod) {
            v.push_back(new_node());
            add_edge(v.back(), i, 0);
        }
        FOR(i, 1, v.size()) {
            add_edge(v[i - 1], v[i], 1);
            add_edge(v[i], v[i - 1], 1);
        }
        debug(mod, r, v.front());
        return (M[mp(mod, r)] = v.front());
    }

    void ZOBFS(int sr) {
        deque<int> dq;
        fill(dis, dis + nc, INF);
        dis[sr] = 0;
        dq.push_back(sr);
        while (dq.size()) {
            int id = dq.front();
            dq.pop_front();
            if (b[id]) continue;
            b[id] = true;
            int p = rt[id];
            while (p != -1) {
                auto [i, nxt] = edge[p];
                // if (b[i]) continue;
                // if (dis[i] <= dis[id] + ew[p]) continue;
                if (!b[i] && dis[i] > dis[id] + ew[p]) {
                    dis[i] = dis[id] + ew[p];
                    if (ew[p]) {
                        dq.push_back(i);
                    } else {
                        dq.push_front(i);
                    }
                }
                p = nxt;
            }
        }
    }
}

int minimum_jumps(int N, int M, vector<int> &B, vector<int> &P) {
    using namespace GRAPH;
    n = N;
    m = M;
    FOR(i, 0, n) new_node();
    FOR(i, 0, m) {
        int now = new_node();
        add_edge(B[i], now, 0);
        add_edge(now, B[i], 0);
    }
    FOR(i, 0, m) {
        int rt = ADD_CHAIN(P[i], B[i] % P[i]);
        int now = rt + B[i] / P[i];
        add_edge(n + i, now, 0);
    }
    ZOBFS(n);
    return (dis[n + 1] == INF ? -1 : dis[n + 1]);
}

void miku() {
    int n, m;
    cin >> n >> m;
    vector<int> b(m), p(m);
    FOR(i, 0, m) cin >> b[i] >> p[i];
    cout << minimum_jumps(n, m, b, p) << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int GRAPH::ADD_CHAIN(int, int)':
skyscraper.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
skyscraper.cpp:54:9: note: in expansion of macro 'debug'
   54 |         debug(mod, r, v.front());
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 2 ms 4868 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 5108 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5128 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 5608 KB Output is correct
29 Correct 5 ms 6616 KB Output is correct
30 Correct 2 ms 5092 KB Output is correct
31 Correct 4 ms 5516 KB Output is correct
32 Correct 3 ms 5600 KB Output is correct
33 Correct 9 ms 9684 KB Output is correct
34 Correct 9 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4796 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 3 ms 5112 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4832 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 3 ms 5128 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 5608 KB Output is correct
29 Correct 5 ms 6572 KB Output is correct
30 Correct 2 ms 5088 KB Output is correct
31 Correct 4 ms 5596 KB Output is correct
32 Correct 3 ms 5716 KB Output is correct
33 Correct 9 ms 9048 KB Output is correct
34 Correct 11 ms 8844 KB Output is correct
35 Correct 21 ms 10116 KB Output is correct
36 Correct 4 ms 5336 KB Output is correct
37 Correct 24 ms 15856 KB Output is correct
38 Correct 30 ms 11232 KB Output is correct
39 Correct 29 ms 11724 KB Output is correct
40 Correct 31 ms 11016 KB Output is correct
41 Correct 41 ms 11096 KB Output is correct
42 Correct 6 ms 6148 KB Output is correct
43 Correct 7 ms 6108 KB Output is correct
44 Correct 6 ms 5976 KB Output is correct
45 Correct 67 ms 24972 KB Output is correct
46 Correct 57 ms 25028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4456 KB Output is correct
2 Correct 1 ms 4456 KB Output is correct
3 Correct 1 ms 4456 KB Output is correct
4 Correct 1 ms 4456 KB Output is correct
5 Correct 1 ms 4456 KB Output is correct
6 Correct 1 ms 4456 KB Output is correct
7 Correct 1 ms 4456 KB Output is correct
8 Correct 1 ms 4456 KB Output is correct
9 Correct 1 ms 4880 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 4 ms 5240 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4852 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4824 KB Output is correct
24 Correct 2 ms 5128 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 5820 KB Output is correct
29 Correct 5 ms 6616 KB Output is correct
30 Correct 2 ms 5092 KB Output is correct
31 Correct 3 ms 5596 KB Output is correct
32 Correct 4 ms 5600 KB Output is correct
33 Correct 11 ms 10452 KB Output is correct
34 Correct 10 ms 9624 KB Output is correct
35 Correct 21 ms 10640 KB Output is correct
36 Correct 4 ms 5332 KB Output is correct
37 Correct 27 ms 14920 KB Output is correct
38 Correct 34 ms 11056 KB Output is correct
39 Correct 32 ms 11032 KB Output is correct
40 Correct 29 ms 11464 KB Output is correct
41 Correct 35 ms 11700 KB Output is correct
42 Correct 6 ms 6100 KB Output is correct
43 Correct 7 ms 6100 KB Output is correct
44 Correct 5 ms 6100 KB Output is correct
45 Correct 64 ms 25848 KB Output is correct
46 Correct 60 ms 26272 KB Output is correct
47 Correct 89 ms 42256 KB Output is correct
48 Correct 22 ms 16324 KB Output is correct
49 Correct 18 ms 10440 KB Output is correct
50 Correct 14 ms 9676 KB Output is correct
51 Correct 47 ms 18884 KB Output is correct
52 Correct 49 ms 27076 KB Output is correct
53 Correct 23 ms 11548 KB Output is correct
54 Correct 3 ms 5844 KB Output is correct
55 Correct 4 ms 6752 KB Output is correct
56 Correct 8 ms 7388 KB Output is correct
57 Correct 38 ms 23892 KB Output is correct
58 Correct 9 ms 11224 KB Output is correct
59 Correct 11 ms 10956 KB Output is correct
60 Correct 13 ms 10184 KB Output is correct
61 Correct 12 ms 9928 KB Output is correct
62 Correct 51 ms 26160 KB Output is correct
63 Correct 235 ms 79836 KB Output is correct
64 Correct 308 ms 150432 KB Output is correct
65 Correct 523 ms 148888 KB Output is correct
66 Runtime error 310 ms 262144 KB Execution killed with signal 9
67 Halted 0 ms 0 KB -