The Big Prize

4
International Olympiad in Informatics 2017 July 28 August 4, 2017 Tehran, Iran Day 2 Tasks prize English (ISC) The Big Prize The Big Prize is a famous TV game show. You are the lucky contestant who has advanced to the final round. You are standing in front of a row of boxes, labeled through from left to right. Each box contains a prize that cannot be seen until the box is opened. There are different types of prizes. The types are numbered from to in decreasing order of value. The prize of type is the most expensive one: a diamond. There is exactly one diamond in the boxes. The prize of type is the cheapest one: a lollipop. To make the game more exciting, the number of cheaper prizes is much larger than the number of more expensive ones. More specifically, for all such that we know the following: if there are prizes of type , there are strictly more than prizes of type . Your goal is to win the diamond. At the end of the game you will have to open a box and you will receive the prize it contains. Before having to choose the box to open you get to ask Rambod, the host of the game show, some questions. For each question, you choose some box . As his answer, Rambod will give you an array containing two integers. Their meaning is as follows: Among the boxes to the left of box there are exactly boxes that contain a more expensive prize than the one in box . Among the boxes to the right of box there are exactly boxes that contain a more expensive prize than the one in box . For instance, suppose that . For your question, you choose the box . As his response, Rambod tells you that . The meaning of this response is: Exactly one of the boxes and contains a prize more expensive than the one in box . Exactly two of the boxes contain a prize more expensive than the one in box . Your task is to find the box containing the diamond by asking a small number of questions. Implementation details You should implement the following procedure: int find_best(int n) This procedure is called exactly once by the grader. : the number of boxes. The procedure should return the label of the box which contains the diamond, i.e., the unique Prize (1 of 4)

Transcript of The Big Prize

Page 1: The Big Prize

InternationalOlympiadinInformatics2017July28–August4,2017Tehran,IranDay2Tasks

prizeEnglish(ISC)

TheBigPrizeTheBigPrize isa famousTVgameshow.Youare the luckycontestantwhohasadvancedto thefinalround.Youarestandinginfrontofarowof boxes,labeled through fromlefttoright.Eachboxcontainsaprize thatcannotbeseenuntil thebox isopened.Thereare differenttypesofprizes.Thetypesarenumberedfrom to indecreasingorderofvalue.

The prize of type is themost expensive one: a diamond. There is exactly one diamond in theboxes.Theprizeof type is the cheapest one: a lollipop. Tomake the gamemore exciting, thenumberofcheaperprizesismuchlargerthanthenumberofmoreexpensiveones.Morespecifically,forall such that weknow the following: if thereare prizesof type , therearestrictlymorethan prizesoftype .

Yourgoal is towin thediamond.At theendof thegameyouwillhavetoopenaboxandyouwillreceivetheprizeitcontains.BeforehavingtochoosetheboxtoopenyougettoaskRambod,thehostofthegameshow,somequestions.Foreachquestion,youchoosesomebox .Ashisanswer,Rambodwillgiveyouanarray containingtwointegers.Theirmeaningisasfollows:

Among the boxes to the left of box there are exactly boxes that contain a moreexpensiveprizethantheoneinbox .Among the boxes to the right of box there are exactly boxes that contain a moreexpensiveprizethantheoneinbox .

Forinstance,supposethat .Foryourquestion,youchoosethebox .Ashisresponse,Rambodtellsyouthat .Themeaningofthisresponseis:

Exactlyoneoftheboxes and containsaprizemoreexpensivethantheoneinbox .Exactlytwooftheboxes containaprizemoreexpensivethantheoneinbox .

Yourtaskistofindtheboxcontainingthediamondbyaskingasmallnumberofquestions.

Implementationdetails

Youshouldimplementthefollowingprocedure:

intfind_best(intn)

Thisprocedureiscalledexactlyoncebythegrader.:thenumberofboxes.

Theprocedureshouldreturnthelabeloftheboxwhichcontainsthediamond,i.e.,theunique

Prize (1 of 4)

Page 2: The Big Prize

integer ( )suchthatbox containsaprizeoftype .

Theaboveprocedurecanmakecallstothefollowingprocedure:

int[]ask(inti)

:labeloftheboxthatyouchoosetoaskabout.Thevalueof mustbebetween and ,inclusive.This procedure returns the array with elements. Here, is the number of moreexpensiveprizes in theboxes to the leftofbox and is thenumberofmoreexpensiveprizesintheboxestotherightofbox .

Example

Thegradermakesthefollowingprocedurecall:

find_best(8)

Thereare boxes.Supposetheprize typesare .Allpossiblecalls to theprocedureaskandthecorrespondingreturnvaluesarelistedbelow.

ask(0)returnsask(1)returnsask(2)returnsask(3)returnsask(4)returnsask(5)returnsask(6)returnsask(7)returns

Inthisexample,thediamondisinbox .Sotheprocedurefind_bestshouldreturn .

Prize (2 of 4)

Page 3: The Big Prize

Theabovefigureillustratesthisexample.Theupperpartshowsthetypesoftheprizesineachbox.Thelowerpartillustratesthequeryask(2).Themarkedboxescontainmoreexpensiveprizesthantheoneinbox .

Constraints

.Thetypeoftheprizeineachboxisbetween and ,inclusive.Thereisexactlyoneprizeoftype .Forall ,ifthereare prizesoftype ,therearestrictlymorethan prizesoftype .

Subtasksandscoring

Insometestcasesthebehaviorofthegrader isadaptive.Thismeansthat inthesetestcasesthegrader does not have a fixed sequence of prizes. Instead, the answers given by the gradermaydependonthequestionsaskedbyyoursolution.Itisguaranteedthatthegraderanswersinsuchawaythataftereachanswerthereisatleastonesequenceofprizesconsistentwithalltheanswersgivensofar.

1. (20points)There isexactly diamondand lollipops (hence, ).Youcancall theprocedureaskatmost times.

2. (80points)Noadditionalconstraints.

Insubtask2youcanobtainapartialscore.Let bethemaximumnumberofcallstotheprocedureaskamongalltestcasesinthissubtask.Then,yourscoreforthissubtaskiscalculatedaccordingtothefollowingtable:

Prize (3 of 4)

Page 4: The Big Prize

Questions Score

(reportedinCMSas'WrongAnswer')

Samplegrader

Thesamplegraderisnotadaptive.Instead,itjustreadsandusesafixedarray ofprizetypes.Forall ,thetypeoftheprizeinbox isgivenas .Thesamplegraderexpectsinputinthefollowingformat:

line :line :

Thesamplegraderprintsasinglelinecontainingthereturnvalueoffind_bestandthenumberofcallstotheprocedureask.

Prize (4 of 4)