# Input starts with a string of characters of length n (1 ≤ n ≤ 150) # indicating the initial usage of the bins. The characters will all # be from the set {A, E, I, O, U, X} indicating either the company # using the bin or an empty bin (X). SET(quit=0) WHILEI(i,quit==0) REGEX("[AEIOUX\n]",x) IF(x=="\n") SET(quit=1) ELSE SET(s[i]=x) END END SET(n=i-1) ASSERT(n>=1 && n <=150) # Following this is a row of n # integers indicating the number of items in each bin; values at # locations corresponding to an empty bin will always be 0 and values # at locations corresponding to a company’s bin will be positive and ≤ 100. REPI(i,n,SPACE) INT(0,100,k) IF (s[i]=="X") ASSERT(k==0) END IF (s[i] != "X") ASSERT(k>0) END END NEWLINE # Bins for any one company will always be contiguous. # (It probably makes more sense to do this with a different program, but # I wanted to see how hard it would be in CTD!) SET(last="X") SET(acount=0) SET(ecount=0) SET(icount=0) SET(ocount=0) SET(ucount=0) SET(xcount=0) REPI(i,n) IF (s[i]=="A" && last!="A") SET(acount=acount+1) END IF (s[i]=="E" && last!="E") SET(ecount=ecount+1) END IF (s[i]=="I" && last!="I") SET(icount=icount+1) END IF (s[i]=="O" && last!="O") SET(ocount=ocount+1) END IF (s[i]=="U" && last!="U") SET(ucount=ucount+1) END IF (s[i]=="X") SET(xcount=xcount+1) END SET(last=s[i]) END ASSERT(acount<=1) ASSERT(ecount<=1) ASSERT(icount<=1) ASSERT(ocount<=1) ASSERT(ucount<=1) # The next line # starts with an integer d (0 ≤ d ≤ n) indicating the number of deletions # for this quarter. Following this are d integers. Each integer # specifies a bin which is no longer needed by a company. # None will ever correspond to an already empty bin. INT(0,n,d) IF (d > 0) SPACE REPI(i,d,SPACE) INT(1,n,del[i]) ASSERT(s[del[i]-1] != "X") SET(xcount=xcount+1) END ASSERT(UNIQUE(del)) END NEWLINE # On the final # line is a positive-length string of characters indicating the new # bins requested. If this string is a single X then no new bins are # being requested. Otherwise the characters will all be in the set # {A, E, I, O, U}, in no particular order, each character representing # a request for a new bin by the corresponding company. There will # always be enough bins to handle any set of changes. REGEX("[AEIOU]+|X",r) IF (r!="X") ASSERT(STRLEN(r) <= xcount) END NEWLINE