This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>r;
int n,m;
vector<int>dx = {-1,0,1,0};
vector<int>dy = {0,1,0,-1};
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R,m = C;
r.resize(R,vector<int>(C,0));
--sr;--sc;
for (int i = 0;i<M;++i){
char x = S[i];
r[sr][sc] = 1;
if (x == 'N'){
sr--;
}
else if (x == 'S'){
sr++;
}
else if (x == 'W'){
sc--;
}
else{
sc++;
}
}
r[sr][sc] = 1;
}
int colour(int ar, int ac, int br, int bc) {
vector<vector<bool>>visited(n,vector<bool>(m,0));
int ans = 0;
function<void(int,int)>dfs = [&](int u,int v){
visited[u][v] = true;
for (int i = 0;i<4;++i){
int nx = u + dx[i];
int ny = v + dy[i];
if (nx >=ar - 1 && nx < br && ny >= ac - 1 && ny < bc && !visited[nx][ny] && !r[nx][ny]){
dfs(nx,ny);
}
}
};
for (int i = ar - 1;i<br;++i){
for (int j = ac - 1;j<bc;++j){
if (!visited[i][j] && !r[i][j]){
dfs(i,j);
ans++;
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |