can anyone help what is wrong in my this code for atcoder question Atcoder D
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=201;
char arr[N][N];
int dr[]={-1,0,1,0};
int dc[]={0,1,0,-1};
int vis[N][N];
void dfs(int i,int j,vector<int> &v,int c)
{
if(vis[i][j]==1)
return;
vis[i][j]=1;
c++;
for(int k=0;k<4;k++)
{
int x=i+dr[k];
int y=j+dc[k];
if(vis[x][y]==0 and arr[x][y]=='.')
{
dfs(x,y,v,c);
}
else
{
v.push_back(c);
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
int n,m;
cin>>n>>m;
::memset(arr,'/',sizeof arr);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++) cin>>arr[i][j];
vector<int> hell;
dfs(1,1,hell,0);
cout<<*max_element(hell.begin(),hell.end())<<endl;
}
Explanation: there are $$$3$$$ cells with ice, and it should be quite obivous that all of these cells can be visited.
Did you read the problem statement properly? Your code is not even close to what it should be. Notice that if you start going in some direction, you can't change direction before you hit a stone. But all of the ice cells you went over are calculated in the answer. In your code, you're just moving one step at a time, possibly changing direction when it's not allowed.
Also, the problem asks for the number of reachable cells, but not all of them need to be reached with a single path. It seems like your code is looking for the longest path (with incorrect changes in direction) which is not what is asked in the problem.