The Big Prize
Transcript of 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)
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)
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)
Questions Score
(reportedinCMSas'WrongAnswer')
Samplegrader
Thesamplegraderisnotadaptive.Instead,itjustreadsandusesafixedarray ofprizetypes.Forall ,thetypeoftheprizeinbox isgivenas .Thesamplegraderexpectsinputinthefollowingformat:
line :line :
Thesamplegraderprintsasinglelinecontainingthereturnvalueoffind_bestandthenumberofcallstotheprocedureask.
Prize (4 of 4)