やるだけ
class HappyCells { public: vector <int> getHappy(vector <string> g) { vector<int> ret(3, 0); const int di[] = {0, 0, -1, +1, -1, -1, +1, +1}; const int dj[] = {-1, +1, 0, 0, -1, +1, -1, +1}; for (int i = 0; i < (int)g.size(); ++i) { g[i] = "X" + g[i] + "X"; } g.push_back(string(g[0].size(), 'X')); g.insert(g.begin(), g.back()); const int h = g.size(); const int w = g[0].size(); for (int i = 0; i < (int)h; ++i) { for (int j = 0; j < (int)w; ++j) { if (g[i][j] == '.') { int orth = 0; int dia = 0; for (int d = 0; d < (int)8; ++d) { int ni = i + di[d]; int nj = j + dj[d]; if (ni < 0 || nj < 0) continue; if (h <= ni || w <= nj) continue; if (g[ni][nj] == 'X') { orth += d < 4; dia += 4 <= d; } } ret[0] += orth == 4 && dia == 4; ret[1] += orth == 4 && dia != 4; ret[2] += orth != 4 && dia == 4; } } } return ret; } };