Submission #969556

# Submission time Handle Problem Language Result Execution time Memory
969556 2024-04-25T09:57:48 Z Pring Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 2516 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;
typedef array<int, 3> p3i;

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

namespace GRAPH {
    int rt[MXM], dis[MXM], nc;
    vector<p3i> edge;

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

    void add_edge(int u, int v, int w) { 
        debug(u, v, w);
        edge.push_back({w, 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) {
        // FOR(i, 0, nc) cout << rt[i] << ' ';
        // cout << endl;
        // for (auto [u, v, w] : edge) cout << '<' << u << ' ' << v << ' ' << w << '>' << '\n';
        deque<pii> dq;
        fill(dis, dis + nc, INF);
        dq.push_back(mp(0, sr));
        while (dq.size()) {
            auto [len, id] = dq.front();
            dq.pop_front();
            if (dis[id] < INF) continue;
            dis[id] = len;
            debug(id, len);
            int p = rt[id];
            while (p != -1) {
                auto [w, i, nxt] = edge[p];
                // debug(p, w, i, nxt);
                if (dis[i] == INF) {
                    if (w) dq.push_back(mp(len + 1, i));
                    else dq.push_front(mp(len, 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];
}

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 'void GRAPH::add_edge(int, int, int)':
skyscraper.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
skyscraper.cpp:36:9: note: in expansion of macro 'debug'
   36 |         debug(u, v, w);
      |         ^~~~~
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:52:9: note: in expansion of macro 'debug'
   52 |         debug(mod, r, v.front());
      |         ^~~~~
skyscraper.cpp: In function 'void GRAPH::ZOBFS(int)':
skyscraper.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
skyscraper.cpp:68:13: note: in expansion of macro 'debug'
   68 |             debug(id, len);
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2516 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 2 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -