Weired Runtime Error :(


  • 0
    J

    class Solution {
    public:
    void dfs(int i,int j,vector<vector<int>>& matrix,vector<vector<int>>& visited,int curr)
    {
    int m=matrix.size(),n=matrix[0].size();
    if(i>m || j>n || i<0 || j<0)return ;
    if(visited[i][j]==curr || visited[i][j]==3)return;
    if(visited[i][j]!=0)
    visited[i][j]=visited[i][j]+curr;
    else
    visited[i][j]=curr;

        if(i+1<m && visited[i+1][j]!=curr && visited[i+1][j]!=3 && matrix[i+1][j] >= matrix[i][j])
        {
            dfs(i+1,j,matrix,visited,curr);
        }
        if(j+1<n && visited[i][j+1]!=curr && visited[i][j+1]!=3 && matrix[i][j+1] >= matrix[i][j])
        {
            dfs(i,j+1,matrix,visited,curr);
        }
        if(i-1>=0 && visited[i-1][j]!=curr && visited[i-1][j]!=3 && matrix[i-1][j] >= matrix[i][j])
        {
            dfs(i-1,j,matrix,visited,curr);
        }
        if(j-1>=0 && visited[i][j-1]!=curr && visited[i][j-1]!=3 && matrix[i][j-1] >= matrix[i][j])
        {
            dfs(i,j-1,matrix,visited,curr);
        }
    }
    vector<pair<int, int>> pacificAtlantic(vector<vector<int>>& matrix) {        
        vector<pair<int,int> > ans;
        int m=matrix.size(),i,j;
        if(m==0)return ans;int n=matrix[0].size();
        vector<vector<int> > visited(m,vector<int> (n,0));
        for(i=0;i<m;i++)
            dfs(i,0,matrix,visited,1);
        for(j=0;j<n;j++)
            dfs(0,j,matrix,visited,1);
        for(i=0;i<n;i++)
            dfs(i,n-1,matrix,visited,2);
        for(j=0;j<n;j++)
            dfs(m-1,j,matrix,visited,2);
    
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                if(visited[i][j]==3)
                    ans.push_back(make_pair(i,j));
            }
        }
        return ans;
    }
    

    };

    I am getting " reference binding to misaligned address 0x000000000055 for type 'value_type', which requires 4 byte alignment " error on following input: [[3,3,3,3,3,3],[3,0,3,3,0,3],[3,3,3,3,3,3]]. Any suggestions why ? :)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.