C++ with picture, upscaled grid
Note: the problem can be solved in a simpler way; here I just wanted to re-use the upscale tactic from 959. Regions Cut By Slashes.\n\nLike for other similar pr
> Note: the problem can be solved in a simpler way; here I just wanted to re-use the upscale tactic from [959. Regions Cut By Slashes](https://leetcode.com/problems/regions-cut-by-slashes/discuss/205674/C%2B%2B-with-picture-DFS-on-upscaled-grid).\n\nLike for other similar problems, we upscale our grid to 3x, and paint our lines there. Then, we can do regular DFS for each ball and see if it reaches the bottom.\n\nA ball can either go down - if the position is not blocked, left or right. If a ball gets stuck - return -1.\n\n![image](https://assets.leetcode.com/users/images/bb7f412f-f368-4e2c-b5c5-dbdb2dba1c3e_1609041793.3970044.png)\n\n```cpp\nvector<pair<int, int>> dir{{1, 0}, {0, -1}, {0, 1}};\nint drop(int pos, vector<vector<int>> &ug, int m, int n) {\n    queue<pair<int, int>> q;\n    q.push({0, pos});\n    while (!q.empty()) {\n        auto [i, j] = q.front();\n        q.pop();\n        if (i == m - 1)\n            return j / 3;\n        ug[i][j] = 1;\n        for (auto [di, dj] : dir)\n            if (j + dj >= 0 && j + dj < n && !ug[i + di][j + dj]) {\n                q.push({i + di, j + dj});\n                break;\n            }\n    }\n    return -1;\n}\nvector<int> findBall(vector<vector<int>>& g) {\n    int m = g.size(), n = g[0].size();\n    vector<vector<int>> ug(m * 3, vector<int>(n * 3));\n    for (auto i = 0; i < m; ++i)\n        for (auto j = 0; j < n; ++j) {\n            ug[i * 3 + 1][j * 3 + 1] = 1;\n            ug[i * 3][j * 3] = ug[i * 3 + 2][j * 3 + 2] = g[i][j] == 1;\n            ug[i * 3][j * 3 + 2] = ug[i * 3 + 2][j * 3] = g[i][j] != 1;\n        }\n    vector<int> res;\n    for (auto i = 0; i < n; ++i) {\n        res.push_back(drop(i * 3 + 1, ug, m * 3, n * 3));\n    }\n    return res;\n}\n```
[]