fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include<stdio.h>
  4. #include<math.h>
  5. #define ll long long
  6. using namespace std;
  7.  
  8. int n,t,i=0,j=0,k,m,sum=0,r;
  9. /*long long getn()
  10. {long long i=0;
  11.  char ch=getchar_unlocked();
  12.  while(ch>'9'||ch<'0')
  13. ch=getchar_unlocked();
  14.  while(ch<='9'&&ch>='0')
  15.  {i=(i<<1)+(i<<3)+ch-'0';
  16.  ch=getchar_unlocked();
  17.  }
  18. return i;
  19. }
  20. */
  21.  
  22. int main(){
  23. char a[101][101];
  24. cin>>t;
  25. for(i=0;i<t;i++){
  26. cin>>m>>n>>k;
  27. int c[101]={0};
  28. for(j=0;j<m;j++){
  29. scanf("%s",a[j]);
  30. }
  31. for(j=0;j<m;j++){
  32. for(r=0;r<n;r++){
  33. if(a[j][r]=='*')
  34. c[j]++;
  35. }
  36. }
  37. sort(c,c+m);
  38. for(j=0;j<m;j++){
  39. if((c[j]<=n/2)&&k>0){
  40. k--;
  41. c[j]=n-c[j];
  42. }
  43. }
  44. int d=1000000;
  45. for(j=0;j<m;j++){
  46. d=min(d,c[j]);
  47. }
  48.  
  49.  
  50. if(k%2==0){
  51. for(j=0;j<m;j++){
  52. sum=sum+c[j];
  53. }
  54. }
  55. if(k%2!=0){
  56. for(j=0;j<m;j++){
  57. sum=sum+c[j];
  58. }
  59. sum=sum+n-2*d;
  60. }
  61. cout<<sum<<endl;
  62. sum=0;
  63.  
  64. }
  65. return 0;
  66. }
Success #stdin #stdout 0s 3348KB
stdin
2
2 2 1
..
**
2 2 2
..
**
stdout
4
2