Submission #408611

# Submission time Handle Problem Language Result Execution time Memory
408611 2021-05-19T09:29:48 Z syl123456 Land of the Rainbow Gold (APIO17_rainbow) C++17
Compilation error
0 ms 0 KB
#include "rainbow.h"
vector<vector<bool>> b;
vector<int> p;
int m;
void init(int R, int C, int sr, int sc, int M, char *S) {
    m = C;
    b.assign(R, vector<bool>(C, false));
    p.resize(R * C);
    --sr, --sc;
    b[sr][sc] = true;
    for (int i = 0; i < M; ++i) {
        if (S[i] == 'N') --sr;
        else if (S[i] == 'S') ++sr;
        else if (S[i] == 'W') --sc;
        else ++sc;
        b[sr][sc] = true;
    }
}

int colour(int ar, int ac, int br, int bc) {
    --ar, --ac;
    int _ = 0;
    for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j)
        p[i * m + j] = i * m + j;
    function<int(int)> find = [&](int i) {
        return p[i] = p[i] == i ? i : find(p[i]);
    };
    for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j]) {
        if (i < br - 1 && !b[i + 1][j])
            p[find(i * m + j)] = find((i + 1) * m + j);
        if (j < bc - 1 && !b[i][j + 1])
            p[find(i * m + j)] = find(i * m + j + 1);
    }
    int ans = 0;
    for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j])
        ans += find(i * m + j) == i * m + j;
    return ans;
}

Compilation message

rainbow.cpp:2:1: error: 'vector' does not name a type
    2 | vector<vector<bool>> b;
      | ^~~~~~
rainbow.cpp:3:1: error: 'vector' does not name a type
    3 | vector<int> p;
      | ^~~~~~
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:7:5: error: 'b' was not declared in this scope
    7 |     b.assign(R, vector<bool>(C, false));
      |     ^
rainbow.cpp:7:17: error: 'vector' was not declared in this scope
    7 |     b.assign(R, vector<bool>(C, false));
      |                 ^~~~~~
rainbow.cpp:7:24: error: expected primary-expression before 'bool'
    7 |     b.assign(R, vector<bool>(C, false));
      |                        ^~~~
rainbow.cpp:8:5: error: 'p' was not declared in this scope
    8 |     p.resize(R * C);
      |     ^
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:24:9: error: 'p' was not declared in this scope
   24 |         p[i * m + j] = i * m + j;
      |         ^
rainbow.cpp:25:5: error: 'function' was not declared in this scope; did you mean 'union'?
   25 |     function<int(int)> find = [&](int i) {
      |     ^~~~~~~~
      |     union
rainbow.cpp:25:14: error: expected primary-expression before 'int'
   25 |     function<int(int)> find = [&](int i) {
      |              ^~~
rainbow.cpp:28:70: error: 'b' was not declared in this scope
   28 |     for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j]) {
      |                                                                      ^
rainbow.cpp:30:13: error: 'p' was not declared in this scope
   30 |             p[find(i * m + j)] = find((i + 1) * m + j);
      |             ^
rainbow.cpp:30:15: error: 'find' was not declared in this scope
   30 |             p[find(i * m + j)] = find((i + 1) * m + j);
      |               ^~~~
rainbow.cpp:32:13: error: 'p' was not declared in this scope
   32 |             p[find(i * m + j)] = find(i * m + j + 1);
      |             ^
rainbow.cpp:32:15: error: 'find' was not declared in this scope
   32 |             p[find(i * m + j)] = find(i * m + j + 1);
      |               ^~~~
rainbow.cpp:35:70: error: 'b' was not declared in this scope
   35 |     for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j])
      |                                                                      ^
rainbow.cpp:36:16: error: 'find' was not declared in this scope
   36 |         ans += find(i * m + j) == i * m + j;
      |                ^~~~
rainbow.cpp:22:9: warning: unused variable '_' [-Wunused-variable]
   22 |     int _ = 0;
      |         ^