Submission #1257819

#TimeUsernameProblemLanguageResultExecution timeMemory
1257819Rainmaker2627World Map (IOI25_worldmap)C++20
Compilation error
0 ms0 KiB
#include "worldmap.h"

#include<bits/stdc++.h>
using namespace std;

namespace std {

template <class Fun> class y_combinator_result {
    Fun fun_;

public:
    template <class T>
    explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}

    template <class... Args> decltype(auto) operator()(Args &&...args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template <class Fun> decltype(auto) y_combinator(Fun &&fun) {
    return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

}  // namespace std

vector<vector<int>> ans;
void fill(int d, int v) {
    for (int x = 0; x < 2*n; x++) {
        if (0<=d-x && d-x<2*n) ans[x][d-x]=v;
    }
}

vector<vector<int>> create_map(int N, int M, vector<int> A, vector<int> B) {

    int n=N;
    ans.assign(2*n, vector<int>(2*n, 1));
    vector<vector<int>> adj(n+1);
    vector<int> vis(n+1);
    for (int i = 0; i < M; ++i) {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }

    int glob_diag = 0;
    int cnt = 0;
    auto dfs = y_combinator([&](auto self, int v) -> void {
        vis.at(v) = ++cnt;
        int diag = glob_diag + 1;
        glob_diag += 3;
        fill(diag - 1, v);
        fill(diag, v);
        fill(diag + 1, v);
        int x = max(0, diag - 2 * N + 1);
        for (int w : adj.at(v)) {
            if (!vis.at(w)) {
                self(w);
                fill(glob_diag, v);
                ++glob_diag;
            } else if (vis.at(w) < vis.at(v)) {
                assert(0 <= diag - x && diag - x < 2 * N);
                ans.at(x).at(diag - x) = w;
                ++x;
            }
        }
    });

    dfs(1);

    assert(cnt == N);
    return ans;
}

Compilation message (stderr)

worldmap.cpp: In function 'void fill(int, int)':
worldmap.cpp:28:27: error: 'n' was not declared in this scope
   28 |     for (int x = 0; x < 2*n; x++) {
      |                           ^