h1j1k1

untitled

Aug 3rd, 2021
693
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #define rep(i,r,l) for(int i =(r); (int) l < i;i++)
  3. int  main(void){
  4.   int h,w;
  5.   scanf("%d %d", &h, &w);
  6.   char mi[h+1][w+1], mo[h+1][h+1];
  7.   char t;
  8.   int rc[h], bc[h], wc[h];
  9.   rep(i,0,h){
  10.     rep(j,0,w){
  11.       if((t= mi[i][j] = mo[i][j] =getchar()) != 'R'){
  12.         rc[i] ++;
  13.       }
  14.       if((t) != 'B'){
  15.         bc[i]++;
  16.       }
  17.       if((t) != 'W'){
  18.         wc[i]++;
  19.       }
  20.     }
  21.   }
  22.   int we = 0, re = 0;
  23.   int cmin = 1e9+7;
  24.   int buf_cmin = 0
  25.   rep(i,1,h-2){
  26.     rep(j,2+i,h-1){
  27.       buf_cmin =0;
  28.       rep(k,0,i-1){
  29.         buf_cmin += wc[k];
  30.       }
  31.       rep(k,i,j-1){
  32.         buf_cmin += bc[k];
  33.       }
  34.       rep(k,j,h){
  35.         buf_cmin += rc[k];
  36.       }
  37.       if(buf_cmin < cmin){
  38.         cmin = buf_cmin;
  39.         we = (we >= i ? i:we);
  40.         re = (we >= j ? j:re);
  41.       }
  42.     }
  43.   }
  44.   printf("%d %d",we,re );
  45.   return 0;
  46. }
RAW Paste Data