Hex Artifact Content
Not logged in

Artifact 4e5b4d79ecf48d8e3351fc54e839912ecf9a021d:


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 23 69 6e 63 6c 75 64 65 20  sert>..#include 
0140: 3c 63 73 74 72 69 6e 67 3e 0d 0a 75 73 69 6e 67  <cstring>..using
0150: 20 6e 61 6d 65 73 70 61 63 65 20 73 74 64 3b 0d   namespace std;.
0160: 0a 74 79 70 65 64 65 66 20 6c 6f 6e 67 20 6c 6f  .typedef long lo
0170: 6e 67 20 4c 4c 3b 0d 0a 74 79 70 65 64 65 66 20  ng LL;..typedef 
0180: 63 6f 6d 70 6c 65 78 3c 64 6f 75 62 6c 65 3e 20  complex<double> 
0190: 43 4d 50 3b 0d 0a 0d 0a 63 6c 61 73 73 20 43 75  CMP;....class Cu
01a0: 62 65 53 74 69 63 6b 65 72 73 20 7b 20 70 75 62  beStickers { pub
01b0: 6c 69 63 3a 0d 0a 09 73 74 72 69 6e 67 20 69 73  lic:...string is
01c0: 50 6f 73 73 69 62 6c 65 28 76 65 63 74 6f 72 20  Possible(vector 
01d0: 3c 73 74 72 69 6e 67 3e 20 73 74 69 63 6b 65 72  <string> sticker
01e0: 29 20 0d 0a 09 7b 0d 0a 09 09 6d 61 70 3c 73 74  ) ...{....map<st
01f0: 72 69 6e 67 2c 69 6e 74 3e 20 6d 70 3b 0d 0a 09  ring,int> mp;...
0200: 09 66 6f 72 28 69 6e 74 20 69 3d 30 3b 20 69 3c  .for(int i=0; i<
0210: 73 74 69 63 6b 65 72 2e 73 69 7a 65 28 29 3b 20  sticker.size(); 
0220: 2b 2b 69 29 0d 0a 09 09 09 6d 70 5b 73 74 69 63  ++i).....mp[stic
0230: 6b 65 72 5b 69 5d 5d 2b 2b 3b 0d 0a 09 09 69 6e  ker[i]]++;....in
0240: 74 20 63 6e 74 20 3d 20 30 3b 0d 0a 09 09 66 6f  t cnt = 0;....fo
0250: 72 28 6d 61 70 3c 73 74 72 69 6e 67 2c 69 6e 74  r(map<string,int
0260: 3e 3a 3a 69 74 65 72 61 74 6f 72 20 69 74 3d 6d  >::iterator it=m
0270: 70 2e 62 65 67 69 6e 28 29 3b 20 69 74 21 3d 6d  p.begin(); it!=m
0280: 70 2e 65 6e 64 28 29 3b 20 2b 2b 69 74 29 0d 0a  p.end(); ++it)..
0290: 09 09 09 63 6e 74 20 2b 3d 20 6d 69 6e 28 32 2c  ...cnt += min(2,
02a0: 20 69 74 2d 3e 73 65 63 6f 6e 64 29 3b 0d 0a 09   it->second);...
02b0: 09 72 65 74 75 72 6e 20 63 6e 74 3e 3d 36 20 3f  .return cnt>=6 ?
02c0: 20 22 59 45 53 22 20 3a 20 22 4e 4f 22 3b 0d 0a   "YES" : "NO";..
02d0: 09 7d 0d 0a 7d 3b 0d 0a 0d 0a 2f 2f 20 42 45 47  .}..};....// BEG
02e0: 49 4e 20 43 55 54 20 48 45 52 45 0d 0a 23 69 6e  IN CUT HERE..#in
02f0: 63 6c 75 64 65 20 3c 63 74 69 6d 65 3e 0d 0a 64  clude <ctime>..d
0300: 6f 75 62 6c 65 20 73 74 61 72 74 5f 74 69 6d 65  ouble start_time
0310: 3b 20 73 74 72 69 6e 67 20 74 69 6d 65 72 28 29  ; string timer()
0320: 0d 0a 20 7b 20 6f 73 74 72 69 6e 67 73 74 72 65  .. { ostringstre
0330: 61 6d 20 6f 73 3b 20 6f 73 20 3c 3c 20 22 20 28  am os; os << " (
0340: 22 20 3c 3c 20 69 6e 74 28 28 63 6c 6f 63 6b 28  " << int((clock(
0350: 29 2d 73 74 61 72 74 5f 74 69 6d 65 29 2f 43 4c  )-start_time)/CL
0360: 4f 43 4b 53 5f 50 45 52 5f 53 45 43 2a 31 30 30  OCKS_PER_SEC*100
0370: 30 29 20 3c 3c 20 22 20 6d 73 65 63 29 22 3b 20  0) << " msec)"; 
0380: 72 65 74 75 72 6e 20 6f 73 2e 73 74 72 28 29 3b  return os.str();
0390: 20 7d 0d 0a 74 65 6d 70 6c 61 74 65 3c 74 79 70   }..template<typ
03a0: 65 6e 61 6d 65 20 54 3e 20 6f 73 74 72 65 61 6d  ename T> ostream
03b0: 26 20 6f 70 65 72 61 74 6f 72 3c 3c 28 6f 73 74  & operator<<(ost
03c0: 72 65 61 6d 26 20 6f 73 2c 20 63 6f 6e 73 74 20  ream& os, const 
03d0: 76 65 63 74 6f 72 3c 54 3e 26 20 76 29 0d 0a 20  vector<T>& v).. 
03e0: 7b 20 6f 73 20 3c 3c 20 22 7b 20 22 3b 0d 0a 20  { os << "{ ";.. 
03f0: 20 20 66 6f 72 28 74 79 70 65 6e 61 6d 65 20 76    for(typename v
0400: 65 63 74 6f 72 3c 54 3e 3a 3a 63 6f 6e 73 74 5f  ector<T>::const_
0410: 69 74 65 72 61 74 6f 72 20 69 74 3d 76 2e 62 65  iterator it=v.be
0420: 67 69 6e 28 29 3b 20 69 74 21 3d 76 2e 65 6e 64  gin(); it!=v.end
0430: 28 29 3b 20 2b 2b 69 74 29 0d 0a 20 20 20 6f 73  (); ++it)..   os
0440: 20 3c 3c 20 27 5c 22 27 20 3c 3c 20 2a 69 74 20   << '\"' << *it 
0450: 3c 3c 20 27 5c 22 27 20 3c 3c 20 28 69 74 2b 31  << '\"' << (it+1
0460: 3d 3d 76 2e 65 6e 64 28 29 20 3f 20 22 22 20 3a  ==v.end() ? "" :
0470: 20 22 2c 20 22 29 3b 20 6f 73 20 3c 3c 20 22 20   ", "); os << " 
0480: 7d 22 3b 20 72 65 74 75 72 6e 20 6f 73 3b 20 7d  }"; return os; }
0490: 0d 0a 76 6f 69 64 20 76 65 72 69 66 79 5f 63 61  ..void verify_ca
04a0: 73 65 28 63 6f 6e 73 74 20 73 74 72 69 6e 67 26  se(const string&
04b0: 20 45 78 70 65 63 74 65 64 2c 20 63 6f 6e 73 74   Expected, const
04c0: 20 73 74 72 69 6e 67 26 20 52 65 63 65 69 76 65   string& Receive
04d0: 64 29 20 7b 0d 0a 20 62 6f 6f 6c 20 6f 6b 20 3d  d) {.. bool ok =
04e0: 20 28 45 78 70 65 63 74 65 64 20 3d 3d 20 52 65   (Expected == Re
04f0: 63 65 69 76 65 64 29 3b 0d 0a 20 69 66 28 6f 6b  ceived);.. if(ok
0500: 29 20 63 65 72 72 20 3c 3c 20 22 50 41 53 53 45  ) cerr << "PASSE
0510: 44 22 20 3c 3c 20 74 69 6d 65 72 28 29 20 3c 3c  D" << timer() <<
0520: 20 65 6e 64 6c 3b 20 20 65 6c 73 65 20 7b 20 63   endl;  else { c
0530: 65 72 72 20 3c 3c 20 22 46 41 49 4c 45 44 22 20  err << "FAILED" 
0540: 3c 3c 20 74 69 6d 65 72 28 29 20 3c 3c 20 65 6e  << timer() << en
0550: 64 6c 3b 0d 0a 20 63 65 72 72 20 3c 3c 20 22 5c  dl;.. cerr << "\
0560: 74 6f 3a 20 5c 22 22 20 3c 3c 20 45 78 70 65 63  to: \"" << Expec
0570: 74 65 64 20 3c 3c 20 27 5c 22 27 20 3c 3c 20 65  ted << '\"' << e
0580: 6e 64 6c 20 3c 3c 20 22 5c 74 78 3a 20 5c 22 22  ndl << "\tx: \""
0590: 20 3c 3c 20 52 65 63 65 69 76 65 64 20 3c 3c 20   << Received << 
05a0: 27 5c 22 27 20 3c 3c 20 65 6e 64 6c 3b 20 7d 20  '\"' << endl; } 
05b0: 7d 0d 0a 23 64 65 66 69 6e 65 20 43 41 53 45 28  }..#define CASE(
05c0: 4e 29 20 7b 63 65 72 72 20 3c 3c 20 22 54 65 73  N) {cerr << "Tes
05d0: 74 20 43 61 73 65 20 23 22 20 3c 3c 20 4e 20 3c  t Case #" << N <
05e0: 3c 20 22 2e 2e 2e 22 20 3c 3c 20 66 6c 75 73 68  < "..." << flush
05f0: 3b 20 73 74 61 72 74 5f 74 69 6d 65 3d 63 6c 6f  ; start_time=clo
0600: 63 6b 28 29 3b 0d 0a 23 64 65 66 69 6e 65 20 45  ck();..#define E
0610: 4e 44 09 20 76 65 72 69 66 79 5f 63 61 73 65 28  ND. verify_case(
0620: 5f 2c 20 43 75 62 65 53 74 69 63 6b 65 72 73 28  _, CubeStickers(
0630: 29 2e 69 73 50 6f 73 73 69 62 6c 65 28 73 74 69  ).isPossible(sti
0640: 63 6b 65 72 29 29 3b 7d 0d 0a 69 6e 74 20 6d 61  cker));}..int ma
0650: 69 6e 28 29 7b 0d 0a 0d 0a 43 41 53 45 28 30 29  in(){....CASE(0)
0660: 0d 0a 09 73 74 72 69 6e 67 20 73 74 69 63 6b 65  ...string sticke
0670: 72 5f 5b 5d 20 3d 20 7b 22 63 79 61 6e 22 2c 22  r_[] = {"cyan","
0680: 6d 61 67 65 6e 74 61 22 2c 22 79 65 6c 6c 6f 77  magenta","yellow
0690: 22 2c 22 70 75 72 70 6c 65 22 2c 22 62 6c 61 63  ","purple","blac
06a0: 6b 22 2c 22 77 68 69 74 65 22 2c 22 70 75 72 70  k","white","purp
06b0: 6c 65 22 7d 3b 0d 0a 09 20 20 76 65 63 74 6f 72  le"};...  vector
06c0: 20 3c 73 74 72 69 6e 67 3e 20 73 74 69 63 6b 65   <string> sticke
06d0: 72 28 73 74 69 63 6b 65 72 5f 2c 20 73 74 69 63  r(sticker_, stic
06e0: 6b 65 72 5f 2b 73 69 7a 65 6f 66 28 73 74 69 63  ker_+sizeof(stic
06f0: 6b 65 72 5f 29 2f 73 69 7a 65 6f 66 28 2a 73 74  ker_)/sizeof(*st
0700: 69 63 6b 65 72 5f 29 29 3b 20 0d 0a 09 73 74 72  icker_)); ...str
0710: 69 6e 67 20 5f 20 3d 20 22 59 45 53 22 3b 20 0d  ing _ = "YES"; .
0720: 0a 45 4e 44 0d 0a 43 41 53 45 28 31 29 0d 0a 09  .END..CASE(1)...
0730: 73 74 72 69 6e 67 20 73 74 69 63 6b 65 72 5f 5b  string sticker_[
0740: 5d 20 3d 20 7b 22 62 6c 75 65 22 2c 22 62 6c 75  ] = {"blue","blu
0750: 65 22 2c 22 62 6c 75 65 22 2c 22 62 6c 75 65 22  e","blue","blue"
0760: 2c 22 62 6c 75 65 22 2c 22 62 6c 75 65 22 2c 22  ,"blue","blue","
0770: 62 6c 75 65 22 2c 22 62 6c 75 65 22 2c 22 62 6c  blue","blue","bl
0780: 75 65 22 2c 22 62 6c 75 65 22 7d 3b 0d 0a 09 20  ue","blue"};... 
0790: 20 76 65 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e   vector <string>
07a0: 20 73 74 69 63 6b 65 72 28 73 74 69 63 6b 65 72   sticker(sticker
07b0: 5f 2c 20 73 74 69 63 6b 65 72 5f 2b 73 69 7a 65  _, sticker_+size
07c0: 6f 66 28 73 74 69 63 6b 65 72 5f 29 2f 73 69 7a  of(sticker_)/siz
07d0: 65 6f 66 28 2a 73 74 69 63 6b 65 72 5f 29 29 3b  eof(*sticker_));
07e0: 20 0d 0a 09 73 74 72 69 6e 67 20 5f 20 3d 20 22   ...string _ = "
07f0: 4e 4f 22 3b 20 0d 0a 45 4e 44 0d 0a 43 41 53 45  NO"; ..END..CASE
0800: 28 32 29 0d 0a 09 73 74 72 69 6e 67 20 73 74 69  (2)...string sti
0810: 63 6b 65 72 5f 5b 5d 20 3d 20 7b 22 72 65 64 22  cker_[] = {"red"
0820: 2c 22 79 65 6c 6c 6f 77 22 2c 22 62 6c 75 65 22  ,"yellow","blue"
0830: 2c 22 72 65 64 22 2c 22 79 65 6c 6c 6f 77 22 2c  ,"red","yellow",
0840: 22 62 6c 75 65 22 2c 22 72 65 64 22 2c 22 79 65  "blue","red","ye
0850: 6c 6c 6f 77 22 2c 22 62 6c 75 65 22 7d 3b 0d 0a  llow","blue"};..
0860: 09 20 20 76 65 63 74 6f 72 20 3c 73 74 72 69 6e  .  vector <strin
0870: 67 3e 20 73 74 69 63 6b 65 72 28 73 74 69 63 6b  g> sticker(stick
0880: 65 72 5f 2c 20 73 74 69 63 6b 65 72 5f 2b 73 69  er_, sticker_+si
0890: 7a 65 6f 66 28 73 74 69 63 6b 65 72 5f 29 2f 73  zeof(sticker_)/s
08a0: 69 7a 65 6f 66 28 2a 73 74 69 63 6b 65 72 5f 29  izeof(*sticker_)
08b0: 29 3b 20 0d 0a 09 73 74 72 69 6e 67 20 5f 20 3d  ); ...string _ =
08c0: 20 22 59 45 53 22 3b 20 0d 0a 45 4e 44 0d 0a 43   "YES"; ..END..C
08d0: 41 53 45 28 33 29 0d 0a 09 73 74 72 69 6e 67 20  ASE(3)...string 
08e0: 73 74 69 63 6b 65 72 5f 5b 5d 20 3d 20 7b 22 70  sticker_[] = {"p
08f0: 75 72 70 6c 65 22 2c 22 6f 72 61 6e 67 65 22 2c  urple","orange",
0900: 22 6f 72 61 6e 67 65 22 2c 22 70 75 72 70 6c 65  "orange","purple
0910: 22 2c 22 62 6c 61 63 6b 22 2c 22 6f 72 61 6e 67  ","black","orang
0920: 65 22 2c 22 70 75 72 70 6c 65 22 7d 3b 0d 0a 09  e","purple"};...
0930: 20 20 76 65 63 74 6f 72 20 3c 73 74 72 69 6e 67    vector <string
0940: 3e 20 73 74 69 63 6b 65 72 28 73 74 69 63 6b 65  > sticker(sticke
0950: 72 5f 2c 20 73 74 69 63 6b 65 72 5f 2b 73 69 7a  r_, sticker_+siz
0960: 65 6f 66 28 73 74 69 63 6b 65 72 5f 29 2f 73 69  eof(sticker_)/si
0970: 7a 65 6f 66 28 2a 73 74 69 63 6b 65 72 5f 29 29  zeof(*sticker_))
0980: 3b 20 0d 0a 09 73 74 72 69 6e 67 20 5f 20 3d 20  ; ...string _ = 
0990: 22 4e 4f 22 3b 20 0d 0a 45 4e 44 0d 0a 43 41 53  "NO"; ..END..CAS
09a0: 45 28 34 29 0d 0a 09 73 74 72 69 6e 67 20 73 74  E(4)...string st
09b0: 69 63 6b 65 72 5f 5b 5d 20 3d 20 7b 22 77 68 69  icker_[] = {"whi
09c0: 74 65 22 2c 22 67 72 61 79 22 2c 22 67 72 65 65  te","gray","gree
09d0: 6e 22 2c 22 62 6c 75 65 22 2c 22 79 65 6c 6c 6f  n","blue","yello
09e0: 77 22 2c 22 72 65 64 22 2c 22 74 61 72 67 65 74  w","red","target
09f0: 22 2c 22 61 64 6d 69 6e 22 7d 3b 0d 0a 09 20 20  ","admin"};...  
0a00: 76 65 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20  vector <string> 
0a10: 73 74 69 63 6b 65 72 28 73 74 69 63 6b 65 72 5f  sticker(sticker_
0a20: 2c 20 73 74 69 63 6b 65 72 5f 2b 73 69 7a 65 6f  , sticker_+sizeo
0a30: 66 28 73 74 69 63 6b 65 72 5f 29 2f 73 69 7a 65  f(sticker_)/size
0a40: 6f 66 28 2a 73 74 69 63 6b 65 72 5f 29 29 3b 20  of(*sticker_)); 
0a50: 0d 0a 09 73 74 72 69 6e 67 20 5f 20 3d 20 22 59  ...string _ = "Y
0a60: 45 53 22 3b 20 0d 0a 45 4e 44 0d 0a 2f 2a 0d 0a  ES"; ..END../*..
0a70: 43 41 53 45 28 35 29 0d 0a 09 73 74 72 69 6e 67  CASE(5)...string
0a80: 20 73 74 69 63 6b 65 72 5f 5b 5d 20 3d 20 3b 0d   sticker_[] = ;.
0a90: 0a 09 20 20 76 65 63 74 6f 72 20 3c 73 74 72 69  ..  vector <stri
0aa0: 6e 67 3e 20 73 74 69 63 6b 65 72 28 73 74 69 63  ng> sticker(stic
0ab0: 6b 65 72 5f 2c 20 73 74 69 63 6b 65 72 5f 2b 73  ker_, sticker_+s
0ac0: 69 7a 65 6f 66 28 73 74 69 63 6b 65 72 5f 29 2f  izeof(sticker_)/
0ad0: 73 69 7a 65 6f 66 28 2a 73 74 69 63 6b 65 72 5f  sizeof(*sticker_
0ae0: 29 29 3b 20 0d 0a 09 73 74 72 69 6e 67 20 5f 20  )); ...string _ 
0af0: 3d 20 3b 20 0d 0a 45 4e 44 0d 0a 43 41 53 45 28  = ; ..END..CASE(
0b00: 36 29 0d 0a 09 73 74 72 69 6e 67 20 73 74 69 63  6)...string stic
0b10: 6b 65 72 5f 5b 5d 20 3d 20 3b 0d 0a 09 20 20 76  ker_[] = ;...  v
0b20: 65 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 73  ector <string> s
0b30: 74 69 63 6b 65 72 28 73 74 69 63 6b 65 72 5f 2c  ticker(sticker_,
0b40: 20 73 74 69 63 6b 65 72 5f 2b 73 69 7a 65 6f 66   sticker_+sizeof
0b50: 28 73 74 69 63 6b 65 72 5f 29 2f 73 69 7a 65 6f  (sticker_)/sizeo
0b60: 66 28 2a 73 74 69 63 6b 65 72 5f 29 29 3b 20 0d  f(*sticker_)); .
0b70: 0a 09 73 74 72 69 6e 67 20 5f 20 3d 20 3b 20 0d  ..string _ = ; .
0b80: 0a 45 4e 44 0d 0a 2a 2f 0d 0a 7d 0d 0a 2f 2f 20  .END..*/..}..// 
0b90: 45 4e 44 20 43 55 54 20 48 45 52 45 0d 0a        END CUT HERE..