Hex Artifact Content
Not logged in

Artifact 4557c7ca92985007fa4cc9a1ae5a582bcb2c0345:


0000: 23 69 6e 63 6c 75 64 65 20 3c 69 6f 73 74 72 65  #include <iostre
0010: 61 6d 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73  am>..#include <s
0020: 73 74 72 65 61 6d 3e 0d 0a 23 69 6e 63 6c 75 64  stream>..#includ
0030: 65 20 3c 69 6f 6d 61 6e 69 70 3e 0d 0a 23 69 6e  e <iomanip>..#in
0040: 63 6c 75 64 65 20 3c 76 65 63 74 6f 72 3e 0d 0a  clude <vector>..
0050: 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67  #include <string
0060: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 6d 61 70  >..#include <map
0070: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73 65 74  >..#include <set
0080: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 61 6c 67  >..#include <alg
0090: 6f 72 69 74 68 6d 3e 0d 0a 23 69 6e 63 6c 75 64  orithm>..#includ
00a0: 65 20 3c 6e 75 6d 65 72 69 63 3e 0d 0a 23 69 6e  e <numeric>..#in
00b0: 63 6c 75 64 65 20 3c 69 74 65 72 61 74 6f 72 3e  clude <iterator>
00c0: 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 66 75 6e 63  ..#include <func
00d0: 74 69 6f 6e 61 6c 3e 0d 0a 23 69 6e 63 6c 75 64  tional>..#includ
00e0: 65 20 3c 63 6f 6d 70 6c 65 78 3e 0d 0a 23 69 6e  e <complex>..#in
00f0: 63 6c 75 64 65 20 3c 71 75 65 75 65 3e 0d 0a 23  clude <queue>..#
0100: 69 6e 63 6c 75 64 65 20 3c 73 74 61 63 6b 3e 0d  include <stack>.
0110: 0a 23 69 6e 63 6c 75 64 65 20 3c 63 6d 61 74 68  .#include <cmath
0120: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 63 61 73  >..#include <cas
0130: 73 65 72 74 3e 0d 0a 75 73 69 6e 67 20 6e 61 6d  sert>..using nam
0140: 65 73 70 61 63 65 20 73 74 64 3b 0d 0a 74 79 70  espace std;..typ
0150: 65 64 65 66 20 6c 6f 6e 67 20 6c 6f 6e 67 20 4c  edef long long L
0160: 4c 3b 0d 0a 74 79 70 65 64 65 66 20 6c 6f 6e 67  L;..typedef long
0170: 20 64 6f 75 62 6c 65 20 4c 44 3b 0d 0a 74 79 70   double LD;..typ
0180: 65 64 65 66 20 63 6f 6d 70 6c 65 78 3c 4c 44 3e  edef complex<LD>
0190: 20 43 4d 50 3b 0d 0a 0d 0a 73 74 61 74 69 63 20   CMP;....static 
01a0: 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 4d  const unsigned M
01b0: 4f 44 56 41 4c 20 3d 20 31 30 30 30 30 30 30 30  ODVAL = 10000000
01c0: 30 39 3b 0d 0a 0d 0a 63 6c 61 73 73 20 4d 6f 75  09;....class Mou
01d0: 6e 74 61 69 6e 73 20 7b 20 70 75 62 6c 69 63 3a  ntains { public:
01e0: 0d 0a 09 69 6e 74 20 63 6f 75 6e 74 50 6c 61 63  ...int countPlac
01f0: 65 6d 65 6e 74 73 28 76 65 63 74 6f 72 20 3c 69  ements(vector <i
0200: 6e 74 3e 20 68 65 69 67 68 74 73 2c 20 76 65 63  nt> heights, vec
0210: 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 76 69 73  tor <string> vis
0220: 69 62 69 6c 69 74 79 29 0d 0a 09 7b 0d 0a 09 09  ibility)...{....
0230: 69 6e 74 20 57 20 3d 20 76 69 73 69 62 69 6c 69  int W = visibili
0240: 74 79 5b 30 5d 2e 73 69 7a 65 28 29 3b 0d 0a 09  ty[0].size();...
0250: 09 69 6e 74 20 4e 20 3d 20 76 69 73 69 62 69 6c  .int N = visibil
0260: 69 74 79 2e 73 69 7a 65 28 29 3b 0d 0a 09 09 6d  ity.size();....m
0270: 65 6d 6f 2e 72 65 73 69 7a 65 28 4e 29 3b 0d 0a  emo.resize(N);..
0280: 0d 0a 09 09 76 65 63 74 6f 72 3c 69 6e 74 3e 20  ....vector<int> 
0290: 76 69 65 77 28 57 2c 20 30 29 3b 0d 0a 09 09 72  view(W, 0);....r
02a0: 65 74 75 72 6e 20 72 65 63 28 57 2c 20 76 69 65  eturn rec(W, vie
02b0: 77 2c 20 68 65 69 67 68 74 73 2e 73 69 7a 65 28  w, heights.size(
02c0: 29 2d 31 2c 20 68 65 69 67 68 74 73 2c 20 76 69  )-1, heights, vi
02d0: 73 69 62 69 6c 69 74 79 29 3b 0d 0a 09 7d 0d 0a  sibility);...}..
02e0: 0d 0a 09 76 65 63 74 6f 72 3c 20 6d 61 70 3c 76  ...vector< map<v
02f0: 65 63 74 6f 72 3c 69 6e 74 3e 2c 69 6e 74 3e 20  ector<int>,int> 
0300: 3e 20 6d 65 6d 6f 3b 0d 0a 09 69 6e 74 20 72 65  > memo;...int re
0310: 63 28 69 6e 74 20 57 2c 20 63 6f 6e 73 74 20 76  c(int W, const v
0320: 65 63 74 6f 72 3c 69 6e 74 3e 26 20 76 69 65 77  ector<int>& view
0330: 2c 20 69 6e 74 20 69 2c 20 76 65 63 74 6f 72 3c  , int i, vector<
0340: 69 6e 74 3e 26 20 48 2c 20 63 6f 6e 73 74 20 76  int>& H, const v
0350: 65 63 74 6f 72 3c 73 74 72 69 6e 67 3e 26 20 56  ector<string>& V
0360: 29 0d 0a 09 7b 0d 0a 09 09 69 66 28 69 20 3c 20  )...{....if(i < 
0370: 30 29 0d 0a 09 09 09 72 65 74 75 72 6e 20 31 3b  0).....return 1;
0380: 0d 0a 0d 0a 09 09 69 66 28 6d 65 6d 6f 5b 69 5d  ......if(memo[i]
0390: 2e 63 6f 75 6e 74 28 76 69 65 77 29 29 0d 0a 09  .count(view))...
03a0: 09 09 72 65 74 75 72 6e 20 6d 65 6d 6f 5b 69 5d  ..return memo[i]
03b0: 5b 76 69 65 77 5d 3b 0d 0a 0d 0a 09 09 69 6e 74  [view];......int
03c0: 20 6d 75 73 74 4c 3d 30 2c 20 6d 75 73 74 52 3d   mustL=0, mustR=
03d0: 57 2d 31 3b 0d 0a 09 09 69 6e 74 20 6d 75 73 74  W-1;....int must
03e0: 4e 6f 74 4c 3d 57 2c 20 6d 75 73 74 4e 6f 74 52  NotL=W, mustNotR
03f0: 3d 2d 31 3b 0d 0a 09 09 66 6f 72 28 69 6e 74 20  =-1;....for(int 
0400: 78 3d 30 3b 20 78 3c 57 3b 20 2b 2b 78 29 0d 0a  x=0; x<W; ++x)..
0410: 09 09 7b 0d 0a 09 09 09 69 6e 74 20 4c 4c 4c 20  ..{.....int LLL 
0420: 3d 20 78 20 2d 20 28 48 5b 69 5d 2d 76 69 65 77  = x - (H[i]-view
0430: 5b 78 5d 2d 31 29 3b 0d 0a 09 09 09 69 6e 74 20  [x]-1);.....int 
0440: 52 52 52 20 3d 20 78 20 2b 20 28 48 5b 69 5d 2d  RRR = x + (H[i]-
0450: 76 69 65 77 5b 78 5d 2d 31 29 3b 0d 0a 09 09 09  view[x]-1);.....
0460: 69 66 28 56 5b 69 5d 5b 78 5d 20 3d 3d 20 27 58  if(V[i][x] == 'X
0470: 27 29 20 7b 0d 0a 09 09 09 09 69 66 28 20 48 5b  ') {......if( H[
0480: 69 5d 20 3c 3d 20 76 69 65 77 5b 78 5d 20 29 0d  i] <= view[x] ).
0490: 0a 09 09 09 09 09 72 65 74 75 72 6e 20 30 3b 0d  ......return 0;.
04a0: 0a 09 09 09 09 6d 75 73 74 4c 20 3d 20 6d 61 78  .....mustL = max
04b0: 28 6d 75 73 74 4c 2c 20 4c 4c 4c 29 3b 0d 0a 09  (mustL, LLL);...
04c0: 09 09 09 6d 75 73 74 52 20 3d 20 6d 69 6e 28 6d  ...mustR = min(m
04d0: 75 73 74 52 2c 20 52 52 52 29 3b 0d 0a 09 09 09  ustR, RRR);.....
04e0: 7d 20 65 6c 73 65 20 7b 0d 0a 2f 2f 09 09 09 09  } else {..//....
04f0: 69 66 28 20 48 5b 69 5d 20 3e 20 76 69 65 77 5b  if( H[i] > view[
0500: 78 5d 20 29 20 7b 0d 0a 2f 2f 09 09 09 09 09 6d  x] ) {..//.....m
0510: 75 73 74 4e 6f 74 4c 20 3d 20 6d 69 6e 28 6d 75  ustNotL = min(mu
0520: 73 74 4e 6f 74 4c 2c 20 4c 4c 4c 29 3b 0d 0a 2f  stNotL, LLL);../
0530: 2f 09 09 09 09 09 6d 75 73 74 4e 6f 74 52 20 3d  /.....mustNotR =
0540: 20 6d 61 78 28 6d 75 73 74 4e 6f 74 52 2c 20 52   max(mustNotR, R
0550: 52 52 29 3b 0d 0a 2f 2f 09 09 09 09 7d 0d 0a 09  RR);..//....}...
0560: 09 09 7d 0d 0a 09 09 7d 0d 0a 0d 0a 09 09 4c 4c  ..}....}......LL
0570: 20 72 65 73 75 6c 74 20 3d 20 30 3b 0d 0a 09 09   result = 0;....
0580: 66 6f 72 28 69 6e 74 20 63 3d 6d 75 73 74 4c 3b  for(int c=mustL;
0590: 20 63 3c 3d 6d 75 73 74 52 3b 20 2b 2b 63 29 20   c<=mustR; ++c) 
05a0: 69 66 28 63 3c 6d 75 73 74 4e 6f 74 4c 20 7c 7c  if(c<mustNotL ||
05b0: 20 6d 75 73 74 4e 6f 74 52 3c 63 29 0d 0a 09 09   mustNotR<c)....
05c0: 7b 0d 0a 09 09 09 62 6f 6f 6c 20 67 6f 6f 64 20  {.....bool good 
05d0: 3d 20 74 72 75 65 3b 0d 0a 09 09 09 66 6f 72 28  = true;.....for(
05e0: 69 6e 74 20 78 3d 30 3b 20 78 3c 57 20 26 26 20  int x=0; x<W && 
05f0: 67 6f 6f 64 3b 20 2b 2b 78 29 20 7b 0d 0a 09 09  good; ++x) {....
0600: 09 09 69 6e 74 20 6d 79 5f 68 20 3d 20 48 5b 69  ..int my_h = H[i
0610: 5d 20 2d 20 61 62 73 28 78 2d 63 29 3b 0d 0a 09  ] - abs(x-c);...
0620: 09 09 09 69 66 28 28 56 5b 69 5d 5b 78 5d 3d 3d  ...if((V[i][x]==
0630: 27 58 27 29 20 21 3d 20 28 76 69 65 77 5b 78 5d  'X') != (view[x]
0640: 20 3c 20 6d 79 5f 68 29 29 0d 0a 09 09 09 09 09   < my_h)).......
0650: 67 6f 6f 64 20 3d 20 66 61 6c 73 65 3b 0d 0a 09  good = false;...
0660: 09 09 7d 0d 0a 0d 0a 09 09 09 69 66 28 20 67 6f  ..}.......if( go
0670: 6f 64 20 29 20 7b 0d 0a 09 09 09 09 76 65 63 74  od ) {......vect
0680: 6f 72 3c 69 6e 74 3e 20 76 69 65 77 32 28 57 29  or<int> view2(W)
0690: 3b 0d 0a 09 09 09 09 66 6f 72 28 69 6e 74 20 78  ;......for(int x
06a0: 3d 30 3b 20 78 3c 57 3b 20 2b 2b 78 29 20 7b 0d  =0; x<W; ++x) {.
06b0: 0a 09 09 09 09 09 69 6e 74 20 6d 79 5f 68 20 3d  ......int my_h =
06c0: 20 48 5b 69 5d 20 2d 20 61 62 73 28 78 2d 63 29   H[i] - abs(x-c)
06d0: 3b 0d 0a 09 09 09 09 09 76 69 65 77 32 5b 78 5d  ;.......view2[x]
06e0: 20 3d 20 6d 61 78 28 6d 79 5f 68 2c 20 76 69 65   = max(my_h, vie
06f0: 77 5b 78 5d 29 3b 0d 0a 09 09 09 09 7d 0d 0a 09  w[x]);......}...
0700: 09 09 09 72 65 73 75 6c 74 20 2b 3d 20 72 65 63  ...result += rec
0710: 28 57 2c 20 76 69 65 77 32 2c 20 69 2d 31 2c 20  (W, view2, i-1, 
0720: 48 2c 20 56 29 3b 0d 0a 09 09 09 7d 0d 0a 09 09  H, V);.....}....
0730: 7d 0d 0a 09 09 72 65 74 75 72 6e 20 6d 65 6d 6f  }....return memo
0740: 5b 69 5d 5b 76 69 65 77 5d 20 3d 20 69 6e 74 28  [i][view] = int(
0750: 72 65 73 75 6c 74 20 25 20 4d 4f 44 56 41 4c 29  result % MODVAL)
0760: 3b 0d 0a 09 7d 0d 0a 7d 3b 0d 0a 0d 0a 2f 2f 20  ;...}..};....// 
0770: 42 45 47 49 4e 20 43 55 54 20 48 45 52 45 0d 0a  BEGIN CUT HERE..
0780: 23 69 6e 63 6c 75 64 65 20 3c 63 74 69 6d 65 3e  #include <ctime>
0790: 0d 0a 64 6f 75 62 6c 65 20 73 74 61 72 74 5f 74  ..double start_t
07a0: 69 6d 65 3b 20 73 74 72 69 6e 67 20 74 69 6d 65  ime; string time
07b0: 72 28 29 0d 0a 20 7b 20 6f 73 74 72 69 6e 67 73  r().. { ostrings
07c0: 74 72 65 61 6d 20 6f 73 3b 20 6f 73 20 3c 3c 20  tream os; os << 
07d0: 22 20 28 22 20 3c 3c 20 69 6e 74 28 28 63 6c 6f  " (" << int((clo
07e0: 63 6b 28 29 2d 73 74 61 72 74 5f 74 69 6d 65 29  ck()-start_time)
07f0: 2f 43 4c 4f 43 4b 53 5f 50 45 52 5f 53 45 43 2a  /CLOCKS_PER_SEC*
0800: 31 30 30 30 29 20 3c 3c 20 22 20 6d 73 65 63 29  1000) << " msec)
0810: 22 3b 20 72 65 74 75 72 6e 20 6f 73 2e 73 74 72  "; return os.str
0820: 28 29 3b 20 7d 0d 0a 74 65 6d 70 6c 61 74 65 3c  (); }..template<
0830: 74 79 70 65 6e 61 6d 65 20 54 3e 20 6f 73 74 72  typename T> ostr
0840: 65 61 6d 26 20 6f 70 65 72 61 74 6f 72 3c 3c 28  eam& operator<<(
0850: 6f 73 74 72 65 61 6d 26 20 6f 73 2c 20 63 6f 6e  ostream& os, con
0860: 73 74 20 76 65 63 74 6f 72 3c 54 3e 26 20 76 29  st vector<T>& v)
0870: 0d 0a 20 7b 20 6f 73 20 3c 3c 20 22 7b 20 22 3b  .. { os << "{ ";
0880: 0d 0a 20 20 20 66 6f 72 28 74 79 70 65 6e 61 6d  ..   for(typenam
0890: 65 20 76 65 63 74 6f 72 3c 54 3e 3a 3a 63 6f 6e  e vector<T>::con
08a0: 73 74 5f 69 74 65 72 61 74 6f 72 20 69 74 3d 76  st_iterator it=v
08b0: 2e 62 65 67 69 6e 28 29 3b 20 69 74 21 3d 76 2e  .begin(); it!=v.
08c0: 65 6e 64 28 29 3b 20 2b 2b 69 74 29 0d 0a 20 20  end(); ++it)..  
08d0: 20 6f 73 20 3c 3c 20 27 5c 22 27 20 3c 3c 20 2a   os << '\"' << *
08e0: 69 74 20 3c 3c 20 27 5c 22 27 20 3c 3c 20 28 69  it << '\"' << (i
08f0: 74 2b 31 3d 3d 76 2e 65 6e 64 28 29 20 3f 20 22  t+1==v.end() ? "
0900: 22 20 3a 20 22 2c 20 22 29 3b 20 6f 73 20 3c 3c  " : ", "); os <<
0910: 20 22 20 7d 22 3b 20 72 65 74 75 72 6e 20 6f 73   " }"; return os
0920: 3b 20 7d 0d 0a 76 6f 69 64 20 76 65 72 69 66 79  ; }..void verify
0930: 5f 63 61 73 65 28 63 6f 6e 73 74 20 69 6e 74 26  _case(const int&
0940: 20 45 78 70 65 63 74 65 64 2c 20 63 6f 6e 73 74   Expected, const
0950: 20 69 6e 74 26 20 52 65 63 65 69 76 65 64 29 20   int& Received) 
0960: 7b 0d 0a 20 62 6f 6f 6c 20 6f 6b 20 3d 20 28 45  {.. bool ok = (E
0970: 78 70 65 63 74 65 64 20 3d 3d 20 52 65 63 65 69  xpected == Recei
0980: 76 65 64 29 3b 0d 0a 20 69 66 28 6f 6b 29 20 63  ved);.. if(ok) c
0990: 65 72 72 20 3c 3c 20 22 50 41 53 53 45 44 22 20  err << "PASSED" 
09a0: 3c 3c 20 74 69 6d 65 72 28 29 20 3c 3c 20 65 6e  << timer() << en
09b0: 64 6c 3b 20 20 65 6c 73 65 20 7b 20 63 65 72 72  dl;  else { cerr
09c0: 20 3c 3c 20 22 46 41 49 4c 45 44 22 20 3c 3c 20   << "FAILED" << 
09d0: 74 69 6d 65 72 28 29 20 3c 3c 20 65 6e 64 6c 3b  timer() << endl;
09e0: 0d 0a 20 63 65 72 72 20 3c 3c 20 22 5c 74 6f 3a  .. cerr << "\to:
09f0: 20 5c 22 22 20 3c 3c 20 45 78 70 65 63 74 65 64   \"" << Expected
0a00: 20 3c 3c 20 27 5c 22 27 20 3c 3c 20 65 6e 64 6c   << '\"' << endl
0a10: 20 3c 3c 20 22 5c 74 78 3a 20 5c 22 22 20 3c 3c   << "\tx: \"" <<
0a20: 20 52 65 63 65 69 76 65 64 20 3c 3c 20 27 5c 22   Received << '\"
0a30: 27 20 3c 3c 20 65 6e 64 6c 3b 20 7d 20 7d 0d 0a  ' << endl; } }..
0a40: 23 64 65 66 69 6e 65 20 43 41 53 45 28 4e 29 20  #define CASE(N) 
0a50: 7b 63 65 72 72 20 3c 3c 20 22 54 65 73 74 20 43  {cerr << "Test C
0a60: 61 73 65 20 23 22 20 3c 3c 20 4e 20 3c 3c 20 22  ase #" << N << "
0a70: 2e 2e 2e 22 20 3c 3c 20 66 6c 75 73 68 3b 20 73  ..." << flush; s
0a80: 74 61 72 74 5f 74 69 6d 65 3d 63 6c 6f 63 6b 28  tart_time=clock(
0a90: 29 3b 0d 0a 23 64 65 66 69 6e 65 20 45 4e 44 09  );..#define END.
0aa0: 20 76 65 72 69 66 79 5f 63 61 73 65 28 5f 2c 20   verify_case(_, 
0ab0: 4d 6f 75 6e 74 61 69 6e 73 28 29 2e 63 6f 75 6e  Mountains().coun
0ac0: 74 50 6c 61 63 65 6d 65 6e 74 73 28 68 65 69 67  tPlacements(heig
0ad0: 68 74 73 2c 20 76 69 73 69 62 69 6c 69 74 79 29  hts, visibility)
0ae0: 29 3b 7d 0d 0a 69 6e 74 20 6d 61 69 6e 28 29 7b  );}..int main(){
0af0: 0d 0a 0d 0a 43 41 53 45 28 30 29 0d 0a 09 69 6e  ....CASE(0)...in
0b00: 74 20 68 65 69 67 68 74 73 5f 5b 5d 20 3d 20 7b  t heights_[] = {
0b10: 32 2c 20 33 2c 20 32 7d 3b 0d 0a 09 20 20 76 65  2, 3, 2};...  ve
0b20: 63 74 6f 72 20 3c 69 6e 74 3e 20 68 65 69 67 68  ctor <int> heigh
0b30: 74 73 28 68 65 69 67 68 74 73 5f 2c 20 68 65 69  ts(heights_, hei
0b40: 67 68 74 73 5f 2b 73 69 7a 65 6f 66 28 68 65 69  ghts_+sizeof(hei
0b50: 67 68 74 73 5f 29 2f 73 69 7a 65 6f 66 28 2a 68  ghts_)/sizeof(*h
0b60: 65 69 67 68 74 73 5f 29 29 3b 20 0d 0a 09 73 74  eights_)); ...st
0b70: 72 69 6e 67 20 76 69 73 69 62 69 6c 69 74 79 5f  ring visibility_
0b80: 5b 5d 20 3d 20 7b 22 2d 2d 2d 2d 2d 2d 22 2c 0d  [] = {"------",.
0b90: 0a 20 22 58 58 58 58 2d 2d 22 2c 0d 0a 20 22 2d  . "XXXX--",.. "-
0ba0: 2d 2d 58 58 58 22 7d 3b 0d 0a 09 20 20 76 65 63  --XXX"};...  vec
0bb0: 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 76 69 73  tor <string> vis
0bc0: 69 62 69 6c 69 74 79 28 76 69 73 69 62 69 6c 69  ibility(visibili
0bd0: 74 79 5f 2c 20 76 69 73 69 62 69 6c 69 74 79 5f  ty_, visibility_
0be0: 2b 73 69 7a 65 6f 66 28 76 69 73 69 62 69 6c 69  +sizeof(visibili
0bf0: 74 79 5f 29 2f 73 69 7a 65 6f 66 28 2a 76 69 73  ty_)/sizeof(*vis
0c00: 69 62 69 6c 69 74 79 5f 29 29 3b 20 0d 0a 09 69  ibility_)); ...i
0c10: 6e 74 20 5f 20 3d 20 34 3b 20 0d 0a 45 4e 44 0d  nt _ = 4; ..END.
0c20: 0a 43 41 53 45 28 31 29 0d 0a 09 69 6e 74 20 68  .CASE(1)...int h
0c30: 65 69 67 68 74 73 5f 5b 5d 20 3d 20 7b 34 2c 20  eights_[] = {4, 
0c40: 33 2c 20 34 7d 3b 0d 0a 09 20 20 76 65 63 74 6f  3, 4};...  vecto
0c50: 72 20 3c 69 6e 74 3e 20 68 65 69 67 68 74 73 28  r <int> heights(
0c60: 68 65 69 67 68 74 73 5f 2c 20 68 65 69 67 68 74  heights_, height
0c70: 73 5f 2b 73 69 7a 65 6f 66 28 68 65 69 67 68 74  s_+sizeof(height
0c80: 73 5f 29 2f 73 69 7a 65 6f 66 28 2a 68 65 69 67  s_)/sizeof(*heig
0c90: 68 74 73 5f 29 29 3b 20 0d 0a 09 73 74 72 69 6e  hts_)); ...strin
0ca0: 67 20 76 69 73 69 62 69 6c 69 74 79 5f 5b 5d 20  g visibility_[] 
0cb0: 3d 20 7b 22 58 58 58 58 58 2d 2d 2d 2d 2d 2d 2d  = {"XXXXX-------
0cc0: 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d  -",.. "---------
0cd0: 2d 58 58 58 22 2c 0d 0a 20 22 2d 2d 2d 2d 58 58  -XXX",.. "----XX
0ce0: 58 58 58 58 58 2d 2d 22 7d 3b 0d 0a 09 20 20 76  XXXXX--"};...  v
0cf0: 65 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 76  ector <string> v
0d00: 69 73 69 62 69 6c 69 74 79 28 76 69 73 69 62 69  isibility(visibi
0d10: 6c 69 74 79 5f 2c 20 76 69 73 69 62 69 6c 69 74  lity_, visibilit
0d20: 79 5f 2b 73 69 7a 65 6f 66 28 76 69 73 69 62 69  y_+sizeof(visibi
0d30: 6c 69 74 79 5f 29 2f 73 69 7a 65 6f 66 28 2a 76  lity_)/sizeof(*v
0d40: 69 73 69 62 69 6c 69 74 79 5f 29 29 3b 20 0d 0a  isibility_)); ..
0d50: 09 69 6e 74 20 5f 20 3d 20 34 3b 20 0d 0a 45 4e  .int _ = 4; ..EN
0d60: 44 0d 0a 43 41 53 45 28 32 29 0d 0a 09 69 6e 74  D..CASE(2)...int
0d70: 20 68 65 69 67 68 74 73 5f 5b 5d 20 3d 20 7b 31   heights_[] = {1
0d80: 33 2c 20 32 2c 20 33 2c 20 32 7d 3b 0d 0a 09 20  3, 2, 3, 2};... 
0d90: 20 76 65 63 74 6f 72 20 3c 69 6e 74 3e 20 68 65   vector <int> he
0da0: 69 67 68 74 73 28 68 65 69 67 68 74 73 5f 2c 20  ights(heights_, 
0db0: 68 65 69 67 68 74 73 5f 2b 73 69 7a 65 6f 66 28  heights_+sizeof(
0dc0: 68 65 69 67 68 74 73 5f 29 2f 73 69 7a 65 6f 66  heights_)/sizeof
0dd0: 28 2a 68 65 69 67 68 74 73 5f 29 29 3b 20 0d 0a  (*heights_)); ..
0de0: 09 73 74 72 69 6e 67 20 76 69 73 69 62 69 6c 69  .string visibili
0df0: 74 79 5f 5b 5d 20 3d 20 7b 22 58 58 58 58 58 58  ty_[] = {"XXXXXX
0e00: 58 58 58 22 2c 0d 0a 20 22 2d 58 58 58 2d 2d 2d  XXX",.. "-XXX---
0e10: 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 58 58 58 58  --",.. "----XXXX
0e20: 58 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 58 58 58 2d  X",.. "-----XXX-
0e30: 22 7d 3b 0d 0a 09 20 20 76 65 63 74 6f 72 20 3c  "};...  vector <
0e40: 73 74 72 69 6e 67 3e 20 76 69 73 69 62 69 6c 69  string> visibili
0e50: 74 79 28 76 69 73 69 62 69 6c 69 74 79 5f 2c 20  ty(visibility_, 
0e60: 76 69 73 69 62 69 6c 69 74 79 5f 2b 73 69 7a 65  visibility_+size
0e70: 6f 66 28 76 69 73 69 62 69 6c 69 74 79 5f 29 2f  of(visibility_)/
0e80: 73 69 7a 65 6f 66 28 2a 76 69 73 69 62 69 6c 69  sizeof(*visibili
0e90: 74 79 5f 29 29 3b 20 0d 0a 09 69 6e 74 20 5f 20  ty_)); ...int _ 
0ea0: 3d 20 39 3b 20 0d 0a 45 4e 44 0d 0a 43 41 53 45  = 9; ..END..CASE
0eb0: 28 33 29 0d 0a 09 69 6e 74 20 68 65 69 67 68 74  (3)...int height
0ec0: 73 5f 5b 5d 20 3d 20 7b 38 2c 20 32 2c 20 39 2c  s_[] = {8, 2, 9,
0ed0: 20 33 2c 20 31 30 7d 3b 0d 0a 09 20 20 76 65 63   3, 10};...  vec
0ee0: 74 6f 72 20 3c 69 6e 74 3e 20 68 65 69 67 68 74  tor <int> height
0ef0: 73 28 68 65 69 67 68 74 73 5f 2c 20 68 65 69 67  s(heights_, heig
0f00: 68 74 73 5f 2b 73 69 7a 65 6f 66 28 68 65 69 67  hts_+sizeof(heig
0f10: 68 74 73 5f 29 2f 73 69 7a 65 6f 66 28 2a 68 65  hts_)/sizeof(*he
0f20: 69 67 68 74 73 5f 29 29 3b 20 0d 0a 09 73 74 72  ights_)); ...str
0f30: 69 6e 67 20 76 69 73 69 62 69 6c 69 74 79 5f 5b  ing visibility_[
0f40: 5d 20 3d 20 7b 22 58 2d 2d 2d 2d 2d 2d 22 2c 0d  ] = {"X------",.
0f50: 0a 20 22 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22  . "-------",.. "
0f60: 2d 2d 2d 2d 2d 2d 58 22 2c 0d 0a 20 22 2d 2d 2d  ------X",.. "---
0f70: 2d 2d 2d 2d 22 2c 0d 0a 20 22 58 58 58 58 58 58  ----",.. "XXXXXX
0f80: 58 22 7d 3b 0d 0a 09 20 20 76 65 63 74 6f 72 20  X"};...  vector 
0f90: 3c 73 74 72 69 6e 67 3e 20 76 69 73 69 62 69 6c  <string> visibil
0fa0: 69 74 79 28 76 69 73 69 62 69 6c 69 74 79 5f 2c  ity(visibility_,
0fb0: 20 76 69 73 69 62 69 6c 69 74 79 5f 2b 73 69 7a   visibility_+siz
0fc0: 65 6f 66 28 76 69 73 69 62 69 6c 69 74 79 5f 29  eof(visibility_)
0fd0: 2f 73 69 7a 65 6f 66 28 2a 76 69 73 69 62 69 6c  /sizeof(*visibil
0fe0: 69 74 79 5f 29 29 3b 20 0d 0a 09 69 6e 74 20 5f  ity_)); ...int _
0ff0: 20 3d 20 39 38 3b 20 0d 0a 45 4e 44 0d 0a 43 41   = 98; ..END..CA
1000: 53 45 28 34 29 0d 0a 09 69 6e 74 20 68 65 69 67  SE(4)...int heig
1010: 68 74 73 5f 5b 5d 20 3d 20 7b 32 30 2c 20 32 30  hts_[] = {20, 20
1020: 2c 20 32 30 2c 20 32 30 2c 20 32 30 2c 20 32 30  , 20, 20, 20, 20
1030: 2c 20 34 35 2c 20 35 30 2c 20 34 39 2c 20 35 30  , 45, 50, 49, 50
1040: 7d 3b 0d 0a 09 20 20 76 65 63 74 6f 72 20 3c 69  };...  vector <i
1050: 6e 74 3e 20 68 65 69 67 68 74 73 28 68 65 69 67  nt> heights(heig
1060: 68 74 73 5f 2c 20 68 65 69 67 68 74 73 5f 2b 73  hts_, heights_+s
1070: 69 7a 65 6f 66 28 68 65 69 67 68 74 73 5f 29 2f  izeof(heights_)/
1080: 73 69 7a 65 6f 66 28 2a 68 65 69 67 68 74 73 5f  sizeof(*heights_
1090: 29 29 3b 20 0d 0a 09 73 74 72 69 6e 67 20 76 69  )); ...string vi
10a0: 73 69 62 69 6c 69 74 79 5f 5b 5d 20 3d 20 7b 22  sibility_[] = {"
10b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10c0: 2d 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d  ---",.. "-------
10d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a  ------------",..
10e0: 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   "--------------
10f0: 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d  -----",.. "-----
1100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c  --------------",
1110: 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .. "------------
1120: 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d  -------",.. "---
1130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1140: 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ",.. "----------
1150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d  ---------",.. "-
1160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 58 58 58 58 58  -----------XXXXX
1170: 58 58 22 2c 0d 0a 20 22 58 58 58 58 58 58 58 2d  XX",.. "XXXXXXX-
1180: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20  -----------",.. 
1190: 22 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58  "XXXXXXXXXXXXXXX
11a0: 58 58 58 58 22 7d 0d 0a 3b 0d 0a 09 20 20 76 65  XXXX"}..;...  ve
11b0: 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 76 69  ctor <string> vi
11c0: 73 69 62 69 6c 69 74 79 28 76 69 73 69 62 69 6c  sibility(visibil
11d0: 69 74 79 5f 2c 20 76 69 73 69 62 69 6c 69 74 79  ity_, visibility
11e0: 5f 2b 73 69 7a 65 6f 66 28 76 69 73 69 62 69 6c  _+sizeof(visibil
11f0: 69 74 79 5f 29 2f 73 69 7a 65 6f 66 28 2a 76 69  ity_)/sizeof(*vi
1200: 73 69 62 69 6c 69 74 79 5f 29 29 3b 20 0d 0a 09  sibility_)); ...
1210: 69 6e 74 20 5f 20 3d 20 39 37 33 37 32 36 36 39  int _ = 97372669
1220: 31 3b 20 0d 0a 45 4e 44 0d 0a 43 41 53 45 28 35  1; ..END..CASE(5
1230: 29 0d 0a 09 69 6e 74 20 68 65 69 67 68 74 73 5f  )...int heights_
1240: 5b 5d 20 3d 20 7b 32 30 2c 20 32 30 2c 20 32 30  [] = {20, 20, 20
1250: 2c 20 32 30 2c 20 32 30 2c 20 32 30 2c 20 34 35  , 20, 20, 20, 45
1260: 2c 20 35 30 2c 20 34 39 2c 20 35 30 7d 3b 0d 0a  , 50, 49, 50};..
1270: 09 20 20 76 65 63 74 6f 72 20 3c 69 6e 74 3e 20  .  vector <int> 
1280: 68 65 69 67 68 74 73 28 68 65 69 67 68 74 73 5f  heights(heights_
1290: 2c 20 68 65 69 67 68 74 73 5f 2b 73 69 7a 65 6f  , heights_+sizeo
12a0: 66 28 68 65 69 67 68 74 73 5f 29 2f 73 69 7a 65  f(heights_)/size
12b0: 6f 66 28 2a 68 65 69 67 68 74 73 5f 29 29 3b 20  of(*heights_)); 
12c0: 0d 0a 09 73 74 72 69 6e 67 20 76 69 73 69 62 69  ...string visibi
12d0: 6c 69 74 79 5f 5b 5d 20 3d 20 7b 22 2d 2d 2d 2d  lity_[] = {"----
12e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d  -------------",.
1310: 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . "-------------
1320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1330: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1340: 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d  ----",.. "------
1350: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1360: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1370: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20  -----------",.. 
1380: 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  "---------------
1390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13b0: 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d  --",.. "--------
13c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d  ---------",.. "-
13f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1410: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1420: 22 2c 0d 0a 20 22 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ",.. "----------
1430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1450: 2d 2d 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 2d 2d 2d  -------",.. "---
1460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 58 58 58 58 58 58 58  ---------XXXXXXX
1470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 22 2c  --------------",
1490: 0d 0a 20 22 58 58 58 58 58 58 58 2d 2d 2d 2d 2d  .. "XXXXXXX-----
14a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14c0: 2d 2d 2d 2d 2d 22 2c 0d 0a 20 22 58 58 58 58 58  -----",.. "XXXXX
14d0: 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58  XXXXXXXXXXXXXXXX
14e0: 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58  XXXXXXXXXXXXXXXX
14f0: 58 58 58 58 58 58 58 58 58 58 58 58 22 7d 0d 0a  XXXXXXXXXXXX"}..
1500: 3b 0d 0a 09 20 20 76 65 63 74 6f 72 20 3c 73 74  ;...  vector <st
1510: 72 69 6e 67 3e 20 76 69 73 69 62 69 6c 69 74 79  ring> visibility
1520: 28 76 69 73 69 62 69 6c 69 74 79 5f 2c 20 76 69  (visibility_, vi
1530: 73 69 62 69 6c 69 74 79 5f 2b 73 69 7a 65 6f 66  sibility_+sizeof
1540: 28 76 69 73 69 62 69 6c 69 74 79 5f 29 2f 73 69  (visibility_)/si
1550: 7a 65 6f 66 28 2a 76 69 73 69 62 69 6c 69 74 79  zeof(*visibility
1560: 5f 29 29 3b 20 0d 0a 09 69 6e 74 20 5f 20 3d 20  _)); ...int _ = 
1570: 2d 31 3b 20 0d 0a 45 4e 44 0d 0a 7d 0d 0a 2f 2f  -1; ..END..}..//
1580: 20 45 4e 44 20 43 55 54 20 48 45 52 45 0d 0a      END CUT HERE..