记录编号 |
578449 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[雅礼集训 2017 Day1] 矩阵 |
最终得分 |
100 |
用户昵称 |
zxhhh |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.098 s |
提交时间 |
2023-03-17 19:42:14 |
内存使用 |
4.70 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int lw[N], hb[N], lb[N], n, flag, ans = 0x3f3f3f3f;
char a[N][N];
int main () {
freopen("juzhen.in", "r", stdin);
freopen("juzhen.out", "w", stdout);
scanf("%d", &n);
for (int i = 1;i <= n;i++) scanf("%s", a[i]+1);
for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++) if (a[i][j] == '#') flag = 1, hb[i] = lb[j] = 1; else lw[j] = 1;
if (!flag) {
printf("-1\n");
return 0;
}
for (int i = 1;i <= n;i++) {
int k = 0, cnt = 0, g = 0, gg = 0;
for (int j = 1;j <= n;j++) {
if (a[i][j] == '#') continue;
else if (lb[i] || g) cnt++, g = 1, gg = 1;
else if (hb[j]) cnt += 2, g = 1;
else {k = 1; break;}
}
if (k) continue;
for (int j = 1;j <= n;j++) if (lw[j]) cnt++;
ans = min(ans, cnt);
//for (int )
}
printf("%d\n", ans);
return 0;
}