Advertisement
Emiliatan

d537

Jun 2nd, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. /* d537            */
  2. /* AC (3ms, 144KB) */
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int color_plate[102][102];
  9.  
  10. int colorid(char ch)
  11. {
  12.     switch(ch)
  13.     {
  14.         case 'R':
  15.             return 1;
  16.         case 'B':
  17.             return 2;
  18.         case 'Y':
  19.             return 4;
  20.         case 'P':
  21.             return 3;
  22.         case 'O':
  23.             return 5;
  24.         case 'D':
  25.             return 7;
  26.         case 'G':
  27.             return 6;
  28.     }
  29. }
  30.  
  31. int check(int color, int &color_number, int N)
  32. {
  33.     for(int y = 0; y < N; ++y)
  34.         for(int x = 0; x < N; ++x)
  35.             if(color_plate[y][x] == color)
  36.                 ++color_number;
  37. }
  38. bool inside(int x, int y, int N)
  39. {
  40.     return (x >= 0 && x < N && y >= 0 && y < N);
  41. }
  42. int main()
  43. {
  44.     for(int N, Max_area = 0; ~scanf("%d", &N); Max_area = 0)
  45.     {
  46.         char ch[2];
  47.         int _X[3], _Y[3], COLOR[3];
  48.         memset(color_plate, 0, sizeof(color_plate));
  49.  
  50.         for(int i = 0, x, y; i < 3 && scanf("%s %d %d", ch, &x, &y); ++i)
  51.         {
  52.             _X[i] = x;
  53.             _Y[i] = N - y - 1;
  54.             COLOR[i] = colorid(ch[0]);
  55.             color_plate[N - y - 1][x] = colorid(ch[0]) | color_plate[N - y - 1][x];
  56.         }
  57.         scanf("%s", ch);
  58.         int color = colorid(ch[0]);
  59.  
  60.         for(int t = 0, area = 0; t <= N; ++t, area = 0)
  61.         {
  62.             check(color, area, N);
  63.             Max_area = (Max_area < area ? area : Max_area);
  64.             for(int i = 0; i < 3; ++i)
  65.             {
  66.                 int y = _Y[i], x = _X[i], ty = y - t, dy = y + t, lx = x - t, rx = x + t;
  67.                 if(ty < 0) ty = 0;
  68.                 if(dy >= N) dy = N - 1;
  69.                 if(lx < 0) lx = 0;
  70.                 if(rx >= N) rx = N - 1;
  71.                 for(int Y = ty; Y <= dy; ++Y)
  72.                     for(int X = lx; X <= rx; ++X)
  73.                         color_plate[Y][X] |= COLOR[i];
  74.             }
  75.         }
  76.         printf("%d\n", Max_area);
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement