forked from chinoxyz/Spoj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AMR12G.cpp
113 lines (88 loc) · 1.85 KB
/
AMR12G.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <cstdio>
#include <algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include <complex>
#include <iostream>
#include <valarray>
#include<cstring>
#include<queue>
#include<bitset>
#include<map>
#include<set>
#include<sstream>
#include<ctime>
#include <stack>
#include <iomanip>
using namespace std;
#define PB push_back
#define i64 long long
#define FOR(i,a,b) for(i=(a);i<(b);++i)
#define FORE(i,a,b) for(i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FORE(i,0,n)
#define SZ(v) ((v).size())
#define LD long double
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VLD vector<LD>
#define MSET(x,y) memset((x),(y),sizeof(x))
#define SZOF(x) sizeof((x))
#define VVI vector< VI >
#define PII pair< int,int >
#define VPII vector< PII >
#define MP make_pair
#define PIPII pair<int, PII >
#define PIPIPII pair< int, PIPII >
#define u64 unsigned i64
#define MAXN 52
char arr[MAXN][MAXN];
int ct[MAXN];
int main(){
freopen("Text/AMR12G.txt","r",stdin);
int n,m,cases,k;
scanf("%d",&cases);
while(cases--)
{
MSET(ct,0);
scanf("%d %d %d",&n,&m,&k);
for(int i=0;i<n;++i)
{
scanf("%s",&arr[i]);
for(int j=0;j<m;++j)
{
if(arr[i][j]=='*')
{
++ct[i];
}
}
}
sort(ct,ct+n);
for(int i=0;i<n && k>0;++i)
{
if(2*ct[i]<m)
{
ct[i]=m-ct[i];
--k;
}
else
{
break;
}
}
sort(ct,ct+n);
if(k&1)
{
ct[0]=m-ct[0];
}
int ans=0;
for(int i=0;i<n;++i)
{
ans+=ct[i];
}
printf("%d\n",ans);
}
return 0;
}