TOPIC

Wrong Answer (100%)

Bruno Machado Lobell asked 10 months ago

Está funcionando para todos os casos de testes que encontrei, mas ainda está dando "Wrong Answer (100%)"

#include <iostream>
using namespace std;

int main() {
    int n,m,adj;
    while(cin >> n >> m){
        int M[n][m];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                cin >> M[i][j];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                adj = 0;
                if(M[i][j] == 1)
                    M[i][j] = 9;
                else{
                    if(((M[i][j+1] == 1) || (M[i][j+1] == 9)) && (j != m - 1))
                        adj++;
                    if((M[i+1][j] == 1) || (M[i+1][j] == 9))
                        adj++;
                    if((M[i-1][j] == 1) || (M[i-1][j] == 9))
                        adj++;
                    if(((M[i][j-1] == 1) || (M[i][j-1] == 9)) && (j != 0))
                        adj++;
                    if(adj != 1)
                        M[i][j] = adj;
                    else
                        M[i][j] = -1;
                }                    
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(M[i][j] == -1)
                    cout << 1;
                else
                    cout << M[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 10 months ago

                        if((M[i+1][j] == 1) || (M[i+1][j] == 9))
                            adj++;
                        if((M[i-1][j] == 1) || (M[i-1][j] == 9))
                            adj++;

    Why don't you check here that i < n-1 or i > 0?