Here is my code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ar array
#define ll long long
const int MAXN = 1e5 + 1;
bool visited [5000][5000];
int game[5000][5000];
void floodfill(int r, int c, int color){
if(r < 0 || r > 5000 || c < 0 || c > 5000) return;
if(game[r][c] != 0) return;
if(visited[r][c]) return;
visited[r][c] = true;
floodfill(r, c+1, color);
floodfill(r, c-1, color);
floodfill(r-1, c, color);
floodfill(r+1, c, color);
}
int main() {
/* freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout); */
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, x, y;
x=2500;
y=2500;
cin >> n;
char a;
for (int i = 0; i < n; i++)
{
cin >> a;
if(a=='N') {
game[x][y+1]=1;
game[x][y+2]=1;
y+=2;
}
if(a=='S') {
game[x][y-1]=1;
game[x][y-2]=1;
y-=2;
}
if(a=='E') {
game[x+1][y]=1;
game[x+2][y]=1;
x+=2;
}
if(a=='W') {
game[x-1][y]=1;
game[x-2][y]=1;
x-=2;
}
}
int ans(0);
for (int i = 0; i < 5000; i++)
{
for (int j = 0; j < 5000; j++)
{
if(game[i][j]==0&&visited[i][j]==0) {
ans++;
floodfill(i,j,0);
}
}
}
cout << ans;
}
I am basically just making a 2d array, laying the fences, and using floodfill to find all the regions. I don’t understand why I am getting no output.