Submission #1252646

#TimeUsernameProblemLanguageResultExecution timeMemory
1252646dreamnguyen세계 지도 (IOI25_worldmap)C++20
Compilation error
0 ms0 KiB
#include "worldmap.h"
std::vector<std::vector<int>> create_map(int N, int M, std::vector<int> A, std::vector<int> B) {
    const int K = 2 * N;
    std::vector<std::vector<int>> grid(K, std::vector<int>(K, 0));
    std::vector<std::vector<int>> adj(N + 1);
    for (int i = 0; i < M; ++i) {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }

    std::vector<std::vector<bool>> visited(K, std::vector<bool>(K, false));
    std::vector<bool> country_used(N + 1, false);
    std::function<void(int, int, int)> dfs = [&](int x, int y, int c) {
        if (x < 0 || y < 0 || x >= K || y >= K || visited[x][y]) return;
        visited[x][y] = true;
        grid[x][y] = c;
        country_used[c] = true;
        for (int d = 0; d < 4; ++d) {
            int nx = x + (d == 0) - (d == 1);
            int ny = y + (d == 2) - (d == 3);
            if (nx < 0 || ny < 0 || nx >= K || ny >= K) continue;
            if (!visited[nx][ny]) {
                for (int nc : adj[c]) {
                    if (!country_used[nc]) {
                        dfs(nx, ny, nc);
                        break;
                    }
                }
            }
        }
    };

    dfs(K / 2, K / 2, 1); // Bắt đầu từ giữa bản đồ, từ quốc gia 1

    // Với các quốc gia chưa được dùng, chỉ cần đặt vào vị trí trống bất kỳ
    for (int i = 1; i <= N; ++i) {
        if (!country_used[i]) {
            for (int x = 0; x < K; ++x) {
                for (int y = 0; y < K; ++y) {
                    if (grid[x][y] == 0) {
                        grid[x][y] = i;
                        goto next;
                    }
                }
            }
        next:;
        }
    }

    return grid;
}

Compilation message (stderr)

worldmap.cpp: In function 'std::vector<std::vector<int> > create_map(int, int, std::vector<int>, std::vector<int>)':
worldmap.cpp:13:10: error: 'function' is not a member of 'std'
   13 |     std::function<void(int, int, int)> dfs = [&](int x, int y, int c) {
      |          ^~~~~~~~
worldmap.cpp:2:1: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
    1 | #include "worldmap.h"
  +++ |+#include <functional>
    2 | std::vector<std::vector<int>> create_map(int N, int M, std::vector<int> A, std::vector<int> B) {
worldmap.cpp:13:37: error: expression list treated as compound expression in functional cast [-fpermissive]
   13 |     std::function<void(int, int, int)> dfs = [&](int x, int y, int c) {
      |                                     ^
worldmap.cpp:13:19: error: expected primary-expression before 'void'
   13 |     std::function<void(int, int, int)> dfs = [&](int x, int y, int c) {
      |                   ^~~~
worldmap.cpp:33:5: error: 'dfs' was not declared in this scope
   33 |     dfs(K / 2, K / 2, 1); // Bắt đầu từ giữa bản đồ, từ quốc gia 1
      |     ^~~