Theinputguaranteesthattherearenomorethan 3 testcaseswith n>1000.
Output
Foreachtestcase,output n lines.Eachlinecontainsasingleinteger,representingtheperimeterofblackareaafterthefirst i steps.
SampleInput
1
6
122
343
562
141
261
374
SampleOutput
6
14
20
20
20
22
GraphTheoryClass
TimeLimit:
14000/7000MS(Java/Others) MemoryLimit:
524288/524288K(Java/Others)
TotalSubmission(s):
0 AcceptedSubmission(s):
0
ProblemDescription
Thisclassisongraphtheory.Mr.Kruskalteachesbabiestheconceptofminimalspanningtree,andhowtocalculatetheminimalspanningtreeofagivengraph.
Now,it'stimeforanin-classquizz.Mr.Kruskalshowsaspecialgraph G:
G isacompleteundirectedgraphwith n vertices,andverticesin G areindexedfrom 1 to n.Theweightoftheedgebetweenthe ithvertexandthe jthvertexisequalto lcm(i+1,j+1).Babiesareaskedtofindtheminimalspanningtreeof G.
Asasuperbaby,BabyVolcanoquicklyfindsananswer,butheisnotsureonthecorrectnessofhisanswer.YourtaskistotellBabyVolcanotheweightsumofalledgesontheminimalspanningtree,sothathecouldverifyhisanswer.
Giventwopositiveintegers, lcm(i,j) isdefinedastheminimalpositiveinteger k satisfyingboth i and j arefactorsof k.
Input
Thefirstlinecontainsasingleinteger t(1≤t≤50),thenumberoftestcases.
Foreachtestcase,thefirstlinecontainstwointegers n,K(1≤n≤1010,108≤K≤109).
Theinputguaranteesthat K isaprimenumber.
Theinputguaranteesthattherearenomorethan 5 testcaseswith n>109.
Output
Foreachtestcase,outputasinglelinewithasingleinteger,theanswermodule K.
SampleInput
3
3998244353
100998244353
1000000000998244353
SampleOutput
10
6307
192026508
Reports
TimeLimit:
2000/1000MS(Java/Others) MemoryLimit:
524288/524288K(Java/Others)
TotalSubmission(s):
0 AcceptedSubmission(s):
0
ProblemDescription
BecauseofCovid-19,Kanadeneedstoreporteverytimewhenenteringandleavingschool.NowyouwanttocheckifKanade'sreportsonacertaindayarecorrect.
Asequenceofreportsiscorrectifandonlyiftheredoesnotexisttwoconsecutiveandsamereports.
Input
Thereare T testcasesinthisproblem.
Thefirstlinehasoneinteger T.
Foreverytestcase:
Thefirstlinehasoneinteger n whichdenotesthenumberoftimesKanadereportedonacertainday.
Thesecondlinehas n integers a1,a2,a3,⋯,an, ai denotesthetypeofthe i-threport. ai=0 denotesaleavingschoolreportand ai=1 denotesanenteringschoolreport.
1≤T≤100
3≤n≤50
0≤ai≤1
Output
Foreverytestcase,output``YES''ifKanade'sreportsarecorrect,otherwiseoutput``NO''(withoutquotes)
SampleInput
4
3
111
3
101
5
01010
4
1011
SampleOutput
NO
YES
YES
NO
Lunch
TimeLimit:
6000/3000MS(Java/Others) MemoryLimit:
524288/524288K(Java/Others)
TotalSubmission(s):
0 AcceptedSubmission(s):
0
ProblemDescription
Nowit'stimeforlunch.Today'smenuischocolate!
Thougheverybabylikeschocolate,theappetitesofbabiesarelittle.Afterlunch,therearestill n piecesofchocolateremained:
Thelengthofthe ithpieceis li.
Usingtheremainedchocolate,BabyVolcanoisgoingtoplayagamewithhisteacher,Mr.Sprague.Theruleofthegameisquitesimple.
Twoplayerplaysinturns,andBabyVolcanowillplayfirst:
1.Ineachturn,theplayerneedstoselectonepieceofchocolate.Ifthelengthoftheselectedpieceisequalto 1,theplayerofthisturnwillloseimmediately.
2.Supposethelengthoftheselectedpieceis l.Thentheplayerneedstoselectapositiveinteger k satisfying k isatleast 2 and k isafactorof l.
3.Thentheplayerneedstocuttheselectedpieceinto k pieceswithlength lk.
Thegamecontinuesuntiloneplayerselectsapieceofchocolatewithlength 1.
Supposebothplayersplaysoptimally,yourtaskistodeterminewhetherBabyVolcanowillwin.
Input
Thefirstlinecontainssingleinteger t(1≤t≤2∗104),thenumberoftestcases.
Foreachtestcase,thefirstlinecontainsasingleinteger n(1≤n≤10).
Thesecondlinecontains n positiveintegers li(1≤li≤109),representingthelengthofeachpiece.
Output
Foreachtestcase,outputchar'W'ifBabyVolcanowillwin,otherwiseoutputchar'L'.
SampleInput
3
2
49
2
23
3
3927
SampleOutput
W
L
L
ExpressMailTaking
TimeLimit:
3000/1500MS(Java/Others) MemoryLimit:
524288/524288K(Java/Others)
TotalSubmission(s):
0 AcceptedSubmission(s):
0
ProblemDescription
Besidesonthetraditionalclasses,BabyVolcanoalsoneedstolearnhowtotaketheexpressmails.
Usuallyexpressmailsarestoredincabinets.InBabyVolcano'sschool,thereare n cabinetsinarow,numberedby 1 to n.Thedistancebetweentwoadjacentcabinetsis 1,andtheentranceisatthecabinet 1.Amongall n cabinets,theonenumbered k isspecialanditisusedtoenterthecodeandopenthecabinetdoor.
BabyVolcanohas m expressmailstotake,the i-thisinthecabinet ai.
Twoexpressmailswillnotbestoredinthesamecabinet.Alsothereisnoexpressmailinthecabinet k.
Topreventexpressesfrombeingstolen,BabyVolcanohavetotaketheseexpressmailsonebyone,startingattheentrance.Generally,ifhewantstotaketheexpressmail i,hehavetowalktocabinet k firsttoenterthecode,andthenwalkstocabinet ai.Aftertakingthelastone,hewalkstotheentrance.
Therearesomanyexpressmailstotake,soBabyVolcanowantstofindatakingorderwhichminimizethedistancehewalks.
Input
Thefirstlinecontainsoneinteger T(1≤T≤100),thenumberoftestcases.
Foreachtestcases,thefirstlinecontainsthreeinteger n,m,k(1≤k≤n≤109,1≤mThenextlinecontains m integer,the i-thstandfor ai(1≤ai≤n,ai≠k).
Theinputguaranteesthat ∑m≤2×106
**Note:
Becauseofthelargeinput,itispreferedtousescanfinsteadofcin.**
Output
Foreachtestcase,Outputasinglelinecontainsoneinteger,representingfortheminimalwalkingdistance.
SampleInput
2
1025
67
1025
34
SampleOutput
14
10
ChessClass
TimeLimit:
4000/2000MS(Java/Others) MemoryLimit:
262144/262144K(Java/Others)
TotalSubmission(s):
0 AcceptedSubmission(s):
0
ProblemDescription
Thisclassisonchess.BabyVolcanoisplayingaspecialchessgamewithhisfriend,BabyEvil.
Inthischessgame,thereisadirectedgraph G=(V,E).Verticesareindexedfrom 1 to n.Itisguaranteedthateveryvertexhasatleastoneout-goingedge,i.e. ∀v∈V,∃w∈V,(v,w)∈E,BabyVolcanotakescontrolofasubsetofvertices X⊆V,BabyEviltakescontrolof V∖X.Everyvertex v isassignedaweight W(v).
Thereisachess,positioningat s∈V initially.Thegameconsistsofthreephases.
1.Forevery p∈X,BabyVolcanochoosesanout-goingedge (p,q)∈E anddeleteotherout-goingedgesofvertex p.
2.AfterVolcano'soperation,BabyEvilwouldsimilarlychooseanout-goingedge (p′,q′)∈E anddeleteotherout-goingedgesof p′ forevery p′∉X.Bothtwobabiesmakedecisionsbasedonchess'sinitialposition s.
3.Aftertwoprocessesabove,everyvertexwouldremainonlyoneout-goingedge.Thechessstartsmovingalongtheuniquepathintheprocessedgraph,resultinginaninfinitepath L=v0v1v2⋯,where v0=s.BabyVolcanogainsscore CV atlast,whichiscomputedbelow:
CV:
=max{W(vi) | vi appearsin L}
BabyVolcanowantstomaximize CV,whileBabyEvilwantstominimizeit.
Yourtaskistodetermine,forevery s,1≤s≤n,compute CV underthecircumstancethatthechessisputat s initially.
Input
Inthefirstlinethereisanumber T,denotesthenumberoftestcases.
Thenthereare T partsofinput,eachpartdescribesatestcase.Eachpartsbeginswith n,m,R,B,denotesthenumberofvertices,edges,therangeof W(v),andthesizeof X,thesetwhichbabyvolcanotakescontrol.
Thenthereisalineconsistsof B numbers,denoteselementsin X.
Thenthereisalinewith n numbers,the i-thnumber,denotes W(i),1≤W(i)≤R.
Thenthereare m lines,eachlineconsistsof 2 numbers, u,v,showingthatthereisanedgefrom u to v in G.
1≤T≤100
1≤m,R≤5×105
1≤B≤n≤5×105
1≤∑n,∑m,∑R≤106
Output
Foreachtestcase,youshouldfirstoutput''Case#t:
''(withoutquotes),denotesthetestnumber.
Thenyouneedtooutput n numbersinthenextline,the i-thnumberis CV underthecircumstancethatthechessisputat i initially.
SampleInput
2
3321
3
112
12
23
33
46101
4
8732
13
24
32
42
21
22
SampleOutput
Case#1:
222
Case#2:
8777
RoboticClass
TimeLimit:
2000/1000MS(Java/Others) MemoryLimit:
262144/262144K(Java/Others)
TotalSubmission(s):
0 Accepted