File size: 915 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 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1000000000;
const int LIM = 2000005;
int R, C, K;
string G[LIM];
int solve() {
cin >> R >> C >> K;
for (int i = 1; i <= R; i++) {
cin >> G[i];
}
vector<int> nb(LIM);
for (int j = 0; j < C; j++) {
int tot = 0;
for (int i = 1; i <= R; i++) {
tot += G[i][j] == 'X';
}
int curr = 0;
for (int i = 0; i <= R + 1; i++) {
bool isX = 1 <= i && i <= R && G[i][j] == 'X';
curr += isX;
if (isX || curr > K - 1 || tot - curr > R - K) {
nb[i]++;
}
}
}
int ans = INF;
for (int i = 0; i <= R + 1; i++) {
ans = min(ans, abs(i - K) + nb[i]);
}
return ans;
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case #" << t << ": " << solve() << endl;
}
return 0;
}
|