fork download
  1. #include <iostream>
  2. using namespace std;
  3. int whiteans=0,blueans=0;
  4.  
  5. int check(int a[100][100], int startx,int starty, int endx, int endy){
  6.  
  7. int white=0,blue=0;
  8. for(int i=startx;i<=endx;i++){
  9. for(int j=starty;j<=endy;j++){
  10. if(a[i][j]==1){
  11. ++blue;
  12. }else{
  13. ++white;
  14. }
  15. }
  16. }
  17. if(white==0){
  18. return 1;
  19. }
  20. if(blue==0){
  21. return 2;
  22. }
  23. return 3;
  24. }
  25. void whiteandblue(int a[100][100], int n,int startx, int starty, int endx, int endy){
  26.  
  27. int t = check(a,startx,starty,endx,endy);
  28.  
  29. if(t==1){
  30. blueans++;return;
  31. }else if(t==2){
  32. whiteans++;return;
  33. }
  34. whiteandblue(a,n/2,startx,starty,startx+n/2,starty+n/2);
  35. whiteandblue(a,n/2,startx,(starty+n/2)+1,startx+n/2,endy);
  36. whiteandblue(a,n/2,(startx+n/2)+1,starty,endx,starty+n/2);
  37. whiteandblue(a,n/2,(startx+n/2)+1,(starty+n/2)+1,endx,endy);
  38.  
  39.  
  40.  
  41. return;
  42.  
  43. }
  44. int main() {
  45. //freopen("input.txt","r",stdin);
  46. //freopen("output.txt","w",stdout);
  47. ios_base::sync_with_stdio(false);
  48. int t;
  49. cin>>t;
  50. while(t--){
  51. whiteans=0,blueans=0;
  52. int n;
  53. cin>>n;
  54. int a[100][100];
  55. for(int i=0;i<n;i++){
  56. for(int j=0;j<n;j++){
  57. cin>>a[i][j];
  58. }
  59. }
  60. whiteandblue(a,n-1,0,0,n-1,n-1);
  61. cout<<whiteans<<" "<<blueans<<endl;
  62. }
  63. return 0;
  64. }
Success #stdin #stdout 0s 15240KB
stdin
2
8
1 1 0 0 0 0 1 1
1 1 0 0 0 0 1 1
0 0 0 0 1 1 0 0
0 0 0 0 1 1 0 0
1 0 0 0 1 1 1 1
0 1 0 0 1 1 1 1 
0 0 1 1 1 1 1 1
0 0 1 1 1 1 1 1

16
1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 1
1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 1 1 1 0 0 1 0 0 1
1 1 0 0 1 0 0 1 0 0 1 0 1 1 1 0
0 1 1 1 0 0 1 1 0 0 1 0 0 1 1 1
1 0 1 1 0 0 0 1 0 1 0 1 0 0 1 1
1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0
1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 1
1 1 1 1 1 1 0 0 1 0 1 1 0 1 1 0
1 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0
1 0 0 1 1 1 1 0 0 0 1 1 0 1 0 1
1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1
1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0
1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0
1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0
1 1 0 0 1 1 0 0 0 1 1 1 1 0 0 0
stdout
9 7
88 99