Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created October 22, 2019 00:53
Show Gist options
  • Save surinoel/3963106e7b564d0848158e983da267be to your computer and use it in GitHub Desktop.
Save surinoel/3963106e7b564d0848158e983da267be to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
using namespace std;
int mat[100][100];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < n; j++) {
if (s[j] == '.') mat[i][j] = 0;
else mat[i][j] = 1;
}
}
int row, col;
row = col = 0;
for (int i = 0; i < n; i++) {
bool ok = false;
for (int j = 0; j < n; j++) {
if (mat[i][j] == 1) {
if (!ok && j - 2 >= 0 && mat[i][j - 2] == 0 && mat[i][j - 1] == 0) {
row += 1;
}
if (j + 2 < n && mat[i][j + 1] == 0 && mat[i][j + 2] == 0) {
row += 1;
}
ok = true;
}
}
if (!ok) row += 1;
}
for (int j = 0; j < n; j++) {
bool ok = false;
for (int i = 0; i < n; i++) {
if (mat[i][j] == 1) {
if (!ok && i - 2 >= 0 && mat[i - 2][j] == 0 && mat[i - 1][j] == 0) {
col += 1;
}
if (i + 2 < n && mat[i + 1][j] == 0 && mat[i + 2][j] == 0) {
col += 1;
}
ok = true;
}
}
if (!ok) col += 1;
}
if (n == 1) row = col = 0;
cout << row << ' ' << col << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment