#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
map<char,int> adjr = {{'N', 1}, {'S', -1}};
map<char,int> adjc = {{'E', 1}, {'W', -1}};
int adjx[] = {0, -1};
int adjy[] = {-1, 0};
int R, C;
bool mark[51][51];
int par[52*52];
int get_par(int v){
return par[v] < 0 ? v : par[v] = get_par(par[v]);
}
bool merge(int v, int u){
if ((v = get_par(v)) == (u = get_par(u)))
return false;
if (par[v] > par[u])
swap(v, u);
par[u] = v;
return true;
}
void init(int r, int c, int sr, int sc, int M, string s){
R = r, C = c;
mark[sr][sc] = 1;
for (int i = 0; i < M; i++){
sr += adjr[s[i]], sc += adjc[s[i]];
mark[sr][sc] = 1;
}
}
int colours(int x1, int y1, int x2, int y2){
int cnt = 0;
memset(par, -1, sizeof par);
for (int i = x1; i <= x2; i++){
for (int j = y1; j <= y2; j++){
if (mark[i][j])
continue;
cnt ++;
if (i > x1 and mark[i-1][j])
merge((i-1)*C+j, (i-2)*C+j);
if (j > y1 and mark[i][j-1])
merge((i-1)*C+j, (i-1)*C+j-1);
}
}
return cnt;
}
Compilation message
/tmp/ccAKhmw1.o: In function `main':
grader.cpp:(.text.startup+0xcc): undefined reference to `init(int, int, int, int, int, char*)'
grader.cpp:(.text.startup+0x131): undefined reference to `colour(int, int, int, int)'
collect2: error: ld returned 1 exit status