#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
#define ll long long
#define fi first
#define se second
ll inf = 1ll << 60;
int r, c, m, q, r0, c0, r1, c1, r2, c2;
char *s;
map<pair<int, int>, bool> is, is2, vis;
bool valid(int i, int j){
if (i > r2 or i < r1) return false;
if (j > c2 or j < c1) return false;
if (is[{i, j}]) return false;
return true;
}
void dfs(int i, int j){
vis[{i, j}] = true;
if (is2[{i + 1, j}] and !vis[{i + 1, j}]) dfs(i + 1, j);
if (is2[{i - 1, j}] and !vis[{i - 1, j}]) dfs(i - 1, j);
if (is2[{i, j + 1}] and !vis[{i, j + 1}]) dfs(i, j + 1);
if (is2[{i, j - 1}] and !vis[{i, j - 1}]) dfs(i, j - 1);
}
void init(int _r, int _c, int _r0, int _c0, int _m, char *_s){
r = _r, c = _c, m = _m, r0 = _r0, c0 = _c0, s = _s;
}
int colours(int _r1, int _c1, int _r2, int _c2){
r1 = _r1, c1 = _c1, r2 = _r2, c2 = _c2;
vector<pair<int, int>> a, b;
a.push_back({r0, c0});
int x = r0, y = c0;
for (int i = 0; i < m; i++){
if (s[i] == 'S') x++;
if (s[i] == 'N') x--;
if (s[i] == 'E') y++;
if (s[i] == 'W') y--;
a.push_back({x, y});
is[{x, y}] = true;
}
for (int i = r1; i <= r2; i++){
a.push_back({i, c1 - 1});
a.push_back({i, c2 + 1});
}
for (int i = c1; i <= c2; i++){
a.push_back({r1 - 1, i});
a.push_back({r2 + 1, i});
}
for (auto i : a){
if (valid(i.fi + 1, i.se)) b.push_back({i.fi + 1, i.se});
if (valid(i.fi, i.se + 1)) b.push_back({i.fi, i.se + 1});
if (valid(i.fi - 1, i.se)) b.push_back({i.fi - 1, i.se});
if (valid(i.fi, i.se - 1)) b.push_back({i.fi, i.se - 1});
}
int ans = 0;
for (auto i : b) is2[i] = true;
for (auto i : b){
if (!vis[i]){
dfs(i.fi, i.se);
ans++;
}
}
return ans;
}
Compilation message
/usr/bin/ld: /tmp/cctzrXaw.o: in function `main':
grader.cpp:(.text.startup+0x167): undefined reference to `colour(int, int, int, int)'
collect2: error: ld returned 1 exit status