Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created September 20, 2016 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurahuna/84057a1e6c33769cd045b354a66bc60e to your computer and use it in GitHub Desktop.
Save yurahuna/84057a1e6c33769cd045b354a66bc60e to your computer and use it in GitHub Desktop.
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int H, W;
vector<string> s;
bool inside(int x, int y) {
return 0 <= x && x < H && 0 <= y && y < W;
}
bool valid(int i, int j) {
if (i == 0) return false;
if (s[i][j] != '-') return false;;
rep(k, 8) {
int ni = i + dx[k], nj = j + dy[k];
if (!inside(ni, nj)) continue;
if (s[ni][nj] == 'x') return false;
if ((k == 1 || k == 3) && s[ni][nj] == 'o') return false;
}
return true;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> H >> W;
s.resize(H);
rep(i, H) cin >> s[i];
int ans = 0;
rep(i, H) {
rep(j, W) {
ans += valid(i, j);
}
}
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment