Case passed on my computer but got wrong answer?


  • 0
    Z

    The case ["xxx", "xox", "xxx"] for this problem, my code get the answer ["xxx", "xxx", "xxx"] on my personal computer, but after I submit, I got wrong output. Anybody can help me and tell me why?

    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    class Solution {
        private:
            int R;
            int C;
        public:
            void solve(vector<vector<char> > &board) 
            {
                if(board.size() == 0)
                {
                    return ;
                }
                R = board.size();
                C = board.begin()->size();
                bool status = false;
                for(int i = 0; i < R; ++i)
                {
                    for(int k = 0; k < C; ++k)
                    {
                        if(board[i][k] == 'o')
                        {
                            status = true;
                            dfs(board, i, k, status); 
                        }
                    }
                }
                for(int i = 0; i < R; ++i)
                {
                    for(int k = 0; k < C; ++k)
                    {
                        if(board[i][k] == '?')
                        {
                            board[i][k] = 'o';
                        }
                    }
                }
            }
            void dfs(vector<vector<char> > &board, int r, int c, bool &status)
            {
                board[r][c] = '?'; 
                static const int dr[] = {1, -1, 0 , 0};
                static const int dc[] = {0, 0, -1 , 1};
                if(r == R - 1 || r == 0 || c == C - 1 || c == 0)
                {
                    status = false;
                }
                for(int i = 0 ; i < 4; ++i)
                {
                    int xr = r + dr[i];
                    int xc = c + dc[i];
                    if(xr < R and xr >= 0 and xc < C and xc >= 0 and board[xr][xc] == 'o')
                    {
                        dfs(board, xr, xc, status);
                    }
                }
                if(status)
                {
                    board[r][c] = 'x';
                }            
            }
    };
    /*
    char *test_case[] = {
        "xxxx",
        "xoox",
        "xxox",
        "xoxx",
        NULL
    };
    */
    char *test_case[] = {
        "xxx",
        "xox",
        "xxx",
        NULL
    };
    int main()
    {
        Solution slt;
        int i = 0; 
        vector<vector<char> > board;
        for(int i = 0; test_case[i]; ++i)
        {
            vector<char> v;
            for(int k = 0 ; test_case[i][k] != 0; ++k)
            {
                v.push_back(test_case[i][k]); 
            }
            board.push_back(v);
        }
        for(int i = 0 ; test_case[i]; ++i)
        {
            for(int k = 0 ; test_case[i][k] != 0; ++k)
            {
                cout << board[i][k];
            }
            cout << endl;
        }
        cout   << endl;
        slt.solve(board); 
        for(int i = 0 ; test_case[i]; ++i)
        {
            for(int k = 0 ; test_case[i][k] != 0; ++k)
            {
                cout << board[i][k];
            }
            cout << endl;
        }
    }

  • 0
    T

    I have the same issue on the same test case, works on my own gnu g++ and compileonline.com, but not accepted here!


  • 1

    Please note that the x is actually upper case X. Same with o, it should be uppercase O.


  • 0
    Z

    Thanks, after i read the problem carefully again, i found it.


Log in to reply
 

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