https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd74/00000000002b3034
why does my code results in WA?
Is any thing there that i was missing?
#include <iostream>
#include <vector>
using namespace std;

bool compassNeighbour(int **a, int i, int j, int m, int n)
{
    int left = 0;
    int right = 0;
    int top = 0;
    int bottom = 0;
    int l = j;
    int r = j;
    int t = i;
    int b = i;
    float cnt = 0;
    while (top <= 0 && t - 1 >= 0)
    {
        top += a[--t][j];
    }
    while (bottom <= 0 && b + 1 < m)
    {
        bottom += a[++b][j];
    }
    while (left <= 0 && l - 1 >= 0)
    {
        left += a[i][--l];
    }
    while (right <= 0 && r + 1 < n)
    {
        right += a[i][++r];
    }
    if (left > 0)
        cnt++;
    if (right > 0)
        cnt++;
    if (bottom > 0)
        cnt++;
    if (top > 0)
        cnt++;
    return (((left + bottom + top + right) / cnt) > a[i][j]) ? true : false;
}

int main()
{
    int te;
    cin >> te;
    for (int i = 0; i < te; i++)
    {
        cout << "Case #" << i + 1 << ": ";
        int interestLevel = 0;
        int m, n;
        cin >> m >> n;
        int **dancers = new int *[m];
        for (int j = 0; j < m; j++)
            dancers[j] = new int[n];
        bool breaker = true;

        for (int j = 0; j < m; j++)
        {
            for (int k = 0; k < n; k++)
            {
                cin >> dancers[j][k];
                interestLevel += dancers[j][k];
            }
        }
        while (breaker)
        {
            vector<pair<int, int>> v;
            for (int j = 0; j < m; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    if (dancers[j][k] > 0)
                    {
                        if (compassNeighbour(dancers, j, k, m, n))
                        {
                            v.push_back(make_pair(j, k));
                        }
                    }
                }
            }
            if (v.size() == 0)
            {
                breaker = false;
            }
            else
            {
                for (auto c : v)
                {
                    dancers[c.first][c.second] = 0;
                }
                cout << endl;
                for (int j = 0; j < m; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        cout << dancers[j][k] << " ";
                    }
                    cout << endl;
                }
                for (int j = 0; j < m; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        interestLevel += dancers[j][k];
                    }
                }
            }
        }
        cout << interestLevel << endl;
    }
}


-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/90a070be-e62f-4b3b-a118-fab95f514075%40googlegroups.com.

Reply via email to