fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. string[] s = Console.ReadLine().Split();
  8. int n = Int32.Parse(s[0]);
  9. int m = Int32.Parse(s[1]);
  10. string[] board = new string[n];
  11. char[] marker = new char[]{' ',' '};
  12. int[] count = new int[]{0,0};
  13. int min = int.MaxValue;
  14.  
  15. for(int i = 0; i<n; i++)
  16. {
  17. board[i] = Console.ReadLine();
  18. }
  19.  
  20. for(int row = 0; row<=n-8;row++)
  21. {
  22. for(int col = 0; col<=m-8;col++)
  23. {
  24. for(int i = row; i<row+8; i++)
  25. {
  26. if(i % 2 == 0)
  27. {
  28. marker[0] = 'W';
  29. marker[1] = 'B';
  30. }
  31. else
  32. {
  33. marker[0] = 'B';
  34. marker[1] = 'W';
  35. }
  36.  
  37. for(int j = col; j<col+8; j++)
  38. {
  39. if(board[i][j] != marker[0])
  40. count[0]++;
  41.  
  42. if(board[i][j] != marker[1])
  43. count[1]++;
  44.  
  45. char tmp = marker[0];
  46. marker[0] = marker[1];
  47. marker[1] = tmp;
  48. }
  49. }
  50.  
  51. int minPartition = count[0] > count[1] ? count[1] : count[0];
  52. count[0] = 0;
  53. count[1] = 0;
  54. if (min > minPartition)
  55. min = minPartition;
  56. }
  57. }
  58. Console.Write(min);
  59. }
  60. }
Success #stdin #stdout 0.03s 24740KB
stdin
8 8
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
stdout
Standard output is empty