File size: 1,518 Bytes
d3f4f72 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
const int MAXN = 50, INF = 1e9;
int N;
char C[MAXN][MAXN];
void solve() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> C[i][j];
}
}
int ans1 = INF, ans2;
set<pair<int, int>> S;
// Rows
for (int i = 0, j; i < N; i++) {
vector<int> empty;
for (j = 0; j < N; j++) {
if (C[i][j] == 'O') {
break;
}
if (C[i][j] == '.') {
empty.push_back(j);
}
}
if (j == N) {
int c = empty.size();
if (c < ans1) {
ans1 = c;
ans2 = 0;
}
if (c == 1) {
S.insert(make_pair(i, empty[0]));
} else if (c == ans1) {
ans2++;
}
}
}
// Columns
for (int i, j = 0; j < N; j++) {
vector<int> empty;
for (i = 0; i < N; i++) {
if (C[i][j] == 'O') {
break;
}
if (C[i][j] == '.') {
empty.push_back(i);
}
}
if (i == N) {
int c = empty.size();
if (c < ans1) {
ans1 = c;
ans2 = 0;
}
if (c == 1) {
S.insert(make_pair(empty[0], j));
} else if (c == ans1) {
ans2++;
}
}
}
if (ans1 == INF) {
cout << "Impossible" << endl;
} else {
cout << ans1 << " " << (ans1 == 1 ? S.size() : ans2) << endl;
}
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case #" << t << ": ";
solve();
}
return 0;
}
|