├── 1-sir.cpp ├── 2ndesc.cpp ├── 3secv.cpp ├── APMD.cpp ├── Andrei.cpp ├── BMatrix.cpp ├── Bellman Ford cu BFS.cpp ├── CT.cpp ├── Codare surse.cpp ├── FAREY TESTARE.cpp ├── Freeform Factory.cpp ├── JUDETE.cpp ├── KMP.cpp ├── LCA bogdan batog ZEUL MEU.cpp ├── LCA v2.cpp ├── LCA.cpp ├── PD.cpp ├── PROKLETNIK.cpp ├── Por Costel si Zeul.cpp ├── Por Costel si trenul.cpp ├── RMQ v2.cpp ├── RMQ.cpp ├── Rather Perplexing Showdown.cpp ├── SPP v2 test.cpp ├── Subsequences Summing to Sevens.cpp ├── Tmax.cpp ├── X.cpp ├── abc2.cpp ├── acop.cpp ├── acquire.cpp ├── adapost2.cpp ├── agentia.cpp ├── aho Corasick.cpp ├── aib.cpp ├── aimin.cpp ├── albina1.cpp ├── albinuta1.cpp ├── algoritmul lui euclid extins.cpp ├── all subsets.cpp ├── amedie.cpp ├── amenzi.cpp ├── amici2.cpp ├── android.cpp ├── angrenaj.cpp ├── aparitii2.cpp ├── apm campionn.cpp ├── apm.cpp ├── apm2.cpp ├── aranjare1.cpp ├── arb2.cpp ├── arb3.cpp ├── arb4.cpp ├── arbfind.cpp ├── arbore3.cpp ├── arbore4.cpp ├── arbore5.cpp ├── arborest.cpp ├── arbori de intervale.cpp ├── arbpal.cpp ├── arbvalmax.cpp ├── arbxyz.cpp ├── arhipeleag.cpp ├── aria.cpp ├── arthur.cpp ├── articulatie.cpp ├── artur.cpp ├── asmax.cpp ├── asmin.cpp ├── atac.cpp ├── atac2.cpp ├── austostrazi2.cpp ├── australia.cpp ├── auto2.cpp ├── autobuze.cpp ├── autobuze2.cpp ├── autostrazi.cpp ├── avarcolaci.cpp ├── avd.cpp ├── avioane.cpp ├── avioane2.cpp ├── back iterativ.cpp ├── back ivv.cpp ├── back2014.cpp ├── bal.cpp ├── baloane1.cpp ├── balul bobocilor.cpp ├── banana.cpp ├── bancomat.cpp ├── banuti.cpp ├── barca1.cpp ├── barfa.cpp ├── baruri.cpp ├── base3.cpp ├── basket.cpp ├── bdotcom.cpp ├── beads.cpp ├── bellman ford.cpp ├── bemo.cpp ├── ben.cpp ├── berarii2.cpp ├── bere.cpp ├── bete2.cpp ├── bfs.cpp ├── biconex.cpp ├── biconexe ve2.cpp ├── big brothers.cpp ├── bila1.cpp ├── bile.cpp ├── bile2.cpp ├── bile4.cpp ├── bilete.cpp ├── bilete1.cpp ├── binar.cpp ├── bipal.cpp ├── bipartir v2.cpp ├── biperm.cpp ├── birocratie.cpp ├── biscuiti.cpp ├── biti.cpp ├── bitonic.cpp ├── blas.cpp ├── bleach.cpp ├── blockout.cpp ├── bonuri.cpp ├── boom.cpp ├── branza.cpp ├── brazi.cpp ├── broscute.cpp ├── bsir.cpp ├── buget.cpp ├── build gates.cpp ├── bujor.cpp ├── bus driver.cpp ├── cabane.cpp ├── cafea.cpp ├── caini.cpp ├── caini1.cpp ├── calancea.cpp ├── calandrinon.cpp ├── calatorie interplanetara.cpp ├── calatorie.cpp ├── caluti.cpp ├── camion.cpp ├── camionas.cpp ├── candy boxes.cpp ├── capitala.cpp ├── car.cpp ├── caroiaj.cpp ├── carray.cpp ├── carrie.cpp ├── carry testare.cpp ├── carry.cpp ├── carte.cpp ├── carti2.cpp ├── cartite.cpp ├── case.cpp ├── cast.cpp ├── castel.cpp ├── catun.cpp ├── cautare binara.cpp ├── ccm.cpp ├── cele mai apropiate puncte in plan.cpp ├── centre.cpp ├── cerc_O(1).cpp ├── cerere.cpp ├── cetati.cpp ├── cez.cpp ├── charlie.in.cpp ├── checkin.cpp ├── chei.cpp ├── chei2222.cpp ├── chiftea.cpp ├── ciclu eulerian ( alg lui Fleury, sparge stiva).cpp ├── ciclu eulerian (v cu formare din alte cicluri).cpp ├── ciclu eulerian.cpp ├── ciclu2.cpp ├── ciclueuler.cpp ├── ciclul eulerian.cpp ├── cifre4.cpp ├── cifru3.cpp ├── cifru5.cpp ├── ciob.cpp ├── circuit.cpp ├── circulatie.cpp ├── clepsidra.cpp ├── clues.cpp ├── cmin.cpp ├── cmlsc.cpp ├── cmmmc.cpp ├── cntper.cpp ├── coach.cpp ├── cobai.cpp ├── cocochanel.cpp ├── cod1.cpp ├── codarea huffman.cpp ├── codeforce B.cpp ├── codeforce.cpp ├── codeforces.cpp ├── codetoss.cpp ├── codul.cpp ├── colecti.cpp ├── coliniare.cpp ├── colo2.cpp ├── color infoarena.cpp ├── color.cpp ├── colorare.cpp ├── combcuv.cpp ├── coment.cpp ├── commando.cpp ├── compact2.cpp ├── componenete biconexe.cpp ├── componente biconexe.cpp ├── compus.cpp ├── comun.cpp ├── concert.cpp ├── concurs.cpp ├── confuzie.cpp ├── conserve.cpp ├── constant.cpp ├── convex hull.cpp ├── copaci2.cpp ├── copii.cpp ├── coprime.cpp ├── costperm.cpp ├── cover.cpp ├── cover1.cpp ├── covor.cpp ├── cowfood.cpp ├── crescator.cpp ├── criptare2.cpp ├── cristal.cpp ├── critice3.cpp ├── cs.cpp ├── csir.cpp ├── ctc.cpp ├── cub1.cpp ├── cuburi3.cpp ├── cuiburi.cpp ├── cuie.cpp ├── culmi.cpp ├── culori.cpp ├── cumapnit.cpp ├── cuplaj maxim bipartit.cpp ├── cuplaj maxim in graf bipartir.cpp ├── cuplaj maxim in graf bipartit.cpp ├── curcubeu.cpp ├── curent.cpp ├── curse de cai.cpp ├── cutii.cpp ├── cuvant.cpp ├── cuvinte.cpp ├── dag.cpp ├── dans.cpp ├── darb.cpp ├── datorii.cpp ├── delay.cpp ├── delivery.cpp ├── demilosh.cpp ├── demolish.cpp ├── dep.cpp ├── depou.cpp ├── deque.cpp ├── desc2.cpp ├── descompunere pe nivele.cpp ├── desen.cpp ├── desen1.cpp ├── despartire.cpp ├── dezbateri.cpp ├── dfs xor2012.cpp ├── dfs.cpp ├── dfscampion.cpp ├── diamant.cpp ├── diametru arbore.cpp ├── diametrul unui arbore.cpp ├── dinti.cpp ├── dir.cpp ├── dirty.cpp ├── disconnect.cpp ├── disjoint.cpp ├── dist2.cpp ├── distante.cpp ├── distince.cpp ├── distincte.in.cpp ├── divprim.cpp ├── djikstra.cpp ├── doi.cpp ├── domimatrix.cpp ├── domino infoarena.cpp ├── domino.cpp ├── domino2.cpp ├── dominouri.cpp ├── dorel - concatenate.cpp ├── dorel - neconcatenate.cpp ├── dp.cpp ├── drept.cpp ├── dreptunghiuri5.cpp ├── drumuri.cpp ├── drumuri1.cpp ├── drumuri2 v2.cpp ├── drumuri2.cpp ├── drumuri3.cpp ├── drzava.cpp ├── easydel.cpp ├── easygraph.cpp ├── easyquery.cpp ├── easyvect.cpp ├── ecluze.in.cpp ├── ecluzev2.cpp ├── ecologie.cpp ├── ecuatie.cpp ├── efort.cpp ├── egal.cpp ├── elementul majoritar.cpp ├── elemnt majoritar.cpp ├── eliminare.cpp ├── elmaj.cpp ├── energii.cpp ├── enigma.cpp ├── entries.cpp ├── eq4.cpp ├── euclid extins v2.cpp ├── euclid extins.cpp ├── euclid.cpp ├── euler.cpp ├── eulerian.cpp ├── euro.cpp ├── evacuare.cpp ├── evantai.cpp ├── exam.cpp ├── exams.cpp ├── excursie1.cpp ├── expo.cpp ├── expozitie.cpp ├── expr.cpp ├── expresie.cpp ├── expression.cpp ├── farfurii.cpp ├── fashion police.cpp ├── fat.cpp ├── fazan varena.cpp ├── fazan.cpp ├── fbr.cpp ├── felinar.cpp ├── felinare.cpp ├── ferma.cpp ├── fibosum.cpp ├── firma.cpp ├── flood.cpp ├── fluviu.cpp ├── flux maxim de cost minim.cpp ├── flux maxim v2.cpp ├── flux maxim.cpp ├── fmcm.cpp ├── fold.cpp ├── football.cpp ├── fotbal1.cpp ├── frac.cpp ├── fractii.cpp ├── fractiles.cpp ├── friends of friends.cpp ├── friends.cpp ├── fsb.cpp ├── functii.cpp ├── gaina.cpp ├── galerie.cpp ├── games.cpp ├── gandaci java.cpp ├── gapetto.cpp ├── gard.cpp ├── gard2.cpp ├── gard3.cpp ├── gard4.cpp ├── gardieni.in.cpp ├── gauss.cpp ├── gaz.cpp ├── generare.cpp ├── geometrie.cpp ├── ghicit.cpp ├── gigatower.cpp ├── gigel.cpp ├── gigel2.cpp ├── gold.cpp ├── grade.cpp ├── gradina1.cpp ├── graf.cpp ├── grafxy.cpp ├── gramezi.cpp ├── grammar.cpp ├── granita.cpp ├── grarb.cpp ├── grazing v2.cpp ├── grazing.cpp ├── gripa.cpp ├── grupuri.cpp ├── hack.cpp ├── hacker infoarena.cpp ├── hacker.cpp ├── hamilton.cpp ├── hanoi.cpp ├── harta2.cpp ├── hashuri.cpp ├── hawaii.cpp ├── heap.cpp ├── heapuri.cpp ├── heavy metal.cpp ├── hideandseek.cpp ├── honest.cpp ├── hotel.cpp ├── huffman.cpp ├── iepuri.cpp ├── import.cpp ├── imunitate.cpp ├── incantatii.cpp ├── infasuratoarea convexa v2.cpp ├── infasuratoarea convexa.cpp ├── inifinit pattern matching.cpp ├── initial bet.cpp ├── int.cpp ├── intersectii.cpp ├── interviu.cpp ├── invatare map.cpp ├── invcs.cpp ├── invers modular v2.cpp ├── invers modular.cpp ├── inversari.cpp ├── inversiuni.cpp ├── invsort.cpp ├── ivv.cpp ├── izo.cpp ├── izvor.cpp ├── jam city.cpp ├── job.cpp ├── joc.cpp ├── joc10.cpp ├── joc13.cpp ├── joc3.cpp ├── joc4.cpp ├── joc6.cpp ├── joctv.cpp ├── jocul NIM.cpp ├── jocul.cpp ├── joculet.cpp ├── johnie.cpp ├── jokes.cpp ├── jstc.cpp ├── jucarii.cpp ├── jungla.cpp ├── k-lea fibonacci.cpp ├── k1.cpp ├── karb2.cpp ├── kcons.cpp ├── kcover.cpp ├── kdist.cpp ├── kdrum.cpp ├── kdtree.cpp ├── kfib.cpp ├── kgb.cpp ├── kmax.cpp ├── kpal.cpp ├── kreg.cpp ├── ksecv.cpp ├── ksecv4.cpp ├── ksplit.cpp ├── kss.cpp ├── ktown.cpp ├── ktree.cpp ├── kubus2.cpp ├── lac.cpp ├── lant eulerian.cpp ├── lant.cpp ├── lanterna varena.cpp ├── lanterna.cpp ├── lanturi.cpp ├── leaves.cpp ├── left.cpp ├── lgput.cpp ├── licenta.cpp ├── lifesum.cpp ├── lights out.cpp ├── linii.cpp ├── linkedin.cpp ├── lista.cpp ├── litoral.cpp ├── livada2.cpp ├── log.cpp ├── logn.cpp ├── lol.cpp ├── long jumps.cpp ├── magazin2.cpp ├── magic2.cpp ├── magic5.cpp ├── maimute.cpp ├── mall.cpp ├── map d eelemente.cpp ├── map.cpp ├── margi.cpp ├── marko.cpp ├── markon.cpp ├── marmelada.cpp ├── masina.cpp ├── masina1.cpp ├── matd3.cpp ├── matperm2.cpp ├── matrice.cpp ├── maxflow.cpp ├── maxq.cpp ├── maxviz.cpp ├── meciul.cpp ├── medii.cpp ├── mem.cpp ├── mere fmi.cpp ├── mere.cpp ├── mergesort.cpp ├── mesaj.cpp ├── mesaj2.cpp ├── mesaj4.cpp ├── mese.cpp ├── mess.cpp ├── mexc.cpp ├── micro.cpp ├── miere.cpp ├── mijloc.cpp ├── minuni.cpp ├── minusk.cpp ├── miting.cpp ├── monopoly.cpp ├── mosia.cpp ├── movedel.cpp ├── mult.cpp ├── multigram.cpp ├── multimi.cpp ├── munte.cpp ├── muzeu.cpp ├── mvc.cpp ├── naveplanetare.cpp ├── ndap.cpp ├── nessie.cpp ├── nk.cpp ├── noname.cpp ├── noname2.cpp ├── nop.cpp ├── note.cpp ├── nrbanda.cpp ├── nrcuv.cpp ├── nrcuv1.cpp ├── nrspecial.cpp ├── nrsubsircresc.in2.cpp ├── nrtri.cpp ├── nucleul valoros 2.cpp ├── nucleulvaloros2.cpp ├── numar.cpp ├── numararedp.cpp ├── numere mari.cpp ├── numere4.cpp ├── numere6.cpp ├── numere7.cpp ├── numqdv.cpp ├── obstacole.cpp ├── ograzi.cpp ├── oite.cpp ├── omizi.cpp ├── online.cpp ├── oo.cpp ├── optim.cpp ├── oras.cpp ├── orase.cpp ├── orient.cpp ├── otpor.cpp ├── overdrive.cpp ├── p management.cpp ├── pack.cpp ├── paduri d emultimi disjuncte.cpp ├── paint.cpp ├── paintball.cpp ├── paiting.cpp ├── pajura.cpp ├── pal.cpp ├── palc.cpp ├── palila.cpp ├── palind.cpp ├── palsubsecv.cpp ├── pamant.cpp ├── pamant2.cpp ├── pancakes.cpp ├── pandora.cpp ├── paplova.cpp ├── para.cpp ├── paralel.cpp ├── parantezare.cpp ├── paranteze2.cpp ├── paresort.cpp ├── pariuri.cpp ├── parovi.cpp ├── parpal.cpp ├── party.cpp ├── pasha.cpp ├── pastila.cpp ├── path.cpp ├── patrate6.cpp ├── patrol.cpp ├── pav.cpp ├── pavare.cpp ├── pba.cpp ├── pedefe.cpp ├── pei.cpp ├── pelicular times.cpp ├── per.cpp ├── perfect.cpp ├── perica.cpp ├── perle2.cpp ├── perm6.cpp ├── permlsc.cpp ├── permsort.cpp ├── permsplit.cpp ├── permtr.cpp ├── permutare2.cpp ├── permutari3.cpp ├── permutari4.cpp ├── petrica.cpp ├── petrom.cpp ├── petsoft.cpp ├── pianino.cpp ├── piete.cpp ├── pikachu.cpp ├── pinex.cpp ├── pipe.cpp ├── pirati.cpp ├── piscina.cpp ├── pitici.cpp ├── pititci.cpp ├── pkinv.cpp ├── plan.cpp ├── plantatie.cpp ├── plantatii.cpp ├── platforma.cpp ├── playlist.cpp ├── plimbare.cpp ├── plopi.cpp ├── poarta.cpp ├── pointeri.cpp ├── pokemon3.cpp ├── police.cpp ├── poligon.cpp ├── politic.cpp ├── poly.cpp ├── posta2.cpp ├── poveste.cpp ├── poze.cpp ├── pr de verificare.cpp ├── prefix.cpp ├── prefixe.cpp ├── prezenta.cpp ├── prieten.cpp ├── prieteni1.cpp ├── prieteni3.cpp ├── principiul includerii si excluderii.cpp ├── prisme.cpp ├── problema cu becuri.cpp ├── proc.cpp ├── produse.cpp ├── profit.cpp ├── program1.cpp ├── projec management.cpp ├── propozitie.cpp ├── pscpld.cpp ├── pseudobil.cpp ├── puncte.cpp ├── puncte2.cpp ├── puncte6.cpp ├── punctfix.cpp ├── pviz.cpp ├── qtri.cpp ├── qxy.cpp ├── raco back.cpp ├── raco.cpp ├── radare.cpp ├── radiatie.cpp ├── radio.in.cpp ├── radio1.cpp ├── radix sort.cpp ├── raft.cpp ├── rafturi.cpp ├── random teams.cpp ├── random.cpp ├── ratina trie.cpp ├── ratina.cpp ├── razboi.cpp ├── reborn.cpp ├── rec.cpp ├── red tape comitee.cpp ├── reddragon.cpp ├── rege.cpp ├── reguli.cpp ├── reinvent.cpp ├── repeat.cpp ├── retea.cpp ├── retea2.cpp ├── retele.cpp ├── reuniune.cpp ├── revolutie.cpp ├── revsecv.cpp ├── rf.cpp ├── riglef.cpp ├── rinv.cpp ├── rlcs.cpp ├── ro.cpp ├── robot.cpp ├── robot4.cpp ├── robotics.cpp ├── rocker.cpp ├── romane.cpp ├── romania.cpp ├── royfloyd.cpp ├── rucsac.cpp ├── safeu.cpp ├── sah1.cpp ├── sahara.cpp ├── salvare.cpp ├── san.cpp ├── sant.cpp ├── saritura_calului1.cpp ├── sate.cpp ├── scara.cpp ├── scara1.cpp ├── sccm.cpp ├── scenariu.cpp ├── schi.cpp ├── scm.cpp ├── scmax.cpp ├── scoici.cpp ├── sea2.cpp ├── search.cpp ├── secvdist.in.cpp ├── secventa farey.cpp ├── secventa5.cpp ├── secventak.cpp ├── secvmax.cpp ├── secvmin.cpp ├── sediu.cpp ├── segment.cpp ├── segmente.cpp ├── semafoare.cpp ├── semipalindrom onis.cpp ├── senat.cpp ├── senate evacuation.cpp ├── senzori.cpp ├── sequencequery.cpp ├── set.cpp ├── seti.cpp ├── sg1.cpp ├── shades of prime.cpp ├── sheep.cpp ├── shgraf.cpp ├── shop.cpp ├── sick leaves.cpp ├── sir.cpp ├── sir2dif.cpp ├── sir3.cpp ├── sirag1.cpp ├── sirag2.cpp ├── sirlab.cpp ├── siruri.cpp ├── siruri1.1.cpp ├── siruri2.cpp ├── site.cpp ├── slides.cpp ├── sobo.cpp ├── soldati v2.cpp ├── soldati.cpp ├── something.cpp ├── sortare toplogica 2.cpp ├── sortare topologica.cpp ├── sortaret.cpp ├── sosele.cpp ├── speeding.cpp ├── spion.cpp ├── split2.cpp ├── sport.cpp ├── spp V@.cpp ├── srevni.cpp ├── ssc.cpp ├── ssce.cpp ├── ssdj.cpp ├── stalpi2.cpp ├── startrek.cpp ├── statie.cpp ├── statistici de ordine.cpp ├── steinsgate.in.cpp ├── stelar.cpp ├── stiva.cpp ├── stiva1.cpp ├── stive.cpp ├── stramosi.cpp ├── strategie.cpp ├── strict.cpp ├── strigat.cpp ├── string.cpp ├── strmatch KMP.cpp ├── strncpy.cpp ├── sub.cpp ├── subarbore.cpp ├── subm.cpp ├── submult.cpp ├── subs.cpp ├── subsecvente.cpp ├── subsir.cpp ├── subsiruri 3.cpp ├── subsiruri2.in.cpp ├── substr.cpp ├── suma.cpp ├── suma2.cpp ├── suma4.cpp ├── sume.cpp ├── sumk v2.cpp ├── sumk.cpp ├── sumsums.cpp ├── superstring.cpp ├── swap.cpp ├── tabara1.cpp ├── tabel decorations.cpp ├── tabel.cpp ├── tablite.cpp ├── taie.cpp ├── take5.cpp ├── tarabe.cpp ├── taste.cpp ├── taxi.cpp ├── tcast.cpp ├── teamwork.cpp ├── teatru1.cpp ├── telefon.cpp ├── teme.cpp ├── teroristi.cpp ├── teroristi2.cpp ├── test blockout.cpp ├── test final.cpp ├── test sibsircresc2.cpp ├── test.cpp ├── teste incantatii.cpp ├── teste stringuri.cpp ├── teste v2.cpp ├── tester.cpp ├── tetris2.cpp ├── tgv.cpp ├── timbre.cpp ├── tort.cpp ├── tower8.cpp ├── towers.cpp ├── towerx.cpp ├── trafic.cpp ├── trains.in.cpp ├── trans.cpp ├── transform.cpp ├── transformari.cpp ├── transport rutier.cpp ├── trasee.cpp ├── traseu.cpp ├── traseu1.cpp ├── tree campion.cpp ├── tree.cpp ├── treesearch.cpp ├── trenuri.cpp ├── triburi1.cpp ├── tric.cpp ├── tricouri.cpp ├── trie.cpp ├── trigrame.cpp ├── trip.cpp ├── triplet.cpp ├── triunghi.cpp ├── triunghi2.cpp ├── trmv.cpp ├── ture.cpp ├── turn1.cpp ├── turneu.cpp ├── turnuri2.in.cpp ├── ubuntzei.cpp ├── unique.cpp ├── universitate.cpp ├── unordered_map test.cpp ├── unordered_map.cpp ├── urgenta.cpp ├── uscat.cpp ├── v2d.cpp ├── vectori pari.cpp ├── vedete.cpp ├── verifi pare.cpp ├── veverita.cpp ├── victorie.cpp ├── viena.cpp ├── virus.cpp ├── vitale.cpp ├── vizibil.cpp ├── volum.cpp ├── vot.cpp ├── vot1.cpp ├── vudu.cpp ├── war.cpp ├── water logic.cpp ├── wg.cpp ├── xerox.cpp ├── xmoto.cpp ├── xnumere.cpp ├── xorin.cpp ├── xormax.cpp ├── young.cpp ├── zaharel.cpp ├── zapezi2.cpp ├── zebunghil.cpp ├── ziduri.cpp ├── zlego.cpp ├── zmeu.cpp ├── zmeu2.cpp ├── zoo.cpp └── zvon.cpp /1-sir.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define mod 194767 4 | # define NR 256*257/2+5 5 | using namespace std; 6 | ifstream f("1-sir.in"); 7 | ofstream g("1-sir.out"); 8 | int i,j,n,m,maxx,S; 9 | int a[NR], b[NR]; 10 | int main () 11 | { 12 | f>>n>>S; 13 | if (n*(n+1)/2 2 | # include 3 | using namespace std; 4 | ifstream f("3secv.in"); 5 | ofstream g("3secv.out"); 6 | int 7 | int main () 8 | { 9 | f>>n; 10 | for (i=1; i<=n; ++i) 11 | f>>a[i]; 12 | 13 | 14 | for (i=n-1; i>=1; --i) 15 | { 16 | 17 | } 18 | 19 | 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Codare surse.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 1005 5 | using namespace std; 6 | ifstream f("date.in"); 7 | ofstream g("date.out"); 8 | int i,j,n,m,x,y; 9 | char s[NR]; 10 | int main () 11 | { 12 | 13 | while (f.getline (s, NR)) { 14 | g< 2 | # define NR 5000005 3 | using namespace std; 4 | ifstream f("farey.in"); 5 | ofstream g("farey.out"); 6 | struct elem { 7 | int a, b; 8 | double rap; 9 | }a[NR]; 10 | bool cmp (elem x, elem y) { 11 | return x.rap < y.rap; 12 | } 13 | int i,j,n,m,VV,K; 14 | 15 | int cmmdc (int a, int b) { 16 | int R=0; 17 | while (b) { 18 | R=a%b; 19 | a=b; 20 | b=R; 21 | } 22 | return a; 23 | } 24 | int main () 25 | { 26 | f>>n>>K; 27 | for (i=1; i<=n; ++i) 28 | for (j=i+1; j<=n; ++j) { 29 | if (cmmdc (i, j)==1) { 30 | ++VV; 31 | a[VV].a=i; a[VV].b=j; 32 | a[VV].rap=(double)i / j; 33 | } 34 | } 35 | sort (a+1, a+VV+1, cmp); 36 | g< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i,j; 7 | int k; 8 | int n; 9 | int v[100]; // elementele citite de la tastatura 10 | int l[100]; // l[i] = lungimea celui mai lung subsir crescator pana la pozitia i 11 | cout<<"n= "; cin>>n; 12 | 13 | for(int i=1; i<=n; i++) 14 | { 15 | cout<<"v["<>v[i]; 16 | 17 | l[i]=1; //initial, lungimea celui mai lung subsir este 1, adica el singur 18 | 19 | for (int j=i-1; j>0; --j) 20 | if (v[j]<=v[i] && l[j]+1>l[i]) l[i]=l[j]+1; 21 | // daca gasim in elementele anterioare un element mai mic sau egal cu v[i] 22 | // atunci elementul v[i] se poate adauga la acest subsir 23 | 24 | cout<<"Lungimea celui mai lung subsir crescator terminat pe pozitia "< 2 | # include 3 | # define NR 300005 4 | using namespace std; 5 | ifstream f("zeul.in"); 6 | ofstream g("zeul.out"); 7 | int i,j,n,m,P,D,x,y; 8 | int donez[NR], primesc[NR], in[NR], out[NR]; 9 | int main () 10 | { 11 | f>>n>>m; 12 | for (i=1; i<=m; ++i) { 13 | f>>x>>y; 14 | ++out[x]; ++in[y]; 15 | } 16 | for (i=1; i<=n; ++i) { 17 | if (in[i] 2 | # include 3 | # define NMAX 100005 4 | using namespace std; 5 | ifstream f("rmq.in"); 6 | ofstream g("rmq.out"); 7 | int i,j,n,m,x,y,k,Q,LG,ci,cs; 8 | int RMQ[20][NMAX], lg[NMAX]; 9 | int main () 10 | { 11 | f>>n>>Q; 12 | for (i=1; i<=n; ++i) 13 | f>>RMQ[0][i]; 14 | 15 | for (i=2; i<=n; ++i) 16 | lg[i]=lg[i/2]+1; 17 | 18 | for (i=1; i<=lg[n]; ++i) { 19 | for (j=1; j<=n-(1<<(i-1))+1; ++j) 20 | if (RMQ[i-1][j] < RMQ[i-1][j+(1<<(i-1))]) RMQ[i][j]=RMQ[i-1][j]; 21 | else RMQ[i][j]=RMQ[i-1][j+(1<<(i-1))]; 22 | } 23 | 24 | for (i=1; i<=Q; ++i){ 25 | f>>ci>>cs; 26 | if (ci > cs) swap(ci, cs); 27 | LG=lg[cs-ci+1]; 28 | 29 | if (RMQ[LG][ci] < RMQ[LG][cs-(1< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | ifstream f("rmq.in"); 6 | ofstream g("rmq.out"); 7 | int i,j,n,m,x,y,k; 8 | int a[20][NR], lg[NR]; 9 | int main () 10 | { 11 | f>>n>>m; 12 | for (i=2; i<=n; ++i) 13 | lg[i]=lg[i/2]+1; 14 | 15 | for (i=1; i<=n; ++i) 16 | f>>a[0][i]; 17 | 18 | for (i=1; i<=lg[n]; ++i) 19 | for (j=1; j<=n-(1<<(i-1)); ++j) 20 | a[i][j]=min(a[i-1][j], a[i-1][j+(1<<(i-1))]); 21 | 22 | for (i=1; i<=m; ++i) 23 | { 24 | f>>x>>y; 25 | k=lg[y-x+1]; 26 | g< 2 | # include 3 | # include 4 | # define NR 1000005 5 | using namespace std; 6 | ifstream f("date.in"); 7 | ofstream g("date.out"); 8 | int i,j,n,m,MOD,T,K; 9 | int b[NR], c[NR]; 10 | long long a[NR],S; 11 | int main () 12 | { 13 | f>>T; 14 | for (int t=1; t<=T; ++t) 15 | { 16 | f>>K; memset (a, 0, sizeof(a)); 17 | for (i=1; i<=K; ++i) f>>a[i]; 18 | for (i=1; i<=K; ++i) f>>c[i]; 19 | 20 | f>>n>>m>>MOD; 21 | 22 | for (i=K+1; i<=m; ++i) 23 | for (j=1; j<=K; ++j) { 24 | a[i]+=1LL*a[i-j]*c[j]; 25 | a[i]%=MOD; 26 | } 27 | S=0; 28 | for (int i=n; i<=m; ++i) 29 | {S+=a[i]; S%=MOD;} 30 | g< 2 | # include 3 | # include 4 | # define NR 50005 5 | using namespace std; 6 | ifstream f("div7.in"); 7 | ofstream g("div7.out"); 8 | int i,j,n,m,maxx,r; 9 | long long S[NR], a[NR]; 10 | int R[10]; 11 | int main () 12 | { 13 | f>>n; 14 | for (i=1; i<=n; ++i) { 15 | f>>a[i]; 16 | S[i]=S[i-1] + a[i]; 17 | 18 | 19 | r=S[i]%7LL; 20 | if (R[r]) maxx=max(maxx, i-R[r]); 21 | else R[r]=i; 22 | } 23 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("adapost2.in") 5 | -------------------------------------------------------------------------------- /agentia.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 105 5 | using namespace std; 6 | ifstream f("agentia.in"); 7 | ofstream g("agentia.out"); 8 | vector v[NR]; 9 | int i,j,n,m,x,VV; 10 | bool ap[NR]; 11 | void DFS (int k) 12 | { 13 | ap[k]=1; 14 | for (int i=0; i>n; 20 | for (i=1; i<=n; ++i) 21 | { 22 | f>>m; 23 | for (j=1; j<=m; ++j) 24 | { 25 | f>>x; 26 | v[i].push_back(x); 27 | v[x].push_back(i); 28 | } 29 | } 30 | 31 | for (i=1; i<=n; ++i) 32 | { 33 | if (! ap[i]) 34 | { 35 | ++VV; 36 | DFS (i); 37 | } 38 | } 39 | g< 2 | # define NMAX 100005 3 | using namespace std; 4 | ifstream fin("aimin.in"); 5 | ofstream fout("aimin.out"); 6 | int n,k,L[NMAX],H[NMAX]; 7 | int main() 8 | { 9 | int i; 10 | fin>>n; 11 | for (i=1;i<=n;++i) 12 | fin>>L[i]; 13 | if (n==1) 14 | { 15 | fout<0 && H[k]<=1+max(L[i],H[k+1])) 22 | H[k+1]=0, --k; 23 | 24 | H[++k]=1+max(L[i],H[k]); 25 | H[k+1]=L[i]; 26 | } 27 | fout< 2 | # include 3 | using namespace std; 4 | ifstream f("euclid3.in"); 5 | ofstream g("euclid3.out"); 6 | int a, b, c, i, T; 7 | int euclid (int a, int b, int &x, int &y) { 8 | if (b==0) { 9 | x=1; y=0; 10 | return a; 11 | } 12 | int x0, y0, D; 13 | D=euclid (b, a%b, x0, y0); 14 | x=y0; 15 | y=x0 - (a/b)*y0; 16 | return D; 17 | } 18 | int main () 19 | { 20 | f>>T; 21 | while (T--) { 22 | f>>a>>b>>c; 23 | int x, y, D; 24 | D=euclid (a, b, x, y); 25 | if (c%D==0) g< 2 | using namespace std; 3 | ifstream f("test.in"); 4 | ofstream g("test.out"); 5 | int i,j,n,m,mask,mask1; 6 | void descompune (int k) { 7 | for (int i=5; i>=0; --i) 8 | if (k & (1<>mask; 15 | descompune(mask); g<<"\n"; 16 | for(mask1=mask; mask1; mask1=(mask1-1)&(mask)) 17 | descompune(mask1); 18 | 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /aria.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define NR 100005 3 | using namespace std; 4 | ifstream f("aria.in"); 5 | ofstream g("aria.out"); 6 | int i,j,n,m; 7 | double x[NR], y[NR], arie; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) { 12 | f>>x[i]>>y[i]; 13 | } 14 | y[n+1]=y[1]; x[n+1]=x[1]; 15 | 16 | for (i=1; i<=n; ++i) { 17 | arie=arie + (x[i] * y[i+1] - x[i+1] * y[i]); 18 | } 19 | 20 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | vector v[20000]; 6 | int i,j,n,x,y,maxx; 7 | int val[20005], ap[20005]; 8 | void DFS (int k) 9 | { 10 | ap[k]=1; 11 | for (int i=0; ival[k]) val[k]+=val[v[k][i]]; 17 | } 18 | } 19 | maxx=max(maxx, val[k]); 20 | } 21 | int main () 22 | { 23 | freopen ("asmax.in", "r", stdin); 24 | freopen ("asmax.out", "w", stdout); 25 | scanf ("%d", &n); 26 | for (i=1; i<=n; ++i) 27 | scanf ("%d", &val[i]); 28 | maxx=val[1]; 29 | for (i=1; i 2 | # define NR 1005 3 | # define mp make_pair 4 | # define f first 5 | # define s second 6 | using namespace std; 7 | ifstream f("autostrazi2.in"); 8 | ofstream g("autostrazi2.out"); 9 | vector v[NR]; 10 | int i,j,n,m,x,y,VV; 11 | int cuplat[NR]; 12 | pair sol[NR]; 13 | int main () 14 | { 15 | f>>n>>m; 16 | for (i=1; i<=m; ++i) { 17 | f>>x>>y; 18 | v[x].push_back(y); 19 | v[y].push_back(x); 20 | } 21 | for (i=1; i<=n; ++i) 22 | if (! cuplat[i]) { 23 | for (j=0; j 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /baloane1.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("baloane.in"); 5 | ofstream g("baloane.out"); 6 | int i,j,n,m,VV; 7 | int maxx,x,r; 8 | struct elem 9 | { 10 | int x,y; 11 | }v[100005]; 12 | bool cmp (elem x, elem y) 13 | { 14 | if (x.x>y.x) return 0; 15 | else if (x.x==y.x && x.y>=y.y) return 0; 16 | else return 1; 17 | } 18 | int main () 19 | { 20 | f>>n; 21 | for (i=1; i<=n; ++i) 22 | { 23 | f>>x>>r; 24 | v[i].x=x-r; v[i].y=x+r; 25 | } 26 | sort (v+1, v+n+1, cmp); 27 | maxx=v[1].y; VV=1; 28 | for (i=2; i<=n; ++i) 29 | { 30 | if (v[i].x 2 | # include 3 | using namespace std; 4 | ifstream f("balulbobocilor.in"); 5 | ofstream g("balulbobocilor.out"); 6 | float v1,v2,x,y,D,V,T; 7 | int main () 8 | { 9 | f>>D; 10 | f>>v1>>x>>y; 11 | f>>v2>>x>>y; 12 | f>>V; 13 | 14 | T=D/(v1+v2); 15 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /barfa.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | using namespace std; 5 | int 6 | int main () 7 | { 8 | freopen ("barfa.in", "r", stdiin); 9 | freopen ("barfa.out", "w", stdout); 10 | 11 | 12 | 13 | scanf ("%d", &T); 14 | scanf ("%d%d", &A, &B); 15 | for (int t=1; t<=T; ++i) { 16 | if (t!=1) { 17 | A=(A*i)%1000003; B=(Bi*i)%1000003; 18 | } 19 | } 20 | 21 | 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /basket.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | long long a[304][304]; 5 | int i, j, m, n, p, t; 6 | void generare(int p) 7 | { 8 | int i, j; 9 | a[1][1]=1; 10 | for(i=2; i<=300; ++i) 11 | for(j=1; j<=i; ++j) 12 | a[i][j]=(j*a[i-1][j]+(i-j+1)*a[i-1][j-1])%p; 13 | } 14 | int main() 15 | { 16 | freopen ("basket.in", "r", stdin); 17 | freopen ("basket.out", "w", stdout); 18 | scanf("%d%d", &t, &p); 19 | generare(p); 20 | for(int k=1; k<=t; ++k) 21 | { 22 | scanf("%d%d", &n, &m); 23 | printf("%d\n", a[n][m+1]); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /ben.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define MOD 32173 4 | # define NR 30005 5 | using namespace std; 6 | ifstream f("ben.in"); 7 | ofstream g("ben.out"); 8 | int i,j,n,m,x,y,ci,cs,CS,K,rez; 9 | int mars[NR], A[NR], incep[NR]; 10 | int aranjamente (int n, int k) 11 | { 12 | int rez=1; 13 | for (int i=n-k+1; i<=n; ++i) 14 | rez=rez*i%MOD; 15 | 16 | return rez; 17 | } 18 | int main () 19 | { 20 | f>>n; 21 | for (i=1; i<=n; ++i) { 22 | f>>ci>>cs; CS=max(CS, cs); 23 | 24 | ++mars[ci]; --mars[cs+1]; 25 | ++incep[ci]; 26 | } 27 | 28 | for (i=1; i<=CS; ++i) { 29 | A[i]=A[i-1] + mars[i]; 30 | K=max(K, A[i]); 31 | } 32 | 33 | rez=1; 34 | for (i=1; i<=CS; ++i) 35 | if (incep[i]) { 36 | rez=rez * aranjamente (K - (A[i] - incep[i]), incep[i]); 37 | rez%=MOD; 38 | } 39 | g< 2 | # include 3 | # include 4 | # define mil 1000005 5 | using namespace std; 6 | ifstream f("berarii2.in"); 7 | ofstream g("berarii2.out"); 8 | vector v[mil]; 9 | queue q; 10 | int i,j,n,m,x,y,p; 11 | bool bere[mil],ap[mil]; 12 | void BFS () 13 | { 14 | int i,k; 15 | while (! q.empty()) 16 | { 17 | k=q.front(); q.pop(); 18 | for (i=0; i>n>>m>>p; 31 | for (i=1; i<=m; ++i) 32 | { 33 | f>>x>>y; 34 | v[y].push_back(x); 35 | } 36 | for (i=1; i<=p; ++i) 37 | { 38 | f>>x; 39 | q.push(x); ap[x]=1; bere[x]=1; 40 | } 41 | BFS (); 42 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("br.in"); 5 | ofstream g("br.out"); 6 | int a[50000],s[50000]; 7 | int i,j,n,m,ind,bani,*x,poz,VV; 8 | int main () 9 | { 10 | f>>n>>m; 11 | for (i=1; i<=n; ++i) 12 | { 13 | f>>a[i]; 14 | a[n+i]=a[i]; 15 | } 16 | for (i=1; i<=2*n; ++i) 17 | s[i]=s[i-1]+a[i]; 18 | 19 | for (i=1; i<=m; ++i) 20 | { 21 | f>>ind>>bani; 22 | bani+=s[ind-1]; 23 | x=upper_bound(s+1,s+2*n+1,bani); 24 | poz=x-s-1; 25 | VV=poz-ind+1; 26 | if (VV>n) g<0) g< 2 | # include 3 | # include 4 | # define mod 666013 5 | # define NR 3005 6 | using namespace std; 7 | ifstream f("bete2.in"); 8 | ofstream g("bete2.out"); 9 | vector HASH[mod]; 10 | int i,j,n,m,x,y,S,k,VV; 11 | int a[NR]; 12 | int main () 13 | { 14 | f>>n; 15 | for (i=1; i<=n; ++i) 16 | { 17 | f>>a[i]; k=a[i]%mod; 18 | HASH[k].push_back(a[i]); 19 | } 20 | for (i=1; i<=n; ++i) 21 | for (j=i+1; j<=n; ++j) 22 | { 23 | S=a[i]+a[j]; k=S%mod; 24 | if (find(HASH[k].begin(), HASH[k].end(), S) != HASH[k].end()) ++VV; 25 | } 26 | g< 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | ifstream f("bfs.in"); 7 | ofstream g("bfs.out"); 8 | vector a[100010]; 9 | queue q; 10 | int i,j,n,m,x,y,start,cost[100010]; 11 | void bfs (int start) 12 | { 13 | int i; 14 | memset(cost,-1,sizeof(cost)); 15 | 16 | cost[start]=0; 17 | q.push(start); 18 | 19 | while (! q.empty()) 20 | { 21 | x=q.front (); q.pop (); 22 | for (i=0; i>n>>m>>start; 35 | for (i=1; i<=m; ++i) 36 | { 37 | f>>x>>y; 38 | a[x].push_back(y); 39 | } 40 | 41 | bfs(start); 42 | 43 | for (i=1; i<=n; ++i) 44 | g< 2 | # include 3 | using namespace std; 4 | int 5 | int main () 6 | { 7 | freopen ("bile2.in", "r", stdin); 8 | freopen ("bile2.out", "w", stdout); 9 | scanf ("%d%d", &n, &m); 10 | for (i=1; i<=n; ++i) { 11 | scanf ("%d", &tip); 12 | } 13 | 14 | 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /bile4.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | int st[100],n,K; 5 | void back (int k) 6 | { 7 | int i; 8 | if (k==K+1) 9 | { 10 | for (i=1; i<=K; ++i) 11 | printf ("%d ", st[i]); 12 | printf ("\n"); 13 | } 14 | else { 15 | for (i=st[k-1]+1; i<=n; ++i) 16 | { 17 | st[k]=i; 18 | back(k+1); 19 | st[k]=0; 20 | } 21 | } 22 | } 23 | int main () 24 | { 25 | freopen ("bile4.in", "r", stdin); 26 | freopen ("bile4.out", "w", stdout); 27 | 28 | scanf ("%d%d", &n, &K); 29 | 30 | back (1); 31 | 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /bilete1.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("bilete.in"); 5 | ofstream g("bilete.out"); 6 | int i,n,K,nr[10],x,y,patrate,ok,NR,NR2; 7 | int ap[1000000],st[5]; 8 | void back (int k) 9 | { 10 | int i; 11 | if (k==K+1) 12 | { 13 | NR=0; NR2=0; 14 | for (i=1; i<=K; ++i) 15 | { 16 | x=(st[i]-1)/n+1; y=(st[i]-1)%n+1; 17 | NR=NR*10+x; NR=NR*10+y; 18 | nr[i]=x*10+(n-y+1); 19 | } 20 | sort (nr+1,nr+K+1); 21 | for (i=1; i<=K; ++i) 22 | NR2=NR2*100+nr[i]; 23 | 24 | ap[min(NR,NR2)]=1; 25 | } 26 | else 27 | { 28 | for (i=st[k-1]+1; i<=patrate+k-K; ++i) 29 | { 30 | st[k]=i; 31 | back(k+1); 32 | } 33 | } 34 | } 35 | int main () 36 | { 37 | f>>n>>K; 38 | patrate=n*n; 39 | back(1); 40 | for (i=1; i<=1000000; ++i) 41 | if (ap[i]) g< 2 | using namespace std; 3 | ifstream f("bipal.in"); 4 | ofstream g("bipal.out"); 5 | int 6 | int main () 7 | { 8 | f>>n>>m; 9 | 10 | 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /bitonic.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define NR 1005 3 | using namespace std; 4 | ifstream f("bitonic.in"); 5 | ofstream g("bitonic.out"); 6 | int i,j,n,m,x,y,nr1,nr2,t,teste,maxx; 7 | int a[NR]; 8 | int main () 9 | { 10 | f>>teste; 11 | 12 | for (t=1; t<=teste; ++t) 13 | { 14 | f>>n; maxx=1; 15 | for (i=1; i<=n; ++i) 16 | f>>a[i]; 17 | 18 | for (i=1; i<=n; ++i) 19 | { 20 | nr1=0; nr2=0; 21 | // > > 0 < < 22 | for (j=i-1; j>=1; --j) if (a[j]>a[j+1]) ++nr1; 23 | for (j=i+1; j<=n; ++j) if (a[j]>a[j-1]) ++nr2; 24 | maxx=max(maxx, nr1+nr2+1); 25 | 26 | nr1=0; nr2=0; 27 | // < < 0 > > 28 | for (j=i-1; j>=1; --j) if (a[j] 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("branza.in"); 7 | ofstream g("branza.out"); 8 | deque d; 9 | int i,j,n,m,S,T; 10 | int c[NR], p[NR]; 11 | long long cost; 12 | int main () 13 | { 14 | f>>n>>S>>T; 15 | 16 | for (i=1; i<=n; ++i) 17 | { 18 | f>>c[i]>>p[i];//costul si productia 19 | while (! d.empty() && 1LL*c[i]<=1LL*c[d.back()]+1LL*S*(i-d.back())) 20 | d.pop_back(); 21 | 22 | d.push_back(i); 23 | if (d.front()==i-T-1) d.pop_front(); 24 | cost+=(1LL*p[i]*c[d.front()]+1LL*S*p[i]*(i-d.front())); 25 | } 26 | g< 2 | # include 3 | # define MOD 30103 4 | # define NR 1050 5 | using namespace std; 6 | ifstream f("bsir.in"); 7 | ofstream g("bsir.out"); 8 | int i,j,n,m,ci,cs,SOL; 9 | int v[NR], a[NR][NR]; 10 | int descompunere (int k) 11 | { 12 | int nr=0; 13 | while (k) 14 | { 15 | int r=k%2; 16 | nr+=r; 17 | k=k/2; 18 | } 19 | 20 | return nr%2; 21 | } 22 | int main () 23 | { 24 | f>>n; 25 | for (i=1; i<=n; ++i) 26 | v[i]=descompunere (i-1); 27 | 28 | for (i=1; i<=n; ++i) 29 | a[i][i]=1; 30 | 31 | for (i=2; i<=n; ++i) //fiecare lungime de palindrom 32 | for (j=1; j<=n-i+1; ++j) { 33 | ci=j; cs=j+i-1; 34 | if (v[ci]==v[cs]) { 35 | if (i==2) a[ci][cs]=1; 36 | else a[ci][cs]=a[ci+1][cs-1]; 37 | 38 | SOL=(SOL+a[ci][cs])%MOD; 39 | } 40 | } 41 | 42 | 43 | 44 | g< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | ifstream f("buget.in"); 6 | ofstream g("buget.out"); 7 | int i,j,n,m,P[NR],ci,cs,mij,maxx; 8 | long long B,suma,sol; 9 | long long verifica (int H) 10 | { 11 | long long S=0; 12 | for (int i=1; i<=n; ++i) 13 | S=S+min(H, P[i]); 14 | return S; 15 | } 16 | int main () 17 | { 18 | f>>n>>B; 19 | for (i=1; i<=n; ++i) { 20 | f>>P[i]; 21 | maxx=max(maxx, P[i]); 22 | } 23 | ci=1; cs=maxx; 24 | while (ci<=cs) { 25 | mij=(ci+cs)/2; 26 | suma=verifica(mij); 27 | if (suma<=B) ci=mij+1, sol=mij; 28 | else cs=mij-1; 29 | } 30 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("calatorie.in"); 5 | ofstream g("calatorie.out"); 6 | int a[200][200],b[200][200] 7 | int main () 8 | { 9 | f>>x>>k; 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | f>>v[i]; 13 | sort (v+1,v+n+1); VV=1; 14 | a[1][1]=1; b[1][1]=1; 15 | J=1; 16 | for (i=2; i<=x; ++i) 17 | { 18 | ++J; 19 | for (j=max(1,i-k); j<=i+k; ++j) 20 | { 21 | if (v[VV]==i && j==J) ++VV; 22 | { 23 | for (q=1; q<=k; ++q) b[i] 24 | } 25 | b[i][j] 26 | } 27 | } 28 | 29 | 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /caluti.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 100005 6 | using namespace std; 7 | ifstream f("caluti.in"); 8 | ofstream g("caluti.out"); 9 | deque d; 10 | int i,j,n,m,x,y,K,T; 11 | long long start[NR], a[NR], timp; 12 | int main () 13 | { 14 | f>>T; 15 | 16 | // a[i] - timpul minim pentru a duce toti calutii inclusiv i 17 | 18 | for (int t=1; t<=T; ++t) { 19 | f>>n>>K>>timp; d.clear(); 20 | d.push_back(0); memset (a, 0, sizeof(a)); 21 | 22 | for (i=1; i<=n; ++i) { 23 | f>>start[i]; 24 | a[i]=max(a[d.front()], start[i]) + timp; 25 | 26 | while (!d.empty() && a[i]<=a[d.back()]) 27 | d.pop_back(); 28 | d.push_back(i); 29 | 30 | if (d.front()==i-K) d.pop_front(); 31 | } 32 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("camion.in"); 5 | ofstream g("camion.out"); 6 | int i,j,n,m,k,c,X; 7 | int x[30005],y[30005],y2[30005],x2[30005]; 8 | int main () 9 | { 10 | f>>n>>m>>k>>c; 11 | for (i=1; i<=k; ++i) 12 | f>>x[i]>>y[i]>>x2[i]>>y2[i]; 13 | 14 | for (i=1; i<=n; ++i) 15 | { 16 | X=c; 17 | for (j=k; j>=1; --j) 18 | { 19 | if (x[j]<=i && i<=x2[j]) 20 | { 21 | if (X>=y[j]) X=X+y2[j]-y[j]+1; 22 | } 23 | } 24 | if (X>m) g<<"0\n"; 25 | else g< 2 | # define NR 100 3 | # define MOD 30211 4 | using namespace std; 5 | ifstream f("carry.in"); 6 | ofstream g("carry.out"); 7 | int st[NR], a[NR], i,j,SOL,n,K; 8 | char s[NR]; 9 | int verifica () { 10 | int sol=0, t=0; 11 | for (int i=n; i>=1; --i) { 12 | t=t + st[i] + a[i]; 13 | t=t/10; 14 | if (t) ++sol; 15 | } 16 | if (sol==K) ++SOL; 17 | } 18 | void back (int k) { 19 | if (k==n+1) { 20 | verifica (); 21 | } else { 22 | int start; 23 | if (k==1) start=1; 24 | else start=0; 25 | 26 | for (int i=start; i<=9; ++i) { 27 | st[k]=i; 28 | back(k+1); 29 | } 30 | } 31 | } 32 | int main () 33 | { 34 | f>>n>>K; f.get(); 35 | f.getline (s+1, NR); 36 | for (i=1; i<=n; ++i) 37 | a[i]=s[i]-'0'; 38 | 39 | back(1); 40 | g< 2 | 3 | using namespace std; 4 | int n,i,j,a[30][30]; 5 | int main() 6 | { 7 | cin>>n; 8 | for(i=1;i<=n;i++) 9 | { 10 | for(j=1;j<=n;j++) 11 | { 12 | a[i][j]=n-j+1; 13 | if(i==j) a[i][j]=0; 14 | cout< 3 | # define MOD 666013 4 | using namespace std; 5 | ifstream f("cerc.in"); 6 | ofstream g("cerc.out"); 7 | int k; 8 | long long sol,N,x1,x2,x3; 9 | int main () 10 | { 11 | f>>N; 12 | for (k=4; k<=N; ++k) { 13 | x1=k-3; x2=k-2; x3=k-1; 14 | 15 | if (x1%3==0) x1/=3; 16 | else if (x2%3==0) x2/=3; 17 | else if (x3%3==0) x3/=3; 18 | 19 | sol=(sol +x1%MOD*x2%MOD*x3%MOD)%MOD; 20 | } 21 | 22 | g<<(sol+N)%MOD<<"\n"; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /cerere.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("cerere.in"); 7 | ofstream g("cerere.out"); 8 | vector v[NR]; 9 | int i,j,n,m,x,y,S,VV; 10 | int st[NR], sol[NR], ki[NR], in[NR]; 11 | void DFS (int k) 12 | { 13 | st[++VV]=k; 14 | if (ki[k]==0) sol[k]=0; 15 | else sol[k]=1+sol[st[VV-ki[k]]]; 16 | for (int i=0; i>n; 23 | for (i=1; i<=n; ++i) 24 | f>>ki[i]; 25 | for (i=1; i>x>>y; v[x].push_back(y); 28 | ++in[y]; 29 | } 30 | for (i=1; i<=n; ++i) 31 | if (!in[i]) {S=i; break;} 32 | 33 | DFS (S); 34 | 35 | for (i=1; i<=n; ++i) 36 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("Struct.in"); 5 | ofstream g("Struct.out"); 6 | struct elevi 7 | { 8 | float media; 9 | char nume[30]; 10 | }; 11 | elevi a[30]; 12 | int n,i,j,k; 13 | char s[]="Cezara e dragutica si baietelul ei o iubeste !"; 14 | int main() 15 | {f>>n; 16 | for(k=1;k<=n;k++) 17 | { 18 | f>>a[k].media; 19 | f.get(); f>>a[k].nume; 20 | } 21 | for(i=1;i<=n-1;i++) 22 | for(j=i+1;j<=n;j++) 23 | if(a[i].media>a[j].media) 24 | {a[0]=a[i]; 25 | a[i]=a[j]; 26 | a[j]=a[0]; 27 | } 28 | for(i=1;i<=n;i++) 29 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /chiftea.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("chiftea.in"); 5 | ofstream g("chiftea.out"); 6 | int i,j,n,m,t,rad,x; 7 | int main () 8 | { 9 | f>>t; 10 | for (i=1; i<=t; ++i) 11 | { 12 | f>>x; 13 | rad=sqrt((double)x); 14 | if (rad*rad==x) g<<4*rad<<"\n"; 15 | else { 16 | if (x-rad*rad<=rad) g<<4*rad+2<<"\n"; 17 | else g<<4*rad+4<<"\n"; 18 | } 19 | } 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /cmlsc.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 1025 6 | using namespace std; 7 | ifstream f("cmlsc.in"); 8 | ofstream g("cmlsc.out"); 9 | int i,j,n,m,x,y,I,J,VV; 10 | int a[NR], b[NR], maxx[NR][NR], sol[NR]; 11 | int main () 12 | { 13 | f>>n>>m; 14 | for (i=1; i<=n; ++i) f>>a[i]; 15 | for (i=1; i<=m; ++i) f>>b[i]; 16 | 17 | for (i=1; i<=n; ++i) 18 | for (j=1; j<=m; ++j) 19 | if (a[i]==b[j]) maxx[i][j]=maxx[i-1][j-1] + 1; 20 | else maxx[i][j]=max(maxx[i-1][j], maxx[i][j-1]); 21 | 22 | I=n; J=m; 23 | while (J!=0 && I!=0) { 24 | if (a[I]==b[J]) { 25 | sol[++VV]=a[I]; 26 | --I; --J; 27 | } else { 28 | if (maxx[I-1][J] > maxx[I][J-1]) --I; 29 | else --J; 30 | } 31 | } 32 | g<=1; --i) 34 | g< 2 | # include 3 | # define NR 1000005 4 | # define MOD 666013 5 | # define Q 26 6 | using namespace std; 7 | ifstream f("cntper.in"); 8 | ofstream g("cntper.out"); 9 | int i,j,n,x,I; 10 | int sol[NR]; 11 | long long Minus[NR]; 12 | void procesare () 13 | { 14 | I=1; 15 | for (i=1; i<=NR-5; ++i) { 16 | I=(I*Q)%MOD; 17 | sol[i]=(MOD + I - Minus[i]%MOD)%MOD; 18 | 19 | for (j=2; i*j<=NR-5; ++j) { 20 | Minus[i*j]+=sol[i]; 21 | } 22 | } 23 | } 24 | int main () 25 | { 26 | procesare (); 27 | 28 | f>>n; 29 | for (i=1; i<=n; ++i) { 30 | f>>x; 31 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("cocochanel.in"); 5 | ofstream g("cocochanel.out"); 6 | int i,j,n,m,ci,VV,var,ant,Q; 7 | int put[50], C[100005], G[100005]; 8 | void puteri () 9 | { 10 | int i; 11 | put[0]=1; 12 | for (i=1; i<=30; ++i) 13 | put[i]=put[i-1]<<1; 14 | } 15 | int main () 16 | { 17 | f>>n>>m; 18 | for (i=1; i<=n; ++i) 19 | f>>C[i]; 20 | for (i=1; i<=m; ++i) 21 | f>>G[i]; 22 | sort (G+1, G+m+1); 23 | puteri (); 24 | for (i=1; i<=n; ++i) 25 | { 26 | ci=1; VV=0; ant=0; 27 | for (j=0; j<=30; ++j) 28 | { 29 | Q=C[i]*put[j]; 30 | if (Q>G[m] || ci>m) break; 31 | var=lower_bound (G+ci, G+m+1, Q)-G; 32 | ++VV; 33 | ci=var+1; 34 | } 35 | g< 2 | # include 3 | # include 4 | # define NR 500000 5 | using namespace std; 6 | 7 | int i, a[NR], n; 8 | long long A, S; 9 | int main () 10 | { 11 | cin>>n>>A; 12 | 13 | for (i=1; i<=n; ++i) 14 | { 15 | cin>>a[i]; S=S+a[i]; 16 | } 17 | 18 | if (n==1) 19 | { 20 | cout<A) 32 | { 33 | int suma=n-1; 34 | maxx=A-suma; 35 | nr=nr + (a[i]-maxx); 36 | } 37 | 38 | cout< 2 | # include 3 | using namespace std; 4 | int i,j,n,VV; 5 | int a[5005]; 6 | int main () 7 | { 8 | cin>>n; 9 | if (n==3) 10 | { 11 | cout<<"2\n1 3\n"; 12 | } 13 | else if (n==2) 14 | { 15 | cout<<"1\n1\n"; 16 | } 17 | else if (n==4) 18 | { 19 | cout<<"4\n3 1 4 2\n"; 20 | } 21 | else 22 | { 23 | for (i=1; i<=n; i+=2) 24 | a[++VV]=i; 25 | for (i=2; i<=n; i+=2) 26 | a[++VV]=i; 27 | cout< 2 | # include 3 | using namespace std; 4 | int 5 | int mian () 6 | { 7 | freopen ("codetoss.in", "r", stdin); 8 | freopen ("codetoss.out", "w", stdout); 9 | 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /color infoarena.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | ifstream f("color.in"); 4 | ofstream g("color.out"); 5 | int i,j,m,x,y,R[10000]; 6 | long long VV, var, n; 7 | int main () 8 | { 9 | f>>n>>m; 10 | for (i=1; i<=m; ++i) 11 | { 12 | f>>x>>y; 13 | ++R[x]; ++R[y]; 14 | } 15 | VV=n*(n-1)*(n-2)/6; 16 | for (i=1; i<=n; ++i) 17 | var=var+R[i]*(n-1-R[i]); 18 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("coment.in"); 6 | ofstream g("coment.out"); 7 | vector v[105]; 8 | int ap[105],stiva[105]; 9 | int i,j,n,m,x,y,st,ok; 10 | void DFS (int k) 11 | { 12 | int i; 13 | if (!ok) 14 | { 15 | ap[k]=1; stiva[++st]=k; 16 | if (st==n) ok=1; 17 | for (i=0; i>n; 25 | while (f>>x>>y) 26 | v[x].push_back(y); 27 | 28 | ok=0; 29 | DFS(1); 30 | for (i=1; i<=n; ++i) 31 | g< 2 | # include 3 | # define NR 1000005 4 | using namespace std; 5 | ifstream f("compact2.in"); 6 | ofstream g("compact2.out"); 7 | int i,j,n,m,x,y,maxx; 8 | int CI[NR], CS[NR], jos[NR], sus[NR]; 9 | int main () 10 | { 11 | f>>n; 12 | for (i=1; i<=n; ++i) { 13 | f>>x; 14 | 15 | CI[x]=1; jos[x]=x; 16 | CS[x]=1; sus[x]=x; 17 | 18 | if (CI[x+1]) {CI[x]=CI[x+1]+1; ++CS[jos[x+1]]; 19 | jos[x]=jos[x+1]; sus[jos[x+1]]=x;} 20 | 21 | if (CS[x-1]) {CS[x]=CS[x-1]+1; ++CI[sus[x-1]]; 22 | sus[x]=sus[x-1]; jos[sus[x-1]]=x;} 23 | 24 | maxx=max(maxx, CI[x]); 25 | maxx=max(maxx, CS[x]); 26 | } 27 | 28 | g< 2 | # include 3 | # include 4 | # include 5 | # define NR 1000005 6 | using namespace std; 7 | deque d; 8 | int i,j,n,m,x,y,maxx; 9 | int a[NR], MAX[NR]; 10 | int main () 11 | { 12 | freopen ("compus.in", "r", stdin); 13 | freopen ("compus.out", "w", stdout); 14 | scanf ("%d", &n); maxx=1; 15 | 16 | for (i=1; i<=n; ++i) 17 | { 18 | scanf ("%d", &a[i]); 19 | MAX[i]=max(MAX[i-1], a[i]); 20 | 21 | while (! d.empty() && a[i]1) 26 | { 27 | while (! d.empty() && d.front()<=i-i/2) d.pop_front(); 28 | 29 | int x=d.front(); 30 | 31 | if (MAX[i/2]<=a[(i+1)/2] && a[(i+1)/2]<=a[d.front()]) maxx=i; 32 | 33 | } 34 | } 35 | 36 | if (maxx==721461) printf ("721461\n"); 37 | else printf ("%d\n", maxx); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /costperm.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define LB(p) ((-p)&p) 4 | using namespace std; 5 | ifstream f("costperm.in"); 6 | ofstream g("costperm.out"); 7 | int i,j,n,x; 8 | long long AIB[100005], sol; 9 | long long suma (int poz) 10 | { 11 | long long S=0; 12 | for (int i=poz; i>=1; i-=LB(i)) 13 | S+=AIB[i]; 14 | return S; 15 | } 16 | void update (int poz) 17 | { 18 | for (int i=poz; i<=n; i+=LB(i)) 19 | ++AIB[i]; 20 | } 21 | int main () 22 | { 23 | f>>n; 24 | for (i=1; i<=n; ++i) 25 | { 26 | f>>x; 27 | sol=sol+1LL*x*(suma(n)-suma(x-1)); 28 | update (x); 29 | } 30 | g< 2 | # define MOD 10003 3 | # define maxx 600000000 4 | using namespace std; 5 | ifstream f("cover1.in"); 6 | ofstream g("cover1.out"); 7 | int n,p,a; 8 | int main () 9 | { 10 | f>>n; p=1; a=3; --n; 11 | while (n) 12 | { 13 | if (n%2==1) p=(p*a)%MOD,--n; 14 | else a=(a*a)%MOD,n=n/2; 15 | } 16 | 17 | g<<(2*p)%MOD; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /crescator.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("crescator.in"); 5 | ofstream g("crescator.out"); 6 | int i,j,n,sol,maxx,nr,s,ant,x; 7 | int main () 8 | { 9 | f>>n; 10 | for (i=1; i<=n; ++i) 11 | { 12 | f>>x; 13 | if (ant<=x) ++nr; 14 | else { 15 | sol=sol + nr*(nr+1)/2; 16 | maxx=max(maxx, nr); 17 | nr=1; 18 | } 19 | ant=x; 20 | } 21 | sol=sol + nr*(nr+1)/2; 22 | maxx=max(maxx, nr); 23 | 24 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("cristal.in"); 5 | ofstream g("cristal.out"); 6 | vector v[55]; 7 | int i,j,n,m,x,y,ok,NR,VV; 8 | int ap[100],sol[100]; 9 | void dfs (int k) 10 | { 11 | int i; 12 | ap[k]=ok; ++NR; 13 | for (i=0; i>n>>m; 21 | for (i=1; i<=m; ++i) 22 | { 23 | f>>x>>y; 24 | v[x].push_back(y); 25 | v[y].push_back(x); 26 | } 27 | for (i=1; i<=n; ++i) 28 | { 29 | ap[i]=i; ok=i; NR=0; 30 | if (i==1) dfs (2); 31 | else dfs(1); 32 | if (NR==n-1) sol[++VV]=i; 33 | } 34 | for (i=1; i<=VV; ++i) 35 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("cs.in"); 5 | ofstream g("cs.out"); 6 | int i,j,n,a[100005]; 7 | void inmultire (int k) 8 | { 9 | int i,t=0; 10 | for (i=1; i<=a[0]; ++i) 11 | { 12 | t=t+a[i]*k; 13 | a[i]=t%10; 14 | t=t/10; 15 | } 16 | 17 | while (t) a[++a[0]]=t%10, t=t/10; 18 | } 19 | int main () 20 | { 21 | f>>n; 22 | a[0]=a[1]=1; 23 | for (i=1; i<=n; ++i) 24 | inmultire (n); 25 | for (i=1; i<=n-1; ++i) 26 | inmultire (2); 27 | 28 | for (i=a[0]; i>=1; --i) 29 | g< 2 | using namespace std; 3 | int i,j,n,m,x,VV; 4 | int st[10005]; 5 | int main () 6 | { 7 | freopen ("culmi.in", "r", stdin); 8 | freopen ("culmi.out", "w", stdout); 9 | 10 | scanf ("%d", &n); 11 | st[0]=999999999; 12 | for (i=1; i<=n; ++i) 13 | { 14 | scanf ("%d", &x); 15 | if (x<=st[VV]) {st[++VV]=x; continue;} 16 | for (j=VV; j>=1; --j) 17 | if (x<=st[j-1]) 18 | { 19 | st[j]=x; 20 | break; 21 | } 22 | } 23 | printf ("%d\n", VV); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /culori.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define MOD 9901 5 | # define NR 600 6 | using namespace std; 7 | ifstream f("culori.in"); 8 | ofstream g("culori.out"); 9 | int i,j,n,m,len,dist,k; 10 | int a[NR], dp[NR][NR]; 11 | int main () 12 | { 13 | f>>n; len=2*n-1; 14 | for (i=1; i<=2*n-1; ++i) 15 | f>>a[i]; 16 | 17 | for (i=1; i<=len; ++i) dp[i][i]=1; 18 | 19 | for (dist=1; dist 2 | # include 3 | using namespace std; 4 | ifstream f("curcubeu.in"); 5 | ofstream g("curcubeu.out"); 6 | int i,n,x,y; 7 | int ccc[1000005], a[1000005], b[1000005], c[1000005], urm[1000005]; 8 | void color (int minn, int maxx, int col) 9 | { 10 | for (int i=minn; i<=maxx; ++i) 11 | { 12 | if (urm[i]) i=urm[i],--i; 13 | else { 14 | ccc[i]=col; 15 | urm[i]=maxx+1; 16 | } 17 | } 18 | } 19 | int main () 20 | { 21 | f>>n>>a[1]>>b[1]>>c[1]; 22 | for (i=2; i=1; --i) 29 | { 30 | x=min(a[i],b[i]); 31 | y=max(a[i],b[i]); 32 | color (x, y, c[i]); 33 | } 34 | for (i=1; i 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | ifstream f("darb.in"); 7 | ofstream g("darb.out"); 8 | vector v[100005]; 9 | int i,j,n,m,x,y,maxx,S; 10 | int ap[100005]; 11 | void DFS (int k, int niv) 12 | { 13 | ap[k]=1; 14 | if (niv>maxx) 15 | { 16 | maxx=niv; 17 | S=k; 18 | } 19 | for (int i=0; i>n; 27 | for (i=1; i<=n-1; ++i) 28 | { 29 | f>>x>>y; 30 | v[x].push_back(y); 31 | v[y].push_back(x); 32 | } 33 | DFS (1,0); 34 | maxx=0; memset(ap,0,sizeof(ap)); 35 | DFS (S,0); 36 | g< 2 | # define LB(p) ((-p) & p) 3 | using namespace std; 4 | ifstream f("datorii.in"); 5 | ofstream g("datorii.out"); 6 | int i,j,n,m,x,tip,zi,S,ci,cs; 7 | int AIB[15005]; 8 | void update (int poz, int val) 9 | { 10 | for (int i=poz; i<=n; i+=LB(i)) 11 | AIB[i]+=val; 12 | } 13 | int suma (int poz) 14 | { 15 | int sum=0; 16 | for (int i=poz; i>0; i-=LB(i)) 17 | sum+=AIB[i]; 18 | return sum; 19 | } 20 | int main () 21 | { 22 | f>>n>>m; 23 | for (i=1; i<=n; ++i) 24 | { 25 | f>>x; 26 | update (i, x); 27 | } 28 | for (i=1; i<=m; ++i) 29 | { 30 | f>>tip; 31 | if (tip==0) // se achita 32 | { 33 | f>>zi>>S; 34 | update(zi, -S); 35 | } 36 | else if (tip==1) 37 | { 38 | f>>ci>>cs; 39 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /deque.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # include 6 | # include 7 | # define LB(p) ((-p)&p) 8 | # define NR 5000005 9 | # define mod 1999999973 10 | using namespace std; 11 | deque d; 12 | ifstream f("deque.in"); 13 | ofstream g("deque.out"); 14 | int i,j,n,m,k; 15 | int a[NR]; 16 | long long S; 17 | int main () 18 | { 19 | f>>n>>k; 20 | 21 | for (i=1; i<=n; ++i) 22 | { 23 | f>>a[i]; 24 | while (! d.empty() && a[i]<=a[d.back()]) 25 | d.pop_back(); 26 | d.push_back(i); 27 | 28 | if (d.front()<=i-k) d.pop_front(); 29 | if (i>=k) S+=a[d.front()]; 30 | } 31 | g< 2 | # define NR 10005 3 | # define MOD 10007 4 | using namespace std; 5 | ifstream f("desc2.in"); 6 | ofstream g("desc2.out"); 7 | vector dp[NR]; 8 | int i,j,n,m,x,y,K; 9 | int main () 10 | { 11 | f>>n>>K>>x; 12 | 13 | n=n - 1LL*K*(K-1)*x/2; 14 | 15 | // dp[i][j] - numarul de moduri de a face suma i din j numere 16 | // dp[i][j] = dp[i-1][j-1] + dp[i-j][j] 17 | // dp[i][1]=1; 18 | dp[0].resize(K+2); 19 | for (i=1; i<=n; ++i) { 20 | dp[i].resize(K+2); 21 | dp[i][1]=1; 22 | if (i<=K) dp[i][i]=1; 23 | for (j=2; j<=min(i, K); ++j) 24 | dp[i][j]=(dp[i-1][j-1] + dp[i-j][j])%MOD; 25 | } 26 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("strtok.in"); 5 | ofstream g("strtok.out"); 6 | int i,j,n,l; 7 | char *p,s[100]; 8 | int main () 9 | { 10 | f.getline(s,100); 11 | char var[]=" ,.!?"; 12 | p=strtok(s,var); 13 | while (p) 14 | { 15 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("dfs.in"); 6 | ofstream g("dfs.out"); 7 | vector v[100005]; 8 | int ap[100005],L[100005]; 9 | int i,n,m,K,x,y; 10 | void DFS (int k) 11 | { 12 | int i; 13 | ap[k]=K; 14 | for (i=0; i>n>>m; 22 | for (i=1; i<=m; ++i) 23 | { 24 | f>>x>>y; 25 | v[x].push_back(y); 26 | v[y].push_back(x); 27 | } 28 | for (i=1; i<=n; ++i) 29 | { 30 | L[i]=v[i].size(); 31 | } 32 | for (i=1; i<=n; ++i) 33 | { 34 | if (ap[i]==0) 35 | { 36 | ++K; 37 | DFS (i); 38 | } 39 | } 40 | g< 2 | # include 3 | # include 4 | # include 5 | # include 6 | # define NR 100005 7 | using namespace std; 8 | ifstream f("darb.in"); 9 | ofstream g("darb.out"); 10 | vector v[NR]; 11 | int i,j,n,m,S,maxx,x,y; 12 | void DFS (int k, int niv, int tata) 13 | { 14 | if (niv>maxx) 15 | { 16 | S=k; 17 | maxx=niv; 18 | } 19 | for (int i=0; i>n; 25 | for (i=1; i>x>>y; 28 | v[x].push_back(y); 29 | v[y].push_back(x); 30 | } 31 | DFS (1, 1, 0); 32 | DFS (S, 1, 0); 33 | g< 2 | # define NR 100005 3 | using namespace std; 4 | ifstream f("darb.in"); 5 | ofstream g("darb.out"); 6 | vector v[NR]; 7 | int i,j,n,M,I,x,y; 8 | int ap[NR]; 9 | void DFS (int k, int N) { 10 | ap[k]=1; 11 | if (N > M) M=N, I=k; 12 | for (auto &x: v[k]) 13 | if (! ap[x]) DFS (x, N+1); 14 | } 15 | int main () 16 | { 17 | f>>n; 18 | for (i=1; i>x>>y; 20 | v[x].push_back(y); 21 | v[y].push_back(x); 22 | } 23 | DFS (1, 1); memset (ap, 0, sizeof(ap)); 24 | DFS (I, 1); 25 | g< 2 | # include 3 | # include 4 | # define NR 9005 5 | using namespace std; 6 | vector v[NR]; 7 | int i,j,n,m,maxx,S,VV,x,y; 8 | int sol[NR], in[NR]; 9 | void DFS (int k, int niv) 10 | { 11 | int i; 12 | if (v[k].size()) 13 | { 14 | for (i=0; i 2 | # include 3 | # include 4 | # include 5 | # include 6 | # define LB(p) ((-p)&p) 7 | # define NR 100005 8 | # define mod 1999999973 9 | using namespace std; 10 | vector v[NR]; 11 | ifstream f("disjoint.in"); 12 | ofstream g("disjoint.out"); 13 | int i,j,n,m,x,y,tip,Rx,Ry; 14 | int R[NR], H[NR]; 15 | int radacina (int k) 16 | { 17 | while (k!=R[k]) k=R[k]; 18 | return k; 19 | } 20 | int main () 21 | { 22 | f>>n>>m; 23 | for (i=1; i<=n; ++i) 24 | R[i]=i, H[i]=1; 25 | 26 | for (i=1; i<=m; ++i) 27 | { 28 | f>>tip>>x>>y; 29 | Rx=radacina (x); 30 | Ry=radacina (y); 31 | if (tip==1) //reunire 32 | { 33 | if (H[Rx]>H[Ry]) R[Ry]=Rx, H[Rx]+=H[Ry]; 34 | else R[Rx]=Ry, H[Ry]+=H[Rx]; 35 | } 36 | else { 37 | if (Rx==Ry) g<<"DA\n"; 38 | else g<<"NU\n"; 39 | } 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /distante.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | ifstream f("distante.in"); 4 | ofstream g("distante.out"); 5 | int i,j,n,m,x,y,c,o,ok,t,S; 6 | int dist[50005]; 7 | int main () 8 | { 9 | f>>t; 10 | for (o=1; o<=t; ++o) 11 | { 12 | f>>n>>m>>S; ok=1; 13 | for (i=1; i<=n; ++i) 14 | f>>dist[i]; 15 | for (i=1; i<=m; ++i) 16 | { 17 | f>>x>>y>>c; 18 | if (dist[x]+c 2 | # include 3 | # include 4 | # define N_Max 1000005 5 | using namespace std; 6 | ifstream f("divprim.in"); 7 | ofstream g("divprim.out"); 8 | vector v[8]; 9 | vector ::iterator x; 10 | int a[N_Max]; 11 | int i,j,n,nr,cat,poz; 12 | void ciur () 13 | { 14 | int i,j; 15 | for (i=2; i<=N_Max; ++i) 16 | { 17 | if (a[i]==0) 18 | { 19 | for (j=1; i*j<=N_Max; ++j) 20 | ++a[i*j]; 21 | } 22 | if (a[i]<=7) v[a[i]].push_back(i); 23 | } 24 | } 25 | int main () 26 | { 27 | ciur (); 28 | f>>n; 29 | for (i=1; i<=n; ++i) 30 | { 31 | f>>nr>>cat; 32 | x=lower_bound(v[cat].begin(), v[cat].end(), nr); 33 | poz=x-v[cat].begin(); 34 | if (poz==0) g<<"0\n"; 35 | else g< 2 | # include 3 | # include 4 | # define NR 105 5 | using namespace std; 6 | //ifstream cin("domimatrix.in"); 7 | //ofstream cout("domimatrix.out"); 8 | int i,j,n,m,x,y,VV,N; 9 | int mat[NR][NR], a[NR*NR]; 10 | int main () 11 | { 12 | cin>>n; N=n*n; 13 | for (i=1; i<=N; ++i) 14 | cin>>a[i]; 15 | 16 | sort (a+1, a+N+1); 17 | VV=N+1; 18 | for (i=1; i<=n; ++i) 19 | mat[i][i]=a[--VV]; 20 | 21 | for (i=1; i<=n; ++i) 22 | for (j=1; j<=n; ++j) 23 | if (i!=j) mat[i][j]=a[--VV]; 24 | 25 | 26 | for (i=1; i<=n; ++i) 27 | { 28 | for (j=1; j<=n; ++j) 29 | cout< 2 | 3 | const int NMAX = 1e6; 4 | 5 | int main() { 6 | freopen("domino2.in", "r", stdin); 7 | freopen("domino2.out", "w", stdout); 8 | int dif, last, n, i, j; 9 | 10 | scanf("%d", &n); 11 | if(n == 2) { 12 | printf("1 1\n1 2\n2 2\n"); 13 | return 0; 14 | } 15 | 16 | if(n % 2 == 0) { 17 | printf("-1\n"); 18 | return 0; 19 | } 20 | 21 | printf("1 1\n1 2\n2 2\n2 3\n3 3\n3 1\n"); 22 | 23 | for(i = 5; i <= n; i += 2) { 24 | printf("1 %d\n", i - 1); 25 | printf("%d %d\n", i - 1, i - 1); 26 | printf("%d %d\n", i - 1, i); 27 | printf("%d %d\n", i, i); 28 | 29 | dif = 0; 30 | for(j = i - 2; j >= 2; -- j) { 31 | printf("%d %d\n", i - dif, j); 32 | printf("%d %d\n", j, i - 1 + dif); 33 | 34 | dif = 1 - dif; 35 | } 36 | 37 | printf("%d 1\n", i); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /dominouri.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 100005 6 | using namespace std; 7 | ifstream f("dominouri.in"); 8 | ofstream g("dominouri.out"); 9 | vector v[NR]; 10 | int i,j,n,m,VV,x; 11 | int C[NR], cost[NR], nv[NR], var[NR]; 12 | void DFS (int k) { 13 | int COST=0; if (nv[k]==0) COST=1; 14 | for (int i=0; i>n; 29 | for (i=1; i<=n; ++i) { 30 | f>>nv[i]; 31 | for (j=1; j<=nv[i]; ++j) { 32 | f>>x; 33 | v[i].push_back(x); 34 | } 35 | } 36 | for (i=1; i<=n; ++i) 37 | f>>cost[i]; 38 | 39 | DFS(1); 40 | g< 2 | # include 3 | # define inf 999999999 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("ecluze.in"); 7 | ofstream g("ecluze.out"); 8 | int i,j,n,m; 9 | int minn[NR], last[NR], urm[NR], a[NR]; 10 | int main () 11 | { 12 | f>>n; 13 | for (i=1; i<=n; ++i) 14 | { 15 | f>>a[i]; 16 | minn[i]=inf; 17 | } 18 | 19 | for (i=n; i>=1; --i) 20 | if (last[a[i]]==0) last[a[i]]=i; 21 | else urm[i]=last[a[i]], last[a[i]]=i; 22 | 23 | minn[1]=0; 24 | for (i=1; i<=n; ++i) 25 | { 26 | if (i>1) minn[i]=min(minn[i], minn[i-1]+1); 27 | if (urm[i]) minn[urm[i]]=min(minn[urm[i]], minn[i] + (urm[i]-i-1)); 28 | } 29 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("ecuatie.in"); 5 | ofstream g("ecuatie.out"); 6 | int i,j,n,m,a,b,A,B,R,x,y,z; 7 | int st[5]; 8 | void back (int k) 9 | { 10 | if (k==4) 11 | { 12 | x=st[1]; y=st[2]; z=st[3]; 13 | if (B*(x*y+x*z+y*z)==A*x*y*z) 14 | { 15 | g<>a>>b; A=a; B=b; 31 | 32 | st[0]=1; 33 | back(1); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /efort.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | ifstream f("efort.in"); 4 | ofstream g("efort.out"); 5 | int i,j,n,m,K,x,dist; 6 | long long fib[20000],VV; 7 | void fibonacci () 8 | { 9 | int k=1; 10 | fib[0]=1; fib[1]=2; 11 | while (fib[k]+fib[k-1]<2000000000) 12 | fib[++k]=fib[k-1]+fib[k-2]; 13 | } 14 | int main () 15 | { 16 | f>>n>>K; 17 | fibonacci (); 18 | for (i=1; i<=n; ++i) 19 | { 20 | f>>x; 21 | dist+=x; 22 | if (dist>=K) 23 | { 24 | VV=VV+K; 25 | for (j=1; j<=dist-K; ++j) 26 | VV+=fib[j]; 27 | dist=0; 28 | } 29 | } 30 | g< 2 | # define NR 1000005 3 | using namespace std; 4 | ifstream f("elmaj.in"); 5 | ofstream g("elmaj.out"); 6 | int i,j,n,m,x,X,ap, a[NR]; 7 | int main () 8 | { 9 | f>>n; ap=0; 10 | for (i=1; i<=n; ++i) { 11 | f>>x; a[i]=x; 12 | if (ap==0) ap=1, X=x; 13 | else { 14 | if (X==x) ++ap; 15 | else --ap; 16 | } 17 | } 18 | 19 | f>>n; ap=0; 20 | for (i=1; i<=n; ++i) { 21 | if (X==a[i]) ++ap; 22 | } 23 | if (ap>=n/2+1) g< 2 | # include 3 | # include 4 | # include 5 | # include 6 | # define NR 1000005 7 | using namespace std; 8 | ifstream f("elmaj.in"); 9 | ofstream g("elmaj.out"); 10 | int i,j,n,nr,X,ap; 11 | int a[NR]; 12 | int main () 13 | { 14 | f>>n; 15 | for (i=1; i<=n; ++i) 16 | { 17 | f>>a[i]; 18 | if (nr==0) X=a[i], nr=1; 19 | else { 20 | if (a[i]==X) ++nr; 21 | else --nr; 22 | } 23 | } 24 | for (i=1; i<=n; ++i) 25 | if (a[i]==X) ++ap; 26 | 27 | if (ap>=n/2+1) g< 2 | using namespace std; 3 | ifstream f("elmaj.in"); 4 | ofstream g("elmaj.out"); 5 | int i,j,n,m,VV,maj,apmaj; 6 | int a[1000005]; 7 | int main () 8 | { 9 | f>>n; 10 | for (i=1; i<=n; ++i) 11 | { 12 | f>>a[i]; 13 | if (a[i]==maj) ++apmaj; 14 | else { 15 | if (apmaj==0) apmaj=1, maj=a[i]; 16 | else --apmaj; 17 | } 18 | } 19 | for (i=1; i<=n; ++i) 20 | if (a[i]==maj) ++VV; 21 | 22 | if (VV>=(n+1)/2) g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("energii.in"); 6 | ofstream g("energii.out"); 7 | int C[5005]; 8 | int n,G,i,j,E,cost; 9 | int main () 10 | { 11 | f>>n>>G; 12 | for (i=1; i<=G; ++i) C[i]=100000; 13 | for (i=1; i<=n; ++i) 14 | { 15 | f>>E>>cost; 16 | for (j=G; j>=1; --j) 17 | { 18 | if (E>=j) C[j]=min(C[j],cost); 19 | else C[j]=min(C[j],C[j-E]+cost); 20 | } 21 | } 22 | if (C[G]==100000) g<<"-1\n"; 23 | else g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("euclid3.in"); 6 | ofstream g("euclid3.out"); 7 | int i,t,a,b,c; 8 | int euclid (int a, int b, int &x, int &y) 9 | { 10 | if (b==0) 11 | { 12 | x=1; y=0; 13 | return a; 14 | } 15 | int D, x0, y0; 16 | D=euclid (b, a%b, x0, y0); 17 | x=y0; 18 | y=x0 - (a/b)*y0; 19 | return D; 20 | } 21 | int main () 22 | { 23 | f>>t; 24 | for (int i=1; i<=t; ++i) 25 | { 26 | f>>a>>b>>c; 27 | int D, x, y; 28 | D=euclid (a, b, x, y); 29 | 30 | if (c%D==0) g< 2 | # include 3 | using namespace std; 4 | ifstream f("euclid3.in"); 5 | ofstream g("euclid3.out"); 6 | int i,j,n,m,x,y,a,b,c; 7 | int euclid (int a, int b, int &x, int &y) 8 | { 9 | if (b==0) 10 | { 11 | x=1; y=0; 12 | return a; 13 | } 14 | 15 | int D, x0, y0; 16 | D=euclid (b, a%b, x0, y0); 17 | 18 | x=y0; 19 | y=x0 - (a/b)*y0; 20 | return D; 21 | } 22 | int main () 23 | { 24 | f>>n; 25 | for (i=1; i<=n; ++i) 26 | { 27 | f>>a>>b>>c; 28 | 29 | int x, y, D; 30 | D=euclid (a, b, x, y); 31 | 32 | if (c%D) g<<"0 0\n"; 33 | else g< 2 | # define LB(p) ((p)&(-p)) 3 | using namespace std; 4 | ifstream f("euclid2.in"); 5 | ofstream g("euclid2.out"); 6 | int i,j,n,m,a,b; 7 | int euclid (int a, int b) { 8 | if (b==0) return a; 9 | else return euclid (b, a%b); 10 | } 11 | int main () 12 | { 13 | f>>n; 14 | for (i=1; i<=n; ++i) { 15 | f>>a>>b; 16 | g< 2 | # define NR 550000 3 | using namespace std; 4 | ifstream f("euler.in"); 5 | ofstream g("euler.out"); 6 | int i,j,n,m,x,R,VV; 7 | int T[NR], st[NR]; 8 | int main () 9 | { 10 | f>>n; 11 | f>>x; R=x; st[++VV]=R;//radacina 12 | while (f>>x) 13 | { 14 | if (x==st[VV]) 15 | { 16 | g<<"NU\n"; 17 | return 0; 18 | } 19 | 20 | if (x==st[VV-1]) --VV; 21 | else { 22 | T[x]=st[VV]; 23 | st[++VV]=x; 24 | } 25 | } 26 | if (x==R && VV==1) 27 | { 28 | g<<"DA\n"; 29 | for (i=1; i<=n; ++i) 30 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | vector v[1005]; 6 | int i,j,o,n,m,VV,ok,K,x,y; 7 | int ap[1005][1005]; 8 | int main () 9 | { 10 | freopen ("exam.in", "r", stdin); 11 | freopen ("exam.out", "w", stdout); 12 | scanf ("%d%d", &n, &m); 13 | for (i=1; i<=m; ++i) 14 | { 15 | scanf ("%d%d", &x, &y); 16 | ap[x][y]=1; 17 | ap[y][x]=1; 18 | } 19 | for (i=1; i<=n; ++i) 20 | { 21 | ok=1; 22 | for (j=1; j<=VV; ++j) 23 | { 24 | K=1; 25 | for (o=0; o 2 | # include 3 | using namespace std; 4 | int i,j,n; 5 | long long minn; 6 | struct elem 7 | { 8 | long long a,b; 9 | }v[5005]; 10 | bool cmp (elem x, elem y) 11 | { 12 | if (x.a==y.a) return x.b>n; 18 | for (i=1; i<=n; ++i) 19 | cin>>v[i].a>>v[i].b; 20 | sort (v+1, v+n+1, cmp); 21 | minn=v[1].b; 22 | for (i=2; i<=n; ++i) 23 | { 24 | if (v[i].b>=minn) minn=v[i].b; 25 | else minn=v[i].a; 26 | } 27 | cout< 2 | # include 3 | using namespace std; 4 | ifstream f("expo.in"); 5 | ofstream g("expo.out"); 6 | int n; 7 | long long ci,cs,mij,S,H,L,minn; 8 | int main () 9 | { 10 | f>>H>>L>>n; 11 | ci=1; cs=n*max(H,L); 12 | while (ci<=cs) 13 | { 14 | mij=(ci+cs)/2; 15 | S=(mij/H)*(mij/L); 16 | if (S>=n) minn=mij, cs=mij-1; 17 | else ci=mij+1; 18 | } 19 | g< 2 | # include 3 | # include 4 | # define NR 1005 5 | using namespace std; 6 | ifstream f("expresie.in"); 7 | ofstream g("expresie.out"); 8 | int i,j,n,m,VV,S; 9 | char s[NR]; 10 | int numar () 11 | { 12 | int nr=0; 13 | while ('0'<=s[VV] && s[VV]<='9') 14 | { nr=nr*10+s[VV]-'0'; ++VV; } //include trecerea de ] 15 | return nr; 16 | } 17 | int base () 18 | { 19 | int nr=0; 20 | if (s[VV]=='[') //e un nou [ 21 | { 22 | while (s[VV]=='[') 23 | { 24 | ++VV; //trec direct peste '[' 25 | nr+=base(); 26 | } 27 | ++VV; //sa trec de ] 28 | } 29 | else //este numar 30 | { 31 | nr=numar(); 32 | ++VV; //trec de la un nou [ 33 | } 34 | return nr/2; 35 | } 36 | int main () 37 | { 38 | f.getline(s+1, NR); n=strlen(s+1); 39 | VV=1; 40 | while (VV<=n) 41 | { 42 | ++VV; //trec direct peste '[' 43 | S+=base (); 44 | } 45 | 46 | g< 2 | using namespace std; 3 | int a,b,c,maxx,i,v[10]; 4 | int main () 5 | { 6 | cin>>a>>b>>c; 7 | v[1]=a+b+c; 8 | v[2]=a*b*c; 9 | v[3]=(a+b)*c; 10 | v[4]=a*(b+c); 11 | v[5]=a+b*c; 12 | v[6]=a*b+c; 13 | for (i=1; i<=6; ++i) 14 | maxx=max(maxx,v[i]); 15 | cout< 2 | # include 3 | using namespace std; 4 | ifstream f("farfurii.in"); 5 | ofstream g("farfurii.out"); 6 | int i,j,n,k,t,T; 7 | int timp[10005], a[10005], b[10005], reper[10005]; 8 | int main () 9 | { 10 | f>>n>>t; 11 | for (i=1; i<=n; ++i) 12 | f>>timp[i]; 13 | for (k=1; k<=n; ++k) 14 | { 15 | for (i=1; i<=t; ++i) 16 | { 17 | if (i>=timp[k]+(k-1)) b[i]=max(a[i-1], a[i-timp[k]]+1); 18 | else b[i]=a[i-1]; 19 | reper[i]=max(reper[i], b[i]); 20 | } 21 | 22 | for (i=1; i<=t; ++i) 23 | { 24 | a[i]=b[i]; 25 | b[i]=0; 26 | } 27 | } 28 | for (i=1; i<=t; ++i) 29 | if (reper[i]==reper[t]) break; 30 | g< 2 | # include 3 | # define NR 20000 4 | using namespace std; 5 | struct elem 6 | { 7 | int D, maxx, pr; 8 | }a[1005]; 9 | bool cmp (elem x, elem y) 10 | { 11 | if (x.maxx>=y.maxx) return 0; 12 | else return 1; 13 | } 14 | int i,j,n,m,act,nou,maxx; 15 | int P[NR]; 16 | int main () 17 | { 18 | freopen ("fbr.in", "r", stdin); 19 | freopen ("fbr.out", "w", stdout); 20 | scanf ("%d", &n); 21 | for (i=1; i<=n; ++i) 22 | scanf ("%d%d%d", &a[i].D, &a[i].maxx, &a[i].pr); 23 | 24 | sort (a+1, a+n+1, cmp); 25 | P[0]=1; 26 | for (i=1; i<=n; ++i){ 27 | for (j=a[i].maxx-a[i].D; j>=0; --j) 28 | if (P[j] && P[j]+a[i].pr > P[j+a[i].D]) 29 | P[j+a[i].D]=P[j]+a[i].pr; 30 | } 31 | 32 | maxx=0; 33 | for (i=1; i<=NR-5; ++i) 34 | maxx=max(maxx, P[i]); 35 | printf ("%d\n", maxx-1); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /ferma.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 12000 4 | # define inf -999999999 5 | using namespace std; 6 | ifstream f("ferma.in"); 7 | ofstream g("ferma.out"); 8 | int i,j,n,m,k,maxx, maxi; 9 | int a[10005][1005], x[NR]; 10 | int main () 11 | { 12 | f>>n>>k; 13 | for (i=1; i<=n; ++i) f>>x[i]; 14 | 15 | //a[i][j] - suma maxima sa iei din primele i elemente j secvente 16 | for (i=0; i<=n; ++i) 17 | for (j=0; j<=k+1; ++j) 18 | a[i][j]=inf; 19 | a[0][0]=a[0][1]=a[1][0]=0; 20 | 21 | for (j=1; j<=k+1; ++j) 22 | { 23 | maxi=inf; 24 | for (i=1; i<=n; ++i) 25 | { 26 | if (i>=j) a[i][j]=x[i] + max(a[i-1][j], maxi); 27 | maxi=max(maxi, a[i][j-1]); 28 | } 29 | 30 | if (j==k) maxx=a[n][k]; 31 | if (j==k+1) maxx=max (maxx, a[n][k+1]); 32 | } 33 | if (maxx<0) g<<"0\n"; 34 | else g< 2 | using namespace std; 3 | ifstream f("football.in"); 4 | ofstream g("football.out"); 5 | int i,j,n,m,o,t,S,sol[50]; 6 | void procesare () 7 | { 8 | int i; 9 | sol[1]=1; sol[2]=1; sol[3]=1; sol[6]=1; 10 | for (i=1; i<=50; ++i) 11 | { 12 | sol[i]+=sol[i-1]; 13 | if (i>=2) sol[i]+=sol[i-2]; 14 | if (i>=3) sol[i]+=sol[i-3]; 15 | if (i>=6) sol[i]+=sol[i-6]; 16 | } 17 | } 18 | int main () 19 | { 20 | f>>t; 21 | procesare (); 22 | for (o=1; o<=t; ++o) 23 | { 24 | f>>S; 25 | g<<"Case "< 2 | # include 3 | # define mod 100003 4 | # define NR 2005 5 | using namespace std; 6 | int i,j,n,m,tip,nr,S; 7 | int a[NR][NR]; 8 | int main () 9 | { 10 | freopen ("fractii2.in", "r", stdin); 11 | freopen ("fractii2.out", "w", stdout); 12 | scanf ("%d%d", &tip, &n); 13 | if (tip==1) 14 | { 15 | for (i=1; i 2 | using namespace std; 3 | int testCASE,KK,c,s,i,number; 4 | int main() { 5 | freopen("test.in","r",stdin); 6 | freopen("test.out","w",stdout); 7 | scanf("%d",&testCASE); 8 | while(testCASE > 0) { 9 | --testCASE; ++number; 10 | scanf("%d%d%d", &KK, &c, &s); 11 | printf("Case #%d: ",number); 12 | for(i=1; i<=s; ++i) 13 | printf("%d ",i); 14 | printf("\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /fsb.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 200005 5 | # define Q 200000 6 | using namespace std; 7 | ifstream f("fsb.in"); 8 | ofstream g("fsb.out"); 9 | int i,j,n,m,VV,S,l; 10 | int ap[2*NR]; 11 | char s[NR]; 12 | int main () 13 | { 14 | f>>l; f.get(); 15 | f.getline(s+1, NR); 16 | for (i=1; i<=l; ++i) 17 | { 18 | if (s[i]=='1') ++S; 19 | else --S; 20 | 21 | ++ap[Q+S]; 22 | } 23 | VV=ap[Q]; 24 | for (i=1; i<=2*Q; ++i) 25 | VV=VV+ap[i]*(ap[i]-1)/2; 26 | 27 | g< 2 | #include 3 | #include 4 | using namespace std; 5 | int ok,l,i,ok2; 6 | char ch, s[256], s2[256],*p; 7 | int main() 8 | { 9 | cin.getline(s, 300); 10 | p=strtok(s," "); 11 | while(p) 12 | { 13 | strcpy(s2,p); 14 | ok=0; 15 | ok2=0; 16 | l=strlen(s2); 17 | for(i=0;i 2 | # include 3 | using namespace std; 4 | int i,j,n,a[2500],VV,nr; 5 | int main () 6 | { 7 | cin>>n; 8 | for (i=1; i<=n; ++i) 9 | cin>>a[i]; 10 | sort (a+1, a+n+1); 11 | 12 | VV=1; nr=a[n]; 13 | for (i=1; i 2 | # include 3 | # include 4 | # define NR 25 5 | using namespace std; 6 | ifstream f("date.in"); 7 | ofstream g("date.out"); 8 | int i,j,n,m,x,y; 9 | int NU[NR][NR]; 10 | int a[NR], sol; 11 | int main () 12 | { 13 | cin>>n>>m; 14 | for (i=1; i<=m; ++i) { 15 | cin>>x>>y; 16 | if (x>y) swap(x,y); 17 | 18 | NU[y][x]=1; 19 | } 20 | 21 | sol=1; 22 | // a[i] - numarul de pizze care se termian cu ingredientul i 23 | for (i=1; i<=n; ++i) { 24 | a[i]=1; 25 | for (j=1; j 2 | using namespace std; 3 | ifstream f("t.in"); 4 | ofstream g("t.out"); 5 | int n,m,i; 6 | int main () 7 | { 8 | f>>n>>m; 9 | g< 2 | # include 3 | using namespace std; 4 | int ok,gapdan,n,VV; 5 | int main() 6 | { 7 | cin>>n; 8 | ok=1; 9 | gapdan=n; 10 | 11 | while (ok) 12 | { 13 | ++VV; ++n; 14 | gapdan=max(n,-n); 15 | while (gapdan) 16 | { 17 | if (gapdan%10==8) 18 | { 19 | cout< 2 | # include 3 | using namespace std; 4 | int cmp (int x, int y) 5 | { 6 | if (x<=y) return 0; 7 | else return 1; 8 | } 9 | int i,n,pornire; 10 | int a[5005],start[5005],stop[5005]; 11 | int main () 12 | { 13 | freopen ("grade.in", "r", stdin); 14 | freopen ("grade.out", "w", stdout); 15 | scanf ("%d", &n); 16 | for (i=1; i<=n; ++i) 17 | scanf ("%d", &a[i]); 18 | sort (a+1,a+n+1, cmp); 19 | for (i=1; i<=n+1; ++i) 20 | { 21 | if (!start[a[i]]) start[a[i]]=i; 22 | if (a[i] 2 | using namespace std; 3 | int i,j,n,p,k,maxx,nr,x,y,q,var; 4 | int a[1005][1005]; 5 | int main () 6 | { 7 | freopen ("gradina.in", "r", stdin); 8 | freopen ("gradina.out", "w", stdout); 9 | 10 | scanf ("%d%d%d", &n, &p, &k); 11 | for (i=1; i<=p; ++i) 12 | { 13 | scanf ("%d%d", &x, &y); 14 | a[x][y]=1; 15 | } 16 | for (i=1; i<=n; ++i) 17 | for (j=1; j<=n; ++j) 18 | a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1]; 19 | 20 | for (i=k; i<=n; ++i) 21 | for (j=k; j<=n; ++j) 22 | { 23 | var=a[i][j]-a[i-k][j]-a[i][j-k]+a[i-k][j-k]; 24 | if (var>maxx) maxx=var, nr=1; 25 | else if (var==maxx) ++nr; 26 | } 27 | printf ("%d\n%d\n", maxx, nr); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /grammar.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define NR 1005 3 | using namespace std; 4 | //ifstream f("test.in"); 5 | //ofstream g("test.out"); 6 | int i,j,n,m,l; 7 | char s[NR]; 8 | int main () 9 | { 10 | cin.getline(s+1, NR); l=strlen(s+1); 11 | for (i=1; i<=l; ++i) { 12 | if (s[i]=='-' || s[i]=='.') continue; 13 | if (s[i]==',') {cout<<" ,"; continue;} 14 | 15 | cout< 2 | # include 3 | using namespace std; 4 | int i,j,n,m,maxx,VV; 5 | struct elem 6 | { 7 | int x,y; 8 | }a[20000]; 9 | bool cmp (elem x, elem y) 10 | { 11 | if (x.x>y.x) return 0; 12 | else if (x.x==y.x && x.y<=y.y) return 0; 13 | else return 1; 14 | } 15 | int main () 16 | { 17 | freopen ("granita.in", "r", stdin); 18 | freopen ("granita.out", "w", stdout); 19 | scanf ("%d", &n); 20 | for (i=1; i<=n; ++i) 21 | scanf ("%d%d", &a[i].x, &a[i].y); 22 | sort (a+1, a+n+1, cmp); 23 | 24 | maxx=a[1].y; 25 | for (i=2; i<=n; ++i) 26 | { 27 | if (a[i].y 2 | # include 3 | using namespace std; 4 | ifstream f("grarb.in"); 5 | ofstream g("grarb.out"); 6 | vector v[100005]; 7 | int i,j,n,m,x,y,conexe,maxx,nr; 8 | int ap[100005],niv[100005]; 9 | void DFS (int k) 10 | { 11 | ap[k]=1; 12 | for (int i=0; i>n>>m; 18 | for (i=1; i<=m; ++i) 19 | { 20 | f>>x>>y; 21 | v[x].push_back(y); 22 | v[y].push_back(x); 23 | } 24 | for (i=1; i<=n; ++i) 25 | { 26 | if (!ap[i]) 27 | { 28 | ++conexe; 29 | DFS (i); 30 | } 31 | } 32 | g< 2 | # include 3 | # define NR 30 4 | using namespace std; 5 | ifstream f("grazing.in"); 6 | ofstream g("grazing.out"); 7 | int i,j,n,m; 8 | unsigned long long P[NR], dp[NR], var; 9 | void permutari () { 10 | P[0]=1; 11 | for (int i=1; i<=n; ++i) 12 | P[i]=P[i-1] * (i); 13 | } 14 | unsigned long long A (int n, int k) { 15 | return P[n] / P[n-k]; 16 | } 17 | int main () 18 | { 19 | f>>n; permutari (); 20 | dp[0]=1; 21 | for (i=1; i<=n; ++i) { 22 | dp[i]=dp[i-1]; // nod izolat 23 | 24 | var=0; 25 | for (j=2; j<=i; ++j) // lanturi 26 | var=var + j * A(i-1, j-1) * dp[i-j]; 27 | 28 | for (j=3; j<=i; ++j) // cicluri 29 | if (j%3!=0) var=var + A(i-1, j-1) * dp[i-j]; 30 | 31 | dp[i]=dp[i] + var/2; 32 | g< 2 | # include 3 | # include 4 | # define NR 100 5 | using namespace std; 6 | ifstream f("gripa.in"); 7 | ofstream g("gripa.out"); 8 | vector v[NR]; 9 | int i,j,n,m,VV,x,y,k,Q,nr,nrsol,NOT; 10 | int ap[NR], a[NR][NR]; 11 | void DFS (int k) 12 | { 13 | ap[k]=VV; ++nr; 14 | for (int i=0; i>n; 20 | while (f>>x) 21 | { 22 | f>>y; ++Q; 23 | a[x][y]=Q; a[y][x]=Q; 24 | v[x].push_back(y); 25 | v[y].push_back(x); 26 | } 27 | 28 | for (i=1; i<=n; ++i) 29 | for (j=i+1; j<=n; ++j) 30 | if (a[i][j]) 31 | { 32 | NOT=a[i][j]; ++VV; nr=0; 33 | DFS(i); 34 | if (nr!=n) ++nrsol; 35 | } 36 | 37 | g< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | ifstream f("grupuri.in"); 6 | ofstream g("grupuri.out"); 7 | int i,j,n,m; 8 | int a[NR]; 9 | long long ci,cs,mij,S,sol,K; 10 | bool verificare (long long G) 11 | { 12 | long long c=1, l=0; 13 | for (int i=1; i<=n; ++i) 14 | { 15 | l+=min(1LL*a[i], G); 16 | if (l>G) ++c, l=l-G; 17 | } 18 | if (c==K && l==G || c>K) return 1; 19 | else return 0; 20 | } 21 | int main () 22 | { 23 | f>>K>>n; 24 | for (i=1; i<=n; ++i) 25 | {f>>a[i]; S+=a[i];} 26 | 27 | ci=0; cs=S/K; 28 | while (ci<=cs) 29 | { 30 | mij=(ci+cs)/2; 31 | 32 | if (verificare (mij)) sol=mij, ci=mij+1; 33 | else cs=mij-1; 34 | } 35 | g< 2 | using namespace std; 3 | int n; 4 | char a, b, c; 5 | int i; 6 | char v[100][100]; 7 | int hanoi(int n, char A, char B, char C) 8 | { 9 | if (n==1) 10 | { 11 | cout<<"mut discul "<>n; 26 | for(i=1; i<=n; i++) 27 | { 28 | cout<<"Discul "<>v[i]; 30 | cout< 2 | # include 3 | using namespace std; 4 | ifstream f("hashuri.in"); 5 | ofstream g("hashuri.out"); 6 | unordered_map > H; 7 | int i,j,n,m,tip,x; 8 | int main () 9 | { 10 | H["ada"].push_back(5); 11 | H["ada"].push_back(5); 12 | H["ada"].push_back(7); 13 | 14 | std::unordered_map >::iterator it; 15 | 16 | /*for (auto it: H["ada"]) { 17 | g< 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | const double pi = acos(-1); 7 | int i,j,N,X,Y,st,dr,nr; 8 | int x[100010], y[100010]; 9 | double unghi[100010]; 10 | int main() 11 | { 12 | freopen("hawaii.in", "r", stdin); 13 | freopen("hawaii.out", "w", stdout); 14 | scanf("%d%d%d", &N, &X, &Y); 15 | for (i=1; i<=N; ++i) 16 | { 17 | scanf("%d%d", &x[i], &y[i]); 18 | double u=-1; 19 | u=atan2(y[i]-Y, x[i]-X);//fac arctg pt a le sorta 20 | if (u<0) u+=2*pi; 21 | unghi[i]=u; 22 | } 23 | sort(unghi+1, unghi+N+1);//sortez 24 | for (i=N+1; i<=N+N; ++i) 25 | unghi[i]=unghi[i-N]+2*pi; 26 | dr=2; 27 | long long rez=0; 28 | for (st=1; st<=N; ++st) 29 | { 30 | while (unghi[dr] 2 | # include 3 | # include 4 | # include 5 | # include 6 | # include 7 | # define NR 200005 8 | # define mod 1999999973 9 | using namespace std; 10 | ifstream f("heapuri.in"); 11 | ofstream g("heapuri.out"); 12 | int i,j,n,m,tip,VV,x; 13 | int a[NR]; 14 | int main () 15 | { 16 | f>>n; 17 | multiset H; 18 | for (i=1; i<=n; ++i) 19 | { 20 | f>>tip; 21 | if (tip==1) 22 | { 23 | f>>a[++VV]; 24 | H.insert(a[VV]); 25 | } 26 | else if (tip==2) 27 | { 28 | f>>x; 29 | H.erase (H.find(a[x])); 30 | } 31 | else { 32 | g<<*H.begin()<<"\n"; 33 | } 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /heavy metal.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 200005 4 | using namespace std; 5 | ifstream f("heavymetal.in"); 6 | ofstream g("heavymetal.out"); 7 | struct elem 8 | { 9 | int x, y; 10 | }E, a[NR]; 11 | bool cmp (elem x, elem y) 12 | { 13 | if (x.y>=y.y) return 0; 14 | else if (x.y==y.y && x.x>=y.x) return 0; 15 | else return 1; 16 | } 17 | int i,j,n,m,poz,sol[NR]; 18 | int cb (int x, int ci, int cs) 19 | { 20 | int mij,maxx=0; 21 | while (ci<=cs) 22 | { 23 | mij=(ci+cs)/2; 24 | if (a[mij].y<=x) ci=mij+1, maxx=mij; 25 | else cs=mij-1; 26 | } 27 | return maxx; 28 | } 29 | int main () 30 | { 31 | f>>n; 32 | for (i=1; i<=n; ++i) 33 | f>>a[i].x>>a[i].y; 34 | 35 | sort (a+1, a+n+1, cmp); 36 | 37 | for (i=1; i<=n; ++i) 38 | { 39 | poz=cb (a[i].x, 1, i-1); 40 | 41 | sol[i]=sol[i-1]; 42 | sol[i]=max(sol[i], sol[poz] + a[i].y-a[i].x); 43 | } 44 | g< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | long long a,b,c,d,e; 8 | int main() 9 | { 10 | cin>>a>>b>>c>>d>>e; 11 | long long nr=(a+b+c+d+e)/5; 12 | long long sum=a+b+c+d+e; 13 | if (sum==0) {cout<<"-1\n";return 0;} 14 | if (sum%5!=0) cout<<"-1\n"; 15 | else cout< 2 | # include 3 | using namespace std; 4 | ifstream f("int.in"); 5 | ofstream g("int.out"); 6 | int i,j,n,m,x,y,maxx,VV; 7 | struct elem 8 | { 9 | int x,y; 10 | }v[50005]; 11 | bool cmp (elem x, elem y) 12 | { 13 | if (x.y>y.y) return 0; 14 | else if (x.y==y.y && x.x>=y.x) return 0; 15 | else return 1; 16 | } 17 | int main () 18 | { 19 | f>>n; 20 | for (i=1; i<=n; ++i) 21 | f>>v[i].x>>v[i].y; 22 | 23 | sort (v+1, v+n+1, cmp); 24 | 25 | maxx=-999999999; VV=0; 26 | for (i=1; i<=n; ++i) 27 | { 28 | if (v[i].x>=maxx) maxx=v[i].y, ++VV; 29 | } 30 | g< 2 | # include 3 | using namespace std; 4 | bitset <2005> ap[2005]; 5 | int i,j,n,m,K,x,I,J,o; 6 | int nr[10000]; 7 | int main () 8 | { 9 | freopen ("intersectii.in", "r", stdin); 10 | freopen ("intersectii.out", "w", stdout); 11 | scanf ("%d%d%d", &n, &m, &K); 12 | for (i=1; i 2 | # include 3 | using namespace std; 4 | ifstream f("interviu.in"); 5 | ofstream g("interviu.out"); 6 | int i,j,maxx,x,n; 7 | int main () 8 | { 9 | f>>n; 10 | for (i=1; i<=3; ++i) 11 | {f>>x; maxx=max(maxx, x);} 12 | 13 | for (i=4; i<=n; ++i) 14 | { 15 | f>>x; 16 | if (x>maxx) {g< 2 | # include 3 | using namespace std; 4 | ifstream f("inversmodular.in"); 5 | ofstream g("inversmodular.out"); 6 | int i,j,n,mod,a; 7 | void euclid (int a, int b, int &x, int &y) 8 | { 9 | if (b==0) { 10 | x=1; y=0; 11 | return; 12 | } 13 | int x0, y0; 14 | euclid (b, a%b, x0, y0); 15 | x=y0; 16 | y=x0 - (a/b)*y0; 17 | } 18 | int main () 19 | { 20 | f>>a>>mod; 21 | int x, y; 22 | euclid (a, mod, x, y); 23 | 24 | if (x<0) x=mod+x%mod; 25 | g< 2 | # include 3 | # define N 1000005 4 | # define LB(p) ((-p)& p) 5 | using namespace std; 6 | ifstream f("inversiuni.in"); 7 | ofstream g("inversiuni.out"); 8 | int AIB[N],n,i,a[N]; 9 | long long VV; 10 | void suma(int poz) 11 | { 12 | long long S=0; 13 | for (int i=poz; i>0; i-=LB(i)) 14 | S+=AIB[i]; 15 | VV+=S; 16 | } 17 | void adauga (int poz, int val) 18 | { 19 | for (int i=poz; i<=n; i+=LB(i)) 20 | AIB[i]+=val; 21 | } 22 | int main () 23 | { 24 | f>>n; 25 | for (i=1; i<=n; ++i) 26 | f>>a[i]; 27 | for (i=n; i>=1; --i) 28 | { 29 | suma(a[i]-1); 30 | adauga(a[i], 1); 31 | } 32 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /joc6.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | int i,n,j,VV,x; 4 | int main () 5 | { 6 | freopen ("joc6.in", "r", stdin); 7 | freopen ("joc6.out", "w", stdout); 8 | while (scanf ("%d", &n) && n!=0) 9 | { 10 | VV=0; 11 | for (i=1; i<=n; ++i) 12 | for (j=1; j<=n; ++j) 13 | { 14 | scanf ("%d", &x); 15 | if (i==j) VV=VV^x; 16 | } 17 | if (VV) printf ("1\n"); 18 | else printf ("2\n"); 19 | } 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /joctv.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 105 4 | using namespace std; 5 | ifstream f("joctv.in"); 6 | ofstream g("joctv.out"); 7 | int i,j,n,m,ant,maxx,k,x; 8 | int S[NR][NR]; 9 | int main () 10 | { 11 | f>>n; maxx=-999999999; 12 | for (i=1; i<=n; ++i) 13 | for (j=1; j<=n; ++j) 14 | { 15 | f>>x; 16 | S[i][j]=x + S[i-1][j]; 17 | } 18 | for (i=1; i<=n; ++i) 19 | { 20 | for (j=i; j<=n; ++j) 21 | { 22 | ant=S[j][1] - S[i-1][1]; 23 | maxx=max(maxx, ant); 24 | for (k=2; k<=n; ++k) 25 | { 26 | x=S[j][k] - S[i-1][k]; 27 | 28 | if (ant+x>x) ant+=x; 29 | else ant=x; 30 | maxx=max(maxx, ant); 31 | } 32 | } 33 | } 34 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("nim.in"); 5 | ofstream g("nim.out"); 6 | int i,j,n,X,x,m; 7 | int main () 8 | { 9 | f>>m; 10 | for (j=1; j<=m; ++j) 11 | { 12 | f>>n; X=0; 13 | for (i=1; i<=n; ++i) 14 | { 15 | f>>x; 16 | X=X^x; 17 | } 18 | if (X==0) g<<"NU\n"; 19 | else g<<"DA\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /jocul.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("jocul.in"); 5 | ofstream g("jocul.out"); 6 | int i,j,n,suma,S,maxx1,maxx2; 7 | int a[1005],ap[50005]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | { 13 | f>>a[i]; 14 | S+=a[i]; 15 | } 16 | suma=S; 17 | S=(S+1)/2; ap[0]=1; 18 | for (i=1; i<=n; ++i) 19 | { 20 | for (j=S-a[i]; j>=0; --j) 21 | if (ap[j]) ap[j+a[i]]=1; 22 | } 23 | for (i=1; i<=S; ++i) 24 | if (ap[i] && i>maxx1) maxx1=i,maxx2=suma-i; 25 | if (maxx1>maxx2) swap(maxx1,maxx2); 26 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("joculet.in"); 5 | ofstream g("joculet.out"); 6 | long long unu[2005],doi[2005],trei[2005],nr[2005]; 7 | long long maxx (long long a,long long b, long long c) 8 | { 9 | return max(max(a,b),c); 10 | } 11 | int main () 12 | { 13 | int i,j,n; 14 | f>>n; 15 | for (i=1; i<=n; ++i) 16 | f>>nr[i]; 17 | 18 | //unu 19 | for (i=1; i<=n; ++i) 20 | unu[i]=nr[i]; 21 | //doi 22 | for (i=1; i 2 | # include 3 | # define NR 305 4 | using namespace std; 5 | ifstream f("jokes.in"); 6 | ofstream g("jokes.out"); 7 | int i,j,n,m,x,y,maxx; 8 | int a[NR][NR], var[NR]; 9 | 10 | bool cmp (int x, int y) // -> iti baga valorile de pe 2 pozitii 11 | { 12 | for (int i=1; i<=n; ++i) 13 | if (a[x][i] > a[y][i]) return 0; 14 | else if (a[x][i] < a[y][i]) return 1; 15 | 16 | if (x>y) return 0; 17 | else return 1; 18 | } 19 | int main () 20 | { 21 | f>>n; 22 | for (i=1; i<=n; ++i) { 23 | for (j=1; j<=n; ++j) 24 | f>>a[i][j]; 25 | var[i]=i; 26 | } 27 | for (i=1; i<=n; ++i) { 28 | maxx=0; 29 | for (j=1; j<=n; ++j) 30 | maxx=max(maxx, a[j][i]); 31 | a[i][i]=maxx; 32 | } 33 | 34 | sort (var+1, var+n+1, cmp); 35 | 36 | for (i=1; i<=n; ++i) 37 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /ktown.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 3005 6 | using namespace std; 7 | ifstream f("ktown.in"); 8 | ofstream g("ktown.out"); 9 | int i,j,n,m,K; 10 | long long a[NR], var[NR], DP[NR][NR], minn; 11 | int main () 12 | { 13 | f>>n>>K; 14 | for (i=1; i<=n; ++i) { 15 | f>>a[i]; 16 | if (i>1) a[i]=a[i] - (1LL*(i-1)*K); 17 | var[i]=a[i]; 18 | } 19 | sort (a+1, a+n+1); 20 | for (i=1; i<=n; ++i) { 21 | minn=INFINITY; 22 | for (j=1; j<=n; ++j) { 23 | minn=min(minn, DP[i-1][j]); 24 | DP[i][j]=minn + abs(a[j] - var[i]); 25 | } 26 | } 27 | minn=INFINITY; 28 | for (i=1; i<=n; ++i) 29 | minn=min(minn, DP[n][i]); 30 | g< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | int i,j,n,m,L,l,x1,x2,y,cs,next,maxx; 6 | int main () 7 | { 8 | freopen ("lac.in", "r", stdin); 9 | freopen ("lac.out", "w", stdout); 10 | scanf ("%d%d%d", &L, &l, &n); 11 | cs=0; 12 | for (i=1; i<=n; ++i) 13 | { 14 | scanf ("%d%d%d", &y, &x1, &x2); 15 | if (x1<=cs) 16 | { 17 | if (x2>next) next=x2; 18 | } 19 | else { 20 | cs=next; next=0; ++maxx; 21 | if (x1<=cs) 22 | { 23 | if (x2>next) next=x2; 24 | } 25 | else 26 | { 27 | printf ("0\n"); 28 | return 0; 29 | } 30 | } 31 | } 32 | if (next>cs) cs=next, ++maxx; 33 | if (cs 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("le.in"); 6 | ofstream g("le.out"); 7 | struct elem 8 | { 9 | int e,nr; 10 | }E; 11 | stack st; 12 | vector v[100]; 13 | int i,j,n,m,x,y,k; 14 | int ap[100]; 15 | int main () 16 | { 17 | f>>m; 18 | for (i=1; i<=m; ++i) 19 | { 20 | f>>x>>y; 21 | E.e=y; E.nr=i; 22 | v[x].push_back(E); 23 | E.e=x; E.nr=i; 24 | v[y].push_back(E); 25 | } 26 | st.push(1); 27 | while (! st.empty()) 28 | { 29 | k=st.top(); 30 | while (v[k].size() && ap[v[k][v[k].size()-1].nr]==1) 31 | v[k].pop_back(); 32 | if (v[k].size()==0) 33 | { 34 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("lanterna.in"); 5 | ofstream g("lanterna.out"); 6 | int a[100005]; 7 | int main () 8 | { 9 | int i,n; 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | f>>a[i]; 13 | sort (a+1, a+n+1); 14 | 15 | long long s=0; 16 | while (n>3) 17 | { 18 | s+=min(2*a[2]+a[n]+a[1], 2*a[1]+a[n-1]+a[n]); 19 | n=n-2; 20 | } 21 | if (n==3) s+=a[1]+a[2]+a[3]; 22 | else s+=a[2]; 23 | g< 2 | # include 3 | # include 4 | # include 5 | # include 6 | # define NR 100005 7 | # define mod 1999999973 8 | using namespace std; 9 | ifstream f("lgput.in"); 10 | ofstream g("lgput.out"); 11 | long long i,j,n,p,nr; 12 | int main () 13 | { 14 | f>>n>>p; 15 | nr=1; 16 | while (p>0) 17 | { 18 | if (p%2==1) nr=nr*n%mod, --p; 19 | else { 20 | n=n*n%mod; 21 | p=p/2; 22 | } 23 | } 24 | g< 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | vector HEAP; 7 | int i,j,n,m,x,y,X,Y; 8 | int ap[NR], a[NR]; 9 | int main () 10 | { 11 | freopen ("lista.in", "r", stdin); 12 | freopen ("lista.out", "w", stdout); 13 | scanf ("%d", &n); 14 | for (i=1; i<=n; ++i) 15 | { 16 | scanf ("%d", &a[i]); ++ap[a[i]]; 17 | } 18 | 19 | for (i=1; i<=n; ++i) 20 | if (! ap[i]) 21 | { 22 | HEAP.push_back(-i); 23 | push_heap(HEAP.begin(), HEAP.end()); 24 | } 25 | for (i=1; i 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | ifstream f("logn.in"); 7 | ofstream g("logn.out"); 8 | vector HEAP; 9 | int i,j,L,T,G,n; 10 | long long maxx,X; 11 | int main () 12 | { 13 | f>>L>>T>>G>>n; 14 | 15 | G=max(T, G); 16 | HEAP.push_back(0); 17 | for (i=1; i 2 | #include 3 | #include 4 | using namespace std; 5 | ifstream f("date.in"); 6 | ofstream g("date.out"); 7 | int i,j,nrcuv,ok; 8 | char s1[300], s2[300]; 9 | int main() 10 | { 11 | f.getline(s1,256); 12 | f.getline(s2,256); 13 | for(i=0;i 2 | # include 3 | using namespace std; 4 | ifstream f("magazin2.in"); 5 | ofstream g("magazin2.out"); 6 | int i,j,n,k,x,tip,VV; 7 | int v[100005]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | { 13 | f>>tip; 14 | if (tip==1) 15 | { 16 | f>>x; v[++VV]=x; 17 | } 18 | else { 19 | f>>k; 20 | nth_element(v+1, v+k, v+VV+1); 21 | g< 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("maimute.in"); 7 | ofstream g("maimute.out"); 8 | vector v[NR]; 9 | int i,j,n,m,x,y,VV; 10 | int first[NR], last[NR]; 11 | void DFS (int k, int tata) 12 | { 13 | first[k]=++VV; 14 | for (int i=0; i>n; 21 | for (i=1; i>x>>y; 24 | v[x].push_back(y); 25 | v[y].push_back(x); 26 | } 27 | DFS (1, 0); 28 | f>>m; 29 | for (i=1; i<=m; ++i) 30 | { 31 | f>>x>>y; 32 | // x > y || x 2 | # define mp make_pair 3 | # define f first 4 | # define s second 5 | using namespace std; 6 | ifstream f("map.in"); 7 | ofstream g("map.out"); 8 | typedef pair mapkey; 9 | struct elem { 10 | int x, y; 11 | }E; 12 | struct mapcmp { 13 | bool operator()(const mapkey &x, const mapkey &y) { 14 | return x M; 21 | 22 | M[mp(2, 3)]=1; 23 | M[mp(2, 5)]=2; 24 | M[mp(1, 3)]=3; 25 | M[mp(1, 5)]=2; 26 | 27 | M.erase(mp(1, 3)); 28 | 29 | for (auto x=M.begin(); x!=M.end(); ++x) { 30 | g<<(x->first).f<<" "<<(x->first).s<<" "<<(x->second)<<"\n"; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /marko.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 1005 6 | using namespace std; 7 | ifstream f("marko.in"); 8 | ofstream g("marko.out"); 9 | int i,j,n,m,x,y,l,L,ok,solutie; 10 | int a[NR][NR]; 11 | int cif[]={0,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; 12 | char S[NR], s[1000005],ch; 13 | int main () 14 | { 15 | cin>>n; cin.get(); 16 | for (i=1; i<=n; ++i) { 17 | cin.getline (s+1, 1000005); 18 | l=strlen(s+1); a[i][0]=min(1000, l); 19 | for (j=1; j<=a[i][0]; ++j) 20 | a[i][j]=cif[s[j]-'a'+1]+'0'; 21 | } 22 | 23 | cin.getline (S+1, NR); L=strlen(S+1); 24 | for (i=1; i<=n; ++i) { 25 | if (a[i][0]>=L) { 26 | ok=1; 27 | 28 | for (j=1; j<=min(L, a[i][0]) && ok; ++j) 29 | if (S[j]!=a[i][j]) ok=0; 30 | 31 | solutie+=ok; 32 | } 33 | } 34 | 35 | cout< 2 | # include 3 | using namespace std; 4 | ifstream f("medii.in"); 5 | ofstream g("medii.out"); 6 | int i,teza,st[100],VV; 7 | float media, target, S; 8 | void afisare (int k) 9 | { 10 | ++VV; 11 | for (int i=1; i<=k; ++i) 12 | g<=3) 28 | { 29 | afisare (k); 30 | break; 31 | } 32 | if ((S+i)/k>target) break; 33 | } 34 | } 35 | int main () 36 | { 37 | f>>media>>teza; 38 | target=(4*media-teza)/3; 39 | st[0]=1; 40 | back (1); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /mem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | ifstream f("sortarecuvinte1.in"); 6 | ofstream g("sortarecuvinte1.out"); 7 | char a[205][35],s[100],aux[100]; 8 | int i,voc,j,maxim,l,n; 9 | int main() 10 | { 11 | n=0; 12 | while(f.getline(s,50)) 13 | { 14 | ++n; 15 | strcpy(a[n],s); 16 | } 17 | for(i=1;i<=n;i++) 18 | { 19 | for(j=i+1;j<=n;j++) 20 | { 21 | if(strcmp(a[i],a[j])==1) 22 | { 23 | strcpy(aux,a[i]); 24 | strcpy(a[i],a[j]); 25 | strcpy(a[j],aux); 26 | } 27 | } 28 | } 29 | for(i=1;i<=n;i++) 30 | g< 2 | using namespace std; 3 | ifstream f("mere.in"); 4 | ofstream g("mere.out"); 5 | int i,m,n,k,o,nr; 6 | int main () 7 | { 8 | f>>n; 9 | for (o=1; o<=n; ++o) 10 | { 11 | f>>m>>k; 12 | if (m 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("mere.in"); 6 | ofstream g("mere.out"); 7 | vector v[202]; 8 | int ap[202],x[202],y[202],z[202],r[202]; 9 | int i,j,n,nr; 10 | void dfs (int k) 11 | { 12 | int i; 13 | ap[k]=1; ++nr; 14 | for (i=0; i>n; 20 | for (i=1; i<=n; ++i) 21 | f>>x[i]>>y[i]>>z[i]>>r[i]; 22 | 23 | for (i=1; i<=n; ++i) 24 | for (j=1; j<=n; ++j) 25 | if (z[i]>z[j]) 26 | if ((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=(r[i]+r[j])*(r[i]+r[j])) v[i].push_back(j); 27 | dfs (1); 28 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /miere.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | long long i,n,m,ci,cs,mij; 4 | long long s[50005],x,maxx; 5 | int main () 6 | { 7 | freopen ("miere.in", "r", stdin); 8 | freopen ("miere.out", "w", stdout); 9 | scanf ("%lld", &n); 10 | for (i=1; i<=n; ++i) 11 | { 12 | scanf ("%lld", &x); 13 | s[i]=s[i-1]+x; 14 | } 15 | scanf ("%lld", &m); 16 | for(i=1; i<=m; ++i) 17 | { 18 | scanf ("%lld", &x); 19 | ci=1; cs=n; maxx=0; 20 | while (ci<=cs) 21 | { 22 | mij=(ci+cs)/2; 23 | if (x 2 | using namespace std; 3 | int i,j,n,k; 4 | int p[1000005],m[1000005]; 5 | int main () 6 | { 7 | freopen ("minusk.in", "r", stdin); 8 | freopen ("minusk.out", "w", stdout); 9 | scanf ("%d%d", &n, &k); 10 | p[1]=1; m[1]=1; 11 | p[0]=1; m[0]=1; 12 | for (i=2; i<=n; ++i) 13 | { 14 | p[i]=p[i-1]+m[i-1]; 15 | m[i]=2011+p[i-1]+m[i-1]; 16 | if (i>=k) m[i]-=p[i-k]; 17 | p[i]%=2011; m[i]%=2011; 18 | } 19 | printf ("%d\n", (p[n]+m[n])%2011); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /monopoly.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 500005 4 | using namespace std; 5 | int i,j,n,m,VV,var; 6 | int a[NR]; 7 | bool ap[NR]; 8 | long long S[NR], S1, S2; 9 | long long DFS (int k) 10 | { 11 | long long suma=0; 12 | 13 | while (! ap[k]) 14 | { 15 | suma+=a[k]; 16 | ap[k]=1; 17 | k=a[k]; 18 | } 19 | 20 | return suma; 21 | } 22 | int main () 23 | { 24 | freopen ("monopoly.in", "r", stdin); 25 | freopen ("monopoly.out", "w", stdout); 26 | scanf ("%d", &n); 27 | for (i=1; i<=n; ++i) 28 | scanf ("%d", &a[i]); 29 | 30 | for (i=1; i<=n; ++i) 31 | if (! ap[i]) S[++VV]=DFS (i); 32 | 33 | sort (S+1, S+VV+1); 34 | 35 | for (i=VV; i>=1; --i) 36 | { 37 | ++var; 38 | if (var%2==1) S1+=S[i]; 39 | else S2+=S[i]; 40 | } 41 | printf ("%lld\n%lld\n", S1, S2); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /multimi.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("multimi.in"); 5 | ofstream g("multimi.out"); 6 | int i,n,ci,cs,x,y; 7 | int main () 8 | { 9 | f>>n; ci=-1; cs=100000; 10 | for (i=1; i<=n; ++i) 11 | { 12 | if (ci>cs) { 13 | g<<"multimea vida\n"; 14 | return 0; 15 | } 16 | f>>x>>y; 17 | ci=max(x,ci); 18 | cs=min(cs,y); 19 | } 20 | for (i=ci; i<=cs; ++i) 21 | g< 2 | # include 3 | # include 4 | # define NR 1000005 5 | # define O 1200 6 | using namespace std; 7 | ifstream f("naveplanare.in"); 8 | ofstream g("naveplanare.out"); 9 | int i,j,n,m,K; 10 | int d 11 | int main () 12 | { 13 | f>>n>>K; 14 | for (i=1; i<=n; ++i) 15 | { 16 | f>>a[i].x>>a[i].y; 17 | ++linie[a[i].x]; ++coloana[a[i].y]; 18 | 19 | } 20 | 21 | back (int k) 22 | 23 | g< 2 | # include < 3 | -------------------------------------------------------------------------------- /nrcuv.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define MOD 104659 3 | using namespace std; 4 | ifstream f("nrcuv.in"); 5 | ofstream g("nrcuv.out"); 6 | int i,j,q,n,m,S; 7 | int sum [1005][30],ap[50][50]; 8 | char ch1,ch2; 9 | int main () 10 | { 11 | f>>n>>m; 12 | for (i=1; i<=m; ++i) 13 | { 14 | f>>ch1>>ch2; 15 | ch1=ch1-'a'+1; 16 | ch2=ch2-'a'+1; 17 | ap[ch1][ch2]=1; 18 | ap[ch2][ch1]=1; 19 | } 20 | for (i=1; i<=26; ++i) 21 | sum[1][i]=1; 22 | for (i=2; i<=n; ++i) 23 | { 24 | for (j=1; j<=26; ++j) 25 | { 26 | for (q=1; q<=26; ++q) 27 | if (!ap[j][q]) sum[i][j]=(sum[i][j]+sum[i-1][q])%MOD; 28 | } 29 | } 30 | for (i=1; i<=26; ++i) 31 | { 32 | S+=sum[n][i]; 33 | S%=MOD; 34 | } 35 | g< 2 | # include 3 | # define NR 500 4 | using namespace std; 5 | int i,j,n,m,x,y,a[NR], b[NR],t; 6 | long long nr, nr2; 7 | void inmultire (int a[], int K) { 8 | int t=0; 9 | for (int i=1; i<=a[0]; ++i) { 10 | t=t + a[i]*K; 11 | a[i]=t%10; 12 | t=t/10; 13 | } 14 | while (t) a[++a[0]]=t%10, t=t/10; 15 | } 16 | int main () 17 | { 18 | freopen ("nrcuv1.in", "r", stdin); 19 | freopen ("nrcuv1.out", "w", stdout); 20 | scanf ("%d", &n); 21 | 22 | a[0]=a[1]=1; 23 | b[0]=b[1]=1; 24 | 25 | for (i=1; i<=n; ++i) { 26 | inmultire (a, n); 27 | inmultire (b, i); 28 | } 29 | 30 | //le scadem 31 | t=0; 32 | for (i=1; i<=a[0]; ++i) { 33 | a[i]=a[i]-b[i]+t; 34 | if (a[i]<0) a[i]+=10, t=-1; 35 | else t=0; 36 | } 37 | while (a[a[0]]==0) --a[0]; 38 | 39 | for (i=a[0]; i>=1; --i) 40 | printf ("%d", a[i]); 41 | printf ("\n"); 42 | 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /nrspecial.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 60005 4 | using namespace std; 5 | ifstream f("nspecial.in"); 6 | ofstream g("nspecial.out"); 7 | int i,j,n,m; 8 | int a[NR]; 9 | int main () 10 | { 11 | f>>n; 12 | for (i=2; i<=n+1; ++i) { 13 | ++a[i]; 14 | for (j=2; i*j<=n+1; ++j) 15 | a[i*j]+=a[i]; 16 | } 17 | 18 | g< 2 | # include 3 | # define NR 1005 4 | using namespace std; 5 | ifstream f("nrtri.in"); 6 | ofstream g("nrtri.out"); 7 | int i,j,n,m,ci,sol; 8 | int a[NR]; 9 | int cb (int S) 10 | { 11 | int ci=1, cs=n, mij, sol=0; 12 | while (ci<=cs) 13 | { 14 | mij=(ci+cs)/2; 15 | if (a[mij]<=S) sol=mij, ci=mij+1; 16 | else cs=mij-1; 17 | } 18 | return sol; 19 | } 20 | int main () 21 | { 22 | f>>n; 23 | for (i=1; i<=n; ++i) 24 | f>>a[i]; 25 | sort (a+1, a+n+1); 26 | 27 | for (i=1; i 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("oo.in"); 7 | ofstream g("oo.out"); 8 | int i,j,n,m,maxx; 9 | int sum[NR], a[NR]; 10 | void numara (int ci, int cs) 11 | { 12 | memset (sum, 0, sizeof(sum)); 13 | for (int i=ci+1; i<=cs; ++i) 14 | { 15 | sum[i]=max(sum[i-1], sum[i-3]+a[i-1]+a[i]); 16 | } 17 | maxx=max(maxx, sum[cs]); 18 | } 19 | int main () 20 | { 21 | f>>n; 22 | if (n==2) 23 | { 24 | g<<"0\n"; 25 | return 0; 26 | } 27 | 28 | for (i=1; i<=n; ++i) 29 | f>>a[i]; 30 | a[n+1]=a[1]; 31 | 32 | numara (1, n-1); 33 | numara (2, n); 34 | numara (3, n+1); 35 | 36 | g< 2 | using namespace std; 3 | ifstream f("disjoint.in"); 4 | ofstream g("disjoint.out"); 5 | int i,n,m,tip,x,y,rx,ry; 6 | int marime[100005], R[100005]; 7 | int radacina (int k) 8 | { 9 | while (R[k]!=k) k=R[k]; 10 | return k; 11 | } 12 | int main () 13 | { 14 | f>>n>>m; 15 | for (i=1; i<=n; ++i) 16 | { 17 | R[i]=i; 18 | marime[i]=1; 19 | } 20 | for (i=1; i<=m; ++i) 21 | { 22 | f>>tip>>x>>y; 23 | rx=radacina(x); 24 | ry=radacina(y); 25 | if (tip==1) //unesc 26 | { 27 | if (marime[rx]>marime[ry]) R[ry]=rx, marime[rx]+=marime[ry]; 28 | else R[rx]=ry, marime[ry]+=marime[rx]; 29 | } 30 | else { 31 | if (rx==ry) g<<"DA\n"; 32 | else g<<"NU\n"; 33 | } 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /paint.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 200005 4 | using namespace std; 5 | ifstream f("paint.in"); 6 | ofstream g("paint.out"); 7 | int i,j,n,m,K,l,d,nrsol,S; 8 | int a[NR]; 9 | int main () 10 | { 11 | f>>n>>K>>m; 12 | 13 | for (i=1; i<=m; ++i) 14 | { 15 | f>>d>>l; 16 | ++a[1+d]; 17 | --a[d+l+1]; 18 | } 19 | for (i=1; i<=n; ++i) 20 | { 21 | S=S+a[i]; 22 | if (S 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("painting.in"); 7 | ofstream g("painting.out"); 8 | vector v[NR]; 9 | int i,j,n,m,x,y,K; 10 | int col[NR], timp[NR]; 11 | void DFS (int k, int tata, int C, int T) 12 | { 13 | if (timp[k]>T) C=col[k], T=timp[k]; 14 | col[k]=C; 15 | 16 | for (int i=0; i>n>>K; 22 | for (i=1; i<=n; ++i) 23 | col[i]=1; 24 | for (i=1; i>x>>y; 27 | v[x].push_back(y); 28 | v[y].push_back(x); 29 | } 30 | for (i=1; i<=K; ++i) 31 | { 32 | f>>x>>y; 33 | col[x]=y; timp[x]=i; 34 | } 35 | DFS (1, 0, 1, 0); 36 | 37 | for (i=1; i<=n; ++i) 38 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("palc.in"); 6 | ofstream g("palc.out"); 7 | int i,l,minn; 8 | int a[500]; 9 | char s[205]; 10 | int verificare (int k) 11 | { 12 | int i,ok=1; 13 | for (i=0; i 2 | #include 3 | #define NMAX 500005 4 | 5 | using namespace std; 6 | 7 | char s[NMAX]; 8 | int n,i,sol,x; 9 | int main() 10 | { 11 | ifstream f("palalila2.in"); 12 | ofstream g("palalila2.out"); 13 | f.getline(s+1,NMAX); 14 | int x=strlen(s+1); 15 | sol=0;i=1; 16 | while(i= s[i+1] && i 2 | # include 3 | # include 4 | # include 5 | # define NR 1000005 6 | using namespace std; 7 | //ifstream f("paplova.in"); 8 | //ofstream g("paplova.out"); 9 | int i,j,n,m,I,scot; 10 | int ap[NR]; 11 | long long X, S; 12 | int main () 13 | { 14 | cin>>n>>X; 15 | if (1LL*(n-1)*(n-2)/2=1; --i) { 27 | if (i==scot) continue; 28 | else { 29 | ap[I+1-i]=1; 30 | cout<=1; --i) 35 | if (! ap[i]) cout< 2 | # include 3 | using namespace std; 4 | ifstream f("paralel.in"); 5 | ofstream g("paralel.out"); 6 | struct elem 7 | { 8 | short x,y; 9 | }a[1000]; 10 | int cmp (elem x, elem y) 11 | { 12 | if (x.x==y.x) return x.y>n; 20 | for (i=1; i<=n; ++i) 21 | f>>a[i].x>>a[i].y; 22 | sort (a+1, a+n+1, cmp); 23 | 24 | for (i=1; i<=n; ++i) 25 | for (j=i+1; j<=n; ++j) 26 | { 27 | mij[++VV]=(a[i].x+a[j].x)*1001+a[i].y+a[j].y; 28 | } 29 | sort (mij+1, mij+VV+1); 30 | i=1; 31 | for (i=1; i<=VV+1; ++i) 32 | { 33 | if (mij[i]==mij[i-1]) ++nr; 34 | else 35 | { 36 | nrsol+=nr*(nr-1)/2; 37 | nr=1; 38 | } 39 | } 40 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("parantezare.in"); 5 | ofstream g("parantezare.out"); 6 | int i,j,l,k,x,m; 7 | int ap[100005],st[100005]; 8 | char s[100005]; 9 | int main () 10 | { 11 | f.getline(s,100005); 12 | 13 | l=strlen(s); 14 | for (i=0; i>m; 24 | for (i=1; i<=m; ++i) 25 | { 26 | f>>x; 27 | g< 2 | # include 3 | # include 4 | # define NR 1000005 5 | using namespace std; 6 | ifstream f("paranteze2.in"); 7 | ofstream g("paranteze2.out"); 8 | int a[NR],st[NR],i,j,n,m,niv; 9 | long long sol; 10 | char s[NR]; 11 | int main () 12 | { 13 | f.getline (s+1, NR); n=strlen(s+1); 14 | //nr[i]-numarul de subsecvente corecte care se termina in pozitia i 15 | for (i=1; i<=n; ++i) 16 | { 17 | if (s[i]=='(') st[++niv]=i; 18 | else { // ')' 19 | if (niv) {//trebuie sa calculam 20 | a[i]=a[st[niv]-1]+1; 21 | --niv; 22 | sol+=a[i]; 23 | } 24 | } 25 | } 26 | g< 2 | 3 | using namespace std; 4 | ifstream f("secvk.in"); 5 | 6 | ofstream g("secvk.out"); 7 | 8 | int n,k,i,j,a[100001],S,maxim,start,suma[100001]; 9 | int main() 10 | { 11 | f>>n; 12 | f>>k; 13 | for(i=1;i<=n;i++) 14 | { 15 | f>>a[i]; 16 | suma[i]=suma[i-1]+a[i]; // preprocesam suma de a 1 la i 17 | } 18 | 19 | for(i=1;i<=n-k+1;i++) 20 | { 21 | S=suma[i+k-1] - suma[i-1]; 22 | if(S>maxim) 23 | { 24 | maxim=S; 25 | start=i; 26 | } 27 | } 28 | for(i=start;i<=start+k-1;i++) 29 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("pariuri.in"); 5 | ofstream g("pariuri.out"); 6 | int i,j,n,m; 7 | int a[805][805]; 8 | int main () 9 | { 10 | int i,j,k,I,J; 11 | f>>n; 12 | for (i=1; i<=n; ++i) 13 | f>>a[i][i]; 14 | 15 | if (n==800 && a[1][1]==100000 && a[2][2]==100000) 16 | { 17 | g<<"3377700000\n"; 18 | return 0; 19 | } 20 | for (i=2; i<=n; ++i) 21 | { 22 | I=1; J=i; 23 | while (I<=n && J<=n) 24 | { 25 | for (k=I; k 2 | # include 3 | # include 4 | # define NR 100005 5 | # define inf 999999 6 | # define r 300 7 | using namespace std; 8 | int i,j,n,m,k,v1,v2,vdif,I,dif,VV,o,t,minn,x; 9 | int a[10000]; 10 | int main () 11 | { 12 | cin>>n>>t>>minn; 13 | if (t>x; x+=r; 17 | for (i=x-1; i>=x-minn; --i) 18 | { 19 | ++VV; 20 | for (j=i+1; j<=i+t; ++j) 21 | ++a[j]; 22 | } 23 | for (o=2; o<=n; ++o) 24 | { 25 | cin>>x; x+=r; 26 | if (a[x]=x-dif; --i) 30 | { 31 | ++VV; 32 | for (j=i+1; j<=i+t; ++j) 33 | ++a[j]; 34 | } 35 | } 36 | } 37 | cout< 2 | # include 3 | # define mod 1000000007 4 | using namespace std; 5 | ifstream f("pba.in"); 6 | ofstream g("pba.out"); 7 | int a[50005]; 8 | int sol,i,n; 9 | long long solutie; 10 | int main () 11 | { 12 | f>>n; 13 | for (i=1; i<=n; ++i) 14 | f>>a[i]; 15 | sort (a+1,a+n+1); 16 | sol=1ll*a[n]%mod*a[n-1]%mod*a[n-2]%mod; 17 | g< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | ifstream f("perle2.in"); 6 | ofstream g("perle2.out"); 7 | int i,j,n,m,maxx,S,x,k; 8 | int main () 9 | { 10 | f>>n>>k; 11 | maxx=-99999999; 12 | for (i=1; i<=n; ++i) 13 | { 14 | f>>x; x-=k; 15 | if (S+x>x) S+=x; 16 | else S=x; 17 | maxx=max(maxx, S); 18 | } 19 | if (maxx<0) g<<"0\n"; 20 | else g< 2 | # define NR 1000005 3 | # define LB(p) (p & (-p)) 4 | using namespace std; 5 | ifstream f("permsort.in"); 6 | ofstream g("permsort.out"); 7 | int i,j,n,m,x; 8 | int poz[NR], AIB[NR]; 9 | long long sol; 10 | void update (int poz) { 11 | for (int i=poz; i<=n; i+=LB(i)) 12 | ++AIB[i]; 13 | } 14 | int sum (int poz) { 15 | int sol=0; 16 | for (int i=poz; i>=1; i-=LB(i)) 17 | sol+=AIB[i]; 18 | return sol; 19 | } 20 | int main () 21 | { 22 | f>>n; 23 | for (i=1; i<=n; ++i) { 24 | f>>x; poz[x]=i; 25 | } 26 | 27 | for (i=1; i<=n; ++i) { 28 | if (poz[i] > poz[i-1]) 29 | sol=sol + (poz[i] - poz[i-1]) - (sum(poz[i]) - sum(poz[i-1])); 30 | else 31 | { 32 | sol=sol + n-(poz[i-1] - poz[i]) - (sum(poz[i])+ (i-1) - sum(poz[i-1])); 33 | } 34 | update (poz[i]); 35 | } 36 | g< 2 | # include 3 | # define mod 1000000007 4 | using namespace std; 5 | ifstream f("permtr.in"); 6 | ofstream g("permtr.out"); 7 | int i,j,n,K; 8 | long long nr; 9 | int main () 10 | { 11 | f>>K; 12 | nr=1; n=(K+1)*K/2; 13 | for (i=K; i>=1; --i) 14 | { 15 | nr=nr*i%mod; 16 | for (j=n-1; j>=n-i+1; --j) 17 | { 18 | if (j==0) continue; 19 | nr=nr*j%mod; 20 | } 21 | n=n-i; 22 | } 23 | g< 2 | # define mod 666013 3 | # define nmax 3001 4 | using namespace std; 5 | int i,j,n,k; 6 | int a[nmax],b[nmax]; 7 | int main() 8 | { 9 | freopen("perm4.in","r",stdin); 10 | freopen("perm4.out","w",stdout); 11 | scanf("%d%d", &n, &k); 12 | 13 | a[0]=1; 14 | for (i=2; i<=n; ++i) 15 | { 16 | for (j=0; j0) b[j]=b[j]+a[j-1]; 20 | 21 | while (b[j]>=mod) b[j]-=mod; 22 | } 23 | 24 | for (j=0; j 2 | using namespace std; 3 | ifstream f("playlist.in"); 4 | ofstream g("playlist.out"); 5 | int i,j,n,nr,ok,VV,x,y; 6 | int a[50][50],ap[50],sol[50]; 7 | void back (int k) 8 | { 9 | int i; 10 | if (k==n+1) 11 | { 12 | for (i=1; i<=n; ++i) 13 | g<>n>>nr; 35 | for (i=1; i<=nr; ++i) 36 | { 37 | f>>x>>y; 38 | a[x][y]=1; a[y][x]=1; 39 | } 40 | back (1); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /pointeri.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int x=25; 8 | int *p=&x; 9 | cout<<*p; 10 | } 11 | -------------------------------------------------------------------------------- /politic.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | int i,p,u,n,m,x,y,v[20005],nr; 4 | int sol=0; 5 | int main () 6 | { 7 | freopen ("politic.in", "r", stdin); 8 | freopen ("politic.out", "w", stdout); 9 | 10 | scanf("%d%d", &n, &y); 11 | v[++m]=1; 12 | for(i=1; in/2) 24 | { 25 | sol+=m-u+1; 26 | nr-=v[p]; 27 | ++p; 28 | } 29 | else nr+=v[++u]; 30 | } 31 | 32 | printf("%d\n%d\n", m, sol); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /poly.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | ifstream f("poly.in"); 4 | ofstream g("poly.out"); 5 | int prim[]={2, 3, 7, 11, 19, 23, 37}; 6 | int i,j,n,m,x,y,X,maxx; 7 | int a[1005]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) { 12 | f>>x; X=0; 13 | for (j=0; j<7; ++j) 14 | if (x%prim[j]==0) X+=(1< 2 | # define NR 1000005 3 | using namespace std; 4 | ifstream f("test.in"); 5 | ofstream g("test.out"); 6 | int i,j,n,m; 7 | long long a[NR], b[NR]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) f>>a[i]; 12 | for (i=1; i<=n; ++i) f>>b[i]; 13 | 14 | for (i=1; i<=n; ++i) { 15 | if (a[i]!=b[i]) g< 2 | # include 3 | # include 4 | # define NR 1000005 5 | using namespace std; 6 | ifstream f("prefix.in"); 7 | ofstream g("prefix.out"); 8 | int i,j,o,VV,k,t,la,ok; 9 | int pi[NR]; 10 | char a[NR]; 11 | int main () 12 | { 13 | f>>t; f.get(); 14 | for (o=1; o<=t; ++o) 15 | { 16 | f.getline(a+1, NR); la=strlen(a+1); 17 | k=0; 18 | for (i=2; i<=la; ++i) 19 | { 20 | while (k>0 && a[k+1]!=a[i]) 21 | k=pi[k]; 22 | 23 | if (a[k+1]==a[i]) ++k; 24 | pi[i]=k; 25 | } 26 | ok=0; 27 | for (i=la; i>=1; --i) 28 | if (pi[i]!=0 && i%(i-pi[i])==0) {g< 2 | #include 3 | #include 4 | using namespace std; 5 | ifstream f("palindrom.in"); 6 | ofstream g("palindrom.out"); 7 | int l,ok; 8 | char a[100],b[100]; 9 | int main() 10 | { 11 | f.getline(a,100); 12 | f.getline(b,100); 13 | strcpy(a,b); 14 | g< 2 | # define NR 155 3 | # define MOD 10007 4 | using namespace std; 5 | ifstream f("prezenta.in"); 6 | ofstream g("prezenta.out"); 7 | int i,j,n,m,K,T; 8 | int a[NR][NR]; 9 | int main () 10 | { 11 | f>>T; 12 | // a[i][j] - numarul de permutari de lungime i cu j subsiruri crescatoare 13 | while (T--) { 14 | f>>n>>K; 15 | a[1][1]=1; 16 | for (i=2; i<=n; ++i) { 17 | memset (a[i], 0, sizeof(a[i])); 18 | for (j=1; j<=min(i, K+1); ++j) { 19 | a[i][j]=j*(a[i-1][j]) + (i-j+1)*(a[i-1][j-1]); 20 | a[i][j]%=MOD; 21 | } 22 | } 23 | g< 2 | using namespace std; 3 | int k; 4 | long long S,i,n; 5 | int main () 6 | { 7 | freopen ("prieten.in", "r", stdin); 8 | freopen ("prieten.out", "w", stdout); 9 | scanf ("%d%d", &n, &k); 10 | scanf ("%lld", &S); 11 | for (i=1; i<=k; ++i) 12 | printf ("%lld ", (n+1)*i); 13 | printf ("\n"); 14 | for (i=1; i<=500000; ++i) 15 | { 16 | if (2*S==i*(i-1)*(i+1)) 17 | { 18 | printf ("%d\n", i); 19 | return 0; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /prieteni1.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | int i,j,n,K,v1,v2; 5 | int main () 6 | { 7 | freopen ("prieteni1.in", "r", stdin); 8 | freopen ("prieteni1.out", "w", stdout); 9 | 10 | scanf ("%d%d", &n, &K); 11 | 12 | v1=n/2; v2=n-v1; 13 | 14 | if (K<=v1*v2) { 15 | printf ("1\n"); 16 | for (i=1; i<=v1 && K; ++i) 17 | for (j=v1+1; j<=n && K; ++j) { 18 | printf ("%d %d\n", i, j); 19 | --K; 20 | } 21 | } 22 | else printf ("0\n"); 23 | 24 | 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /problema cu becuri.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | ifstream f("pcb.in"); 7 | ofstream g("pcb.out"); 8 | queue q; 9 | vector v[100005]; 10 | int i,j,n,m,x,y,X; 11 | int ap[100005]; 12 | void BFS (int k) 13 | { 14 | int i; 15 | q.push(k); 16 | while (! q.empty()) 17 | { 18 | k=q.front (); q.pop(); 19 | for (i=0; i>n>>m>>X; ++X; 32 | for (i=1; i<=m; ++i) 33 | { 34 | f>>x>>y; 35 | v[x].push_back(y+1); 36 | v[y+1].push_back(x); 37 | } 38 | BFS (1); 39 | if (! ap[X]) g<<"-1\n"; 40 | else g< 2 | # include 3 | using namespace std; 4 | ifstream f("proc.in"); 5 | ofstream g("proc.out"); 6 | int i,j,n,m,mij,ci,cs,unu,doi,p,sol; 7 | bool verificare (int G) 8 | { 9 | int U=unu, D=doi,timp,pot; 10 | for (int i=1; i<=p; ++i) 11 | { 12 | timp=0; 13 | if (D) 14 | { 15 | pot=G/i/2; 16 | timp=2*i*min(D, pot); 17 | D-=min(D, pot); 18 | } 19 | if (U) 20 | { 21 | pot=(G-timp)/i; 22 | U-=min(U, pot); 23 | } 24 | } 25 | if (U || D) return 0; 26 | else return 1; 27 | } 28 | int main () 29 | { 30 | f>>n>>unu>>p; 31 | doi=n-unu; 32 | 33 | ci=0; cs=unu+2*doi; 34 | while (ci<=cs) 35 | { 36 | mij=(ci+cs)/2; 37 | if (verificare (mij)) sol=mij, cs=mij-1; 38 | else ci=mij+1; 39 | } 40 | g< 2 | # include 3 | # include 4 | # define NR 100005 5 | # define mod 9001 6 | using namespace std; 7 | ifstream f("propozitie.in"); 8 | ofstream g("propozitie.out"); 9 | int i,j,n,m,K,poz,VV; 10 | int P[NR], sum[NR], bit[NR], nr[NR]; 11 | char s[NR]; 12 | int main () 13 | { 14 | f>>n>>K; f.get(); 15 | f.getline (s+1, NR); 16 | for (i=1; i<=n; ++i) 17 | if (s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u') bit[i]=1; 18 | else bit[i]=0; 19 | 20 | nr[1]=1; sum[1]=1; 21 | if (bit[1]) P[++VV]=1; 22 | for (i=2; i<=n; ++i) 23 | { 24 | if (bit[i]) P[++VV]=i; 25 | 26 | if (VV<=K) nr[i]=sum[i-1]+1; 27 | else { 28 | poz=P[VV-K]; 29 | nr[i]=(nr[i-1] + mod+sum[i-2]-sum[poz-1])%mod; 30 | } 31 | 32 | sum[i]=(sum[i-1]+nr[i])%mod; 33 | } 34 | 35 | g< 2 | using namespace std; 3 | int n, m, k, D, VV; 4 | bool a[2*1505][2*1505]; 5 | int nr[2*1505][2*1505]; 6 | int main() 7 | { 8 | freopen ("pseudobil.in", "r", stdin); 9 | freopen ("pseudobil.out", "w", stdout); 10 | int i,j,x,y,T,v1,v2; 11 | scanf ("%d%d%d%d", &T, &n, &k, &D); 12 | for (i=1; i<=k; ++i) 13 | { 14 | scanf ("%d%d", &x, &y); 15 | a[x+y-1][n-x+y] = 1; 16 | } 17 | for (i=1; i<=2*n-1; ++i) 18 | for (j=1; j<=2*n-1; ++j) 19 | nr[i][j]=a[i][j]+nr[i-1][j]+nr[i][j-1]-nr[i-1][j-1]; 20 | if (T==1) {x=D/2-1; printf ("%d\n", 2*x*x+D-1);} 21 | else 22 | { 23 | scanf ("%d", &m); 24 | for (i=1; i<=m; ++i) 25 | { 26 | scanf ("%d%d", &x, &y); 27 | v1=x+y-1; v2=n-x+y; 28 | VV=nr[v1+D][v2]-nr[v1+D][v2-D-1]-nr[v1-1][v2]+nr[v1-1][v2-D-1]; 29 | printf ("%d\n", VV); 30 | } 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /puncte.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | -------------------------------------------------------------------------------- /puncte2.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("puncte2.in"); 5 | ofstream g("puncte2.out"); 6 | int i,j,n; 7 | int a[100]; 8 | int main () 9 | { 10 | f>>n; a[1]=1; a[0]=1; 11 | for (i=2; i<=n; ++i) 12 | { 13 | a[i]=a[i-1]; 14 | for (j=i-1; j>=1; --j) 15 | a[i]+=(a[i-j]*a[j-1]); 16 | } 17 | g< 2 | # define inf 1000000000 3 | using namespace std; 4 | int a[10005],v[150005],ap[100005]; 5 | int i,j,n,k,trb,poz,minn,maxx; 6 | int main () 7 | { 8 | freopen ("punctfix.in", "r", stdin); 9 | freopen ("punctfix.out", "w", stdout); 10 | scanf ("%d", &n); 11 | for (i=1; i<=n; ++i) 12 | scanf ("%d", &a[i]); 13 | 14 | scanf ("%d", &k); 15 | minn=inf; maxx=inf; 16 | for (i=1; i<=k; ++i) 17 | { 18 | scanf ("%d", &v[i]); 19 | if (v[i]maxx) maxx=v[i]; 21 | } 22 | for (i=1; i<=n; ++i) 23 | { 24 | trb=i-a[i]; 25 | if (trb>=minn && trb<=maxx) 26 | { 27 | ++ap[trb-minn]; 28 | } 29 | } 30 | 31 | for (i=1; i<=k; ++i) 32 | printf ("%d\n", ap[v[i]-minn]); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /pviz.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define MOD 10007 4 | # define NR 2005 5 | using namespace std; 6 | int i,j,n,m; 7 | int a[NR][NR], nr[NR]; 8 | int main () 9 | { 10 | freopen ("pviz.in", "r", stdin); 11 | freopen ("pviz.out", "w", stdout); 12 | scanf ("%d%d", &n, &m); 13 | for (i=1; i<=m; ++i) 14 | scanf ("%d", &nr[i]); 15 | 16 | a[1][1]=1; 17 | 18 | for (i=1; i<=n; ++i) 19 | for (j=1; j<=min(i,m); ++j) 20 | { 21 | a[i][j]+=a[i-1][j-1]; //adaug un nou element vizibil 22 | a[i][j]+=(nr[j]-i+1)*a[i-1][j]; //adaug un element "invizibil" 23 | 24 | if (a[i][j]>=MOD) a[i][j]%=MOD; 25 | } 26 | 27 | 28 | printf ("%d\n", a[n][m]); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /qtri.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("qtri.in"); 6 | ofstream g("qtri.out"); 7 | struct elem 8 | { 9 | int x1,x2,x3,X,y1,y2,y3,Y; 10 | }a; 11 | int i,A1,A2,A3,A,n; 12 | int arie (int x1, int y1, int x2, int y2, int x3, int y3) 13 | { 14 | int rez; 15 | rez=x1*y2+x2*y3+x3*y1-x1*y3-x3*y2-x2*y1; 16 | rez=abs(rez); 17 | return rez; 18 | } 19 | int main () 20 | { 21 | f>>n; 22 | for (i=1; i<=n; ++i) 23 | { 24 | f>>a.x1>>a.y1>>a.x2>>a.y2>>a.x3>>a.y3>>a.X>>a.Y; 25 | A1=arie(a.x1,a.y1,a.x2,a.y2,a.X,a.Y); 26 | A2=arie(a.x1,a.y1,a.x3,a.y3,a.X,a.Y); 27 | A3=arie(a.x2,a.y2,a.x3,a.y3,a.X,a.Y); 28 | A=arie(a.x1,a.y1,a.x2,a.y2,a.x3,a.y3); 29 | 30 | if (A1+A2+A3==A) g<<"DA\n"; 31 | else g<<"NU\n"; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /raco back.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | ifstream f("raco.in"); 4 | ofstream g("raco.out"); 5 | int sol, st[100], VV, a[100], n, MOD, i; 6 | long long suma; 7 | void back (int k) { 8 | if (st[k-1]<=n) { 9 | if (st[k-1]>0 && (int)(suma%MOD)==0) ++sol; 10 | 11 | for (int i=st[k-1]+1; i<=n; ++i) { 12 | suma+=a[i]; st[k]=i; 13 | back(k+1); 14 | suma-=a[i]; st[k]=0; 15 | } 16 | 17 | } 18 | } 19 | int main () 20 | { 21 | f>>n>>MOD; 22 | for (i=1; i<=n; ++i) 23 | f>>a[i]; 24 | 25 | back (1); 26 | g< 2 | # define NR 10000005 3 | using namespace std; 4 | ifstream f("radixsort.in"); 5 | ofstream g("radixsort.out"); 6 | queue Q[1<<8]; 7 | int i,j,n,m,VV,A,B,C,biti,U; 8 | int v[NR]; 9 | int mask = (1<<8)-1; 10 | int main () 11 | { 12 | f>>n>>A>>B>>C; 13 | v[1]=B; 14 | for (i=2; i<=n; ++i) 15 | v[i]=(1LL * A * v[i-1] + B) % C; 16 | 17 | for (biti=0; biti<32; biti+=8) { 18 | for (i=1; i<=n; ++i) { 19 | U = (v[i] >> biti) & mask; 20 | Q[U].push(v[i]); 21 | } 22 | VV=0; 23 | for (i=0; i<(1<<8); ++i) { 24 | while (! Q[i].empty()) { 25 | v[++VV]=Q[i].front(); 26 | Q[i].pop(); 27 | } 28 | } 29 | } 30 | for (i=1; i<=n; i+=10) 31 | g< 2 | # include 3 | # define NR 105 4 | # define inf 999999 5 | using namespace std; 6 | ifstream f("raft.in"); 7 | ofstream g("raft.out"); 8 | int i,j,n,m,x,y,nr,k,ci,cs,minn; 9 | int cost[NR], H[NR]; 10 | int maxim (int a, int b, int c) 11 | { 12 | return max (a, max(b,c)); 13 | } 14 | int minim (int a, int b, int c) 15 | { 16 | return min (a, min(b,c)); 17 | } 18 | int main () 19 | { 20 | f>>m>>n>>nr; 21 | for (i=1; i<=nr; ++i) 22 | { 23 | f>>y>>x; 24 | H[y]=max(H[y], x); 25 | } 26 | 27 | for (i=1; i<=m; ++i) 28 | { 29 | cost[i]=minim(cost[i-1]+H[i], cost[i-2]+max(H[i-1], H[i]), cost[i-3]+maxim(H[i-2], H[i-1], H[i])); 30 | } 31 | 32 | 33 | 34 | g< 2 | # include 3 | # define NR 10005 4 | using namespace std; 5 | int i,j,n,rafturi,x,y; 6 | int maxx[NR], minn[NR]; 7 | int main () 8 | { 9 | freopen ("rafturi.in", "r", stdin); 10 | freopen ("rafturi.out", "w", stdout); 11 | scanf ("%d%d", &rafturi, &n); 12 | for (i=1; i<=n; ++i) 13 | { 14 | scanf ("%d%d", &x, &y); 15 | maxx[x]=max(maxx[x], y); 16 | } 17 | for (i=1; i<=rafturi; ++i) 18 | { 19 | minn[i]=minn[i-1]+maxx[i]; 20 | if (i>=2) minn[i]=min(minn[i], minn[i-2]+max(maxx[i], maxx[i-1])); 21 | if (i>=3) minn[i]=min(minn[i], minn[i-3]+max(maxx[i], max(maxx[i-1], maxx[i-2]))); 22 | } 23 | printf ("%d\n", minn[rafturi]); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /random teams.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | long long n,m,minn,maxx,intreg,nr,rest; 4 | int main () 5 | { 6 | cin>>n>>m; 7 | //minim 8 | nr=n/m; 9 | rest=n%m; 10 | minn=(nr-1)*nr/2*m+rest*nr; 11 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ifstream f("random.in"); 8 | ofstream cout("random.out"); 9 | int n; 10 | f>>n; 11 | if (n == 1982) cout<<"Robert Tarjan"; 12 | if (n == 1986) cout<<"Leslie Valiant"; 13 | if (n == 1990) cout<<"Alexander Razborov"; 14 | if (n == 1994) cout<<"Avi Wigderson"; 15 | if (n == 1998) cout<<"Peter Shor"; 16 | if (n == 2002) cout<<"Madhu Sudan"; 17 | if (n == 2006) cout<<"Jon Kleinberg"; 18 | if (n == 2010) cout<<"Daniel Spielman"; 19 | if (n == 2014) cout<<"Subhash Khot"; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /rec.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define MOD 666013 4 | # define NR 12005 5 | using namespace std; 6 | ifstream f("rec.in"); 7 | ofstream g("rec.out"); 8 | int i,j,n,m,S,F,nou,act; 9 | long long a[3][NR]; 10 | int main () 11 | { 12 | f>>S>>n>>F; 13 | 14 | S=S-n*F; 15 | 16 | // a[i][j] - numarul de moduri de a forma suma j din i numere 17 | act=0; 18 | for (i=1; i<=n; ++i) { 19 | nou=1-act; 20 | a[nou][0]=1; 21 | for (j=1; j<=S; ++j) { 22 | a[nou][j]=a[act][j]; 23 | if (j>=i) a[nou][j]+=a[nou][j-i]; 24 | 25 | } 26 | act=nou; 27 | } 28 | g< 2 | # define NR 100005 3 | using namespace std; 4 | //ifstream f("test.in"); 5 | //ofstream g("test.out"); 6 | struct elem { 7 | int val, poz; 8 | }a[NR]; 9 | bool cmp (elem x, elem y) { 10 | return x.val > y.val; 11 | } 12 | 13 | int maxx,i,j,n; 14 | int lg[NR]; 15 | 16 | void logaritmi () { 17 | for (int i=2; i<=n; ++i) 18 | lg[i]=lg[i/2]+1; 19 | } 20 | int suma (int i, int j) { 21 | return a[i].val + a[j].val - lg[abs(a[i].poz - a[j].poz)]; 22 | } 23 | int main () 24 | { 25 | cin>>n; logaritmi (); 26 | for (i=1; i<=n; ++i) { 27 | cin>>a[i].val; a[i].poz=i; 28 | } 29 | sort (a+1, a+n+1, cmp); 30 | 31 | maxx=suma (1, 2); 32 | 33 | for (i=1; i<=n; ++i) { 34 | for (j=i+1; j<=n && maxx-suma(i, j) <= 20; ++j) { 35 | maxx=max(maxx, suma(i, j)); 36 | } 37 | } 38 | cout< 2 | # include 3 | # define NR 500005 4 | using namespace std; 5 | ifstream f("reguli.in"); 6 | ofstream g("reguli.out"); 7 | long long i,j,n,ant,x,VV,q; 8 | long long a[NR],pi[NR]; 9 | int main () 10 | { 11 | int i,VV=0; 12 | f>>n; f>>ant; 13 | for (i=2; i<=n; ++i) 14 | { 15 | f>>x; 16 | a[++VV]=x-ant; 17 | ant=x; 18 | } 19 | 20 | for (i=2; i<=VV; ++i) 21 | { 22 | while (q && a[i]!=a[q+1]) 23 | q=pi[q]; 24 | 25 | if (a[i]==a[q+1]) ++q; 26 | pi[i]=q; 27 | } 28 | g< 2 | # include 3 | # define NR 1005 4 | using namespace std; 5 | int i,j,n,m; 6 | int a[NR]; 7 | int main () 8 | { 9 | freopen ("riglef.in", "r", stdin); 10 | freopen ("riglef.out", "w", stdout); 11 | scanf ("%d", &n); 12 | for (i=1; i<=n; ++i) 13 | scanf ("%d", &a[i]); 14 | 15 | printf ("3\n"); 16 | 17 | 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /robot.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define MOD 64997 3 | using namespace std; 4 | ifstream f("robot.in"); 5 | ofstream g("robot.out"); 6 | int 7 | int main () 8 | { 9 | 10 | 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /royfloyd.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | # define NR 105 6 | using namespace std; 7 | ifstream f("royfloyd.in"); 8 | ofstream g("royfloyd.out"); 9 | int R,i,j,n,m,VV,k; 10 | int a[NR][NR]; 11 | int main () 12 | { 13 | f>>n; 14 | for (i=1; i<=n; ++i) 15 | for (j=1; j<=n; ++j) 16 | f>>a[i][j]; 17 | 18 | for (k=1; k<=n; ++k) 19 | for (i=1; i<=n; ++i) 20 | for (j=1; j<=n; ++j) 21 | if (i!=j && a[i][k] && a[k][j] && (! a[i][j] || a[i][k] + a[k][j] < a[i][j])) 22 | a[i][j]=a[i][k] + a[k][j]; 23 | 24 | for (i=1; i<=n; ++i) { 25 | for (j=1; j<=n; ++j) 26 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("rucsac.in"); 5 | ofstream g("rucsac.out"); 6 | int i,j,n,G,gr,P; 7 | int a[10005]; 8 | int main () 9 | { 10 | f>>n>>G; 11 | 12 | for (i=1; i<=n; ++i) 13 | { 14 | f>>gr>>P; 15 | 16 | for (j=G-gr; j>=0; --j) 17 | { 18 | if (a[j+gr] 2 | # include 3 | # include 4 | # define NR 80005 5 | 6 | using namespace std; 7 | ifstream f("sccm.in"); 8 | ofstream g("sccm.out"); 9 | 10 | int main () 11 | { 12 | f>>n>>m; 13 | for (i=1; i<=n; ++i) { 14 | f>>x; 15 | ap[x].unu=i; 16 | ap[x].i=i; 17 | } 18 | for (i=1; i<=m; ++i) { 19 | f>>x; ap2[x]=i; 20 | } g< 2 | # define NR 100005 3 | using namespace std; 4 | ifstream f("scmax.in"); 5 | ofstream g("scmax.out"); 6 | int i,j,n,m,ci,cs,VV,poz,I,ant,mij,nrsol; 7 | int a[NR], st[NR], L[NR], sol[NR]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | f>>a[i]; 13 | 14 | for (i=1; i<=n; ++i) { 15 | if (a[i] > st[VV]) st[++VV]=a[i], L[i]=VV; 16 | else { 17 | ci=1; cs=VV; 18 | while (ci<=cs) { 19 | mij=(ci + cs)/2; 20 | if (a[i]<=st[mij]) cs=mij-1, poz=mij; 21 | else ci=mij+1; 22 | } 23 | st[poz]=a[i]; L[i]=poz; 24 | } 25 | } 26 | I=VV+1; ant=st[VV]+1; 27 | for (i=n; i>=1; --i) { 28 | if (L[i]==I-1 && ant > a[i]) { 29 | --I; sol[I]=a[i]; 30 | ant=a[i]; 31 | } 32 | } 33 | 34 | g< 2 | # include 3 | # include 4 | # include 5 | # define NR 1100000 6 | # define f first 7 | # define s second 8 | using namespace std; 9 | 10 | multimap M; 11 | int i,j,n,m,L,U; 12 | int cod[NR]; 13 | unsigned int A[NR]; 14 | // numarul de secvente cu pana la L elemente diferite 15 | int main () 16 | { 17 | M.insert(make_pair(5, 7)); 18 | M.insert(make_pair(9, 7)); 19 | M.insert(make_pair(5, 10)); 20 | 21 | std::multimap::iterator it = M.find(std::pair(5,10)); 22 | 23 | M.erase(it); 24 | for (it=M.begin(); it!=M.end(); ++it) 25 | cout<first<<" "<second<<"\n"; 26 | 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /secventak.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define LB(p) ((-p)&p) 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("secventak.in"); 7 | ofstream g("secventak.out"); 8 | int i,j,n,m,K,ind; 9 | int AIB[NR]; 10 | long long a[NR], var[NR], S[NR], aux, sol; 11 | int query (int poz) { 12 | int sol=0; 13 | for (int i=poz; i>=1; i-=LB(i)) 14 | sol+=AIB[i]; 15 | return sol; 16 | } 17 | void update (int poz) { 18 | for (int i=poz; i<=n+1; i+=LB(i)) 19 | ++AIB[i]; 20 | } 21 | int main () 22 | { 23 | f>>n>>K; 24 | 25 | // Sb - k*b >= Sa - k*a 26 | for (i=2; i<=n+1; ++i) { 27 | f>>a[i]; S[i]=S[i-1] + a[i]; 28 | var[i]=S[i] - 1LL*K*i; 29 | } 30 | 31 | sort (var+1, var+n+2); 32 | 33 | for (i=1; i<=n+1; ++i) { 34 | aux=S[i] - 1LL*K*i; 35 | ind=lower_bound(var+1, var+n+2, aux) - var; 36 | 37 | sol+=query(ind); 38 | update (ind); 39 | } 40 | g< 2 | # define NR 100005 3 | using namespace std; 4 | ifstream f("secvmin.in"); 5 | ofstream g("secvmin.out"); 6 | int i,j,n,m,P,sol,x; 7 | int poz[10*NR], a[NR], OK[10*NR]; 8 | int main () 9 | { 10 | f>>n>>m; 11 | for (i=1; i<=n; ++i) 12 | f>>a[i]; 13 | 14 | for (i=1; i<=m; ++i) { 15 | f>>x; poz[x]=i; 16 | } 17 | sol=999999; 18 | for (i=1; i<=n; ++i) { 19 | P=poz[a[i]]; 20 | if (P) { 21 | if (P==1) 22 | OK[P]=max(OK[P], i); 23 | else OK[P]=max(OK[P], OK[P-1]); 24 | 25 | if (P==m && OK[P]) 26 | sol=min(sol, i - OK[P]+1); 27 | } 28 | } 29 | if (sol==999999) g<<"-1\n"; 30 | else g< 2 | # include 3 | # include 4 | # include 5 | # include 6 | # include 7 | # define inf 999999999 8 | using namespace std; 9 | ifstream f("seg.in"); 10 | ofstream g("seg.out"); 11 | int i,j,n,k,l; 12 | char s[1000010]; 13 | int main () 14 | { 15 | 16 | 17 | 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /semipalindrom onis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | ifstream fin("semipal.in"); 4 | ofstream fout("semipal.out"); 5 | int t,n,VV; 6 | long long k; 7 | char sol[1005]; 8 | void semipal(long long nr, int t) 9 | { 10 | if (t) 11 | { 12 | semipal(nr>>1,t-1); 13 | sol[++VV]=(char)((nr&1)+'a'); 14 | } 15 | } 16 | int main() 17 | { 18 | int i; 19 | fin>>t; 20 | for (i=1;i<=t;++i) 21 | { 22 | fin>>n>>k; VV=0; 23 | if (k>(1LL<<(n-2))) 24 | { 25 | sol[++VV]='b'; 26 | semipal(k-(1LL<<(n-2))-1,n-2); 27 | sol[++VV]='b'; 28 | } 29 | else 30 | { 31 | sol[++VV]='a'; 32 | semipal(k-1,n-2); 33 | sol[++VV]='a'; 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /shades of prime.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | long long ci, cs, dif, i; 4 | long long cmmdc (long long a, long long b) { 5 | long long R; 6 | while (b!=0) { 7 | R=a%b; 8 | a=b; 9 | b=R; 10 | } 11 | return a; 12 | } 13 | int main () 14 | { 15 | cin>>ci>>cs; 16 | 17 | for (dif=cs-ci; dif>=1; --dif) { 18 | for (i=ci; i+dif<=cs; ++i) { 19 | if (cmmdc(i, i+dif)==1) { 20 | cout< 2 | using namespace std; 3 | long long n,x; 4 | int test,i,COUNT,VV,u,k,j; 5 | int used[20]; 6 | int main() 7 | { 8 | freopen("test.in","r",stdin); 9 | freopen("test.out","w",stdout); 10 | scanf("%d",&test);k=0; 11 | while(test>0) { 12 | --test;++k; 13 | scanf("%lld",&n); 14 | if(n == 0) {printf("CASE #%d: INSOMNIA\n",k);continue;} 15 | memset(used,0,sizeof(used)); 16 | VV=0; i=1; COUNT=0; 17 | while(VV == 0) { 18 | x=i * n; 19 | while(x > 0) { 20 | u= x % 10; 21 | if(used[u] == 0) {++COUNT;used[u]=1;} 22 | x/=10; 23 | } 24 | if(COUNT == 10) break; 25 | ++i; 26 | } 27 | printf("CASE #%d: %lld\n",k,n*i); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /shgraf.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define MOD 30011 4 | using namespace std; 5 | int i,j,n,k,o; 6 | int moduri[251]; //nr de moduri cu suma [i] 7 | int S[251]; 8 | int main () 9 | { 10 | freopen ("shgraf.in", "r", stdin); 11 | freopen ("shgraf.out", "w", stdout); 12 | scanf ("%d%d", &n, &k); 13 | 14 | for (i=k; i<=n; ++i)//fiecare ciclu nou adaugat 15 | { 16 | for (j=i; j<=n; j+=i)//de cate ori il adaug 17 | for (o=n-j; o>=k; --o)//fiecare suma anterioara posibila 18 | S[o+j]+=moduri[o]; 19 | 20 | for (j=k; j<=n; ++j) 21 | { 22 | if (j%i==0) ++S[j]; 23 | moduri[j]=(moduri[j]+S[j])%MOD; 24 | S[j]=0; 25 | } 26 | } 27 | printf ("%d\n", moduri[n]); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /shop.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 1005 5 | using namespace std; 6 | ifstream f("shop.in"); 7 | ofstream g("shop.out"); 8 | int i,j,n; 9 | double minn[NR],var[5],a[NR]; 10 | int main () 11 | { 12 | f>>n; 13 | for (i=1; i<=n; ++i) 14 | f>>a[i]; 15 | 16 | for (i=1; i<=n; ++i) 17 | { 18 | //s 19 | minn[i]=minn[i-1]+a[i]; 20 | //d 21 | if (i>=2) minn[i]=min(minn[i], minn[i-2]+max(a[i], a[i-1])+min(a[i], a[i-1])/2); 22 | //t 23 | if (i>=3) 24 | { 25 | var[1]=a[i-2]; var[2]=a[i-1]; var[3]=a[i]; 26 | sort (var+1, var+3+1); 27 | minn[i]=min(minn[i], minn[i-3]+var[3]+var[2]); 28 | } 29 | } 30 | g< 2 | # define NR 1005 3 | using namespace std; 4 | //ifstream f("sick.in"); 5 | //ofstream g("sick.out"); 6 | vector v[NR]; 7 | int i,j,n,m,x,y,minn,D,sol; 8 | int minim[NR], sick[NR], ap[NR]; 9 | int main () 10 | { 11 | cin>>D>>n>>m; 12 | for (i=1; i<=n; ++i) { 13 | cin>>sick[i]; 14 | ap[sick[i]]=1; 15 | } 16 | sort (sick+1, sick+n+1); 17 | for (i=1; i<=D; ++i) 18 | minim[i]=9999; 19 | for (i=1; i<=m; ++i) { 20 | cin>>x>>y; if (x>y) swap(x, y); 21 | 22 | v[y].push_back(x); 23 | } 24 | sol=9999; 25 | for (i=1; i<=D; ++i) { 26 | minn=564564; 27 | if (! ap[i]) minn=min(minn, minim[i-1]); 28 | for (auto &x: v[i]) 29 | minn=min(minn, minim[x-1]+1); 30 | 31 | minim[i]=minn; 32 | if (i>=sick[n]) sol=min(sol, minim[i]); 33 | } 34 | cout< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | int i,j,n,m,maxx,minn; 6 | int back[NR], front[NR], a[NR]; 7 | int main () 8 | { 9 | freopen ("sir2dif.in", "r", stdin); 10 | freopen ("sir2dif.out", "w", stdout); 11 | scanf ("%d", &n); 12 | for (i=1; i<=n; ++i) 13 | scanf ("%d", &a[i]); 14 | 15 | //front-ul 16 | maxx=a[1]; 17 | for (i=2; i<=n; ++i) 18 | { 19 | front[i]=maxx-a[i]; 20 | maxx=max(maxx, a[i]); 21 | } 22 | for (i=3; i<=n; ++i) 23 | front[i]=max(front[i], front[i-1]); 24 | 25 | //back 26 | minn=a[n]; 27 | for (i=n-1; i>=1; --i) 28 | { 29 | back[i]=a[i]-minn; 30 | minn=min(minn, a[i]); 31 | } 32 | for (i=n-2; i>=1; --i) 33 | back[i]=max(back[i], back[i+1]); 34 | 35 | maxx=-99999999; 36 | for (i=2; i<=n-2; ++i) 37 | maxx=max(maxx, front[i]+back[i+1]); 38 | printf ("%d\n", maxx); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /siruri1.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | ifstream f("date.in"); 6 | ofstream g("date.out"); 7 | int i,j,n,ok,l; 8 | char ch1,ch2,s[105]; 9 | int main() 10 | { 11 | f.getline(s, 100); 12 | l=strlen(s); 13 | ok=1; 14 | for(i=1;i<=l-1;i++) 15 | if(s[i]-s[i-1]!=1) ok=0; 16 | g< 2 | # include 3 | # include 4 | # include 5 | using namespace std; 6 | vector v[100005]; 7 | queue q; 8 | int i,j,n,m,x,y,start,ap[100005],maxx,maxim[100005]; 9 | void DFS (int k, int niv) 10 | { 11 | int i; 12 | ap[k]=niv; 13 | for (i=0; i 3 | # include 4 | # include 5 | using namespace std; 6 | ifstream f("sortaret.in"); 7 | ofstream g("sortaret.out"); 8 | vector v[50005]; 9 | int sol[50005],ap[50005]; 10 | int i,j,n,m,x,y,nrsol; 11 | void DFS (int k) 12 | { 13 | int i; 14 | ap[k]=1; 15 | for (i=0; i>n>>m; 22 | for (i=1; i<=m; ++i) 23 | { 24 | f>>x>>y; 25 | v[x].push_back(y); 26 | } 27 | for (i=1; i<=n; ++i) 28 | if (!ap[i]) DFS(i); 29 | for (i=n; i>=1; --i) 30 | g< 2 | # include 3 | # include 4 | # include 5 | # include 6 | # define NR 50005 7 | using namespace std; 8 | ifstream f("sortaret.in"); 9 | ofstream g("sortaret.out"); 10 | queue q; 11 | vector v[NR]; 12 | int i,j,x,y,n,m; 13 | int grad[NR]; 14 | void sortaret () { 15 | int i,k; 16 | while (! q.empty ()) { 17 | k=q.front(); q.pop(); 18 | g<>n>>m; 28 | for (i=1; i<=m; ++i) { 29 | f>>x>>y; 30 | v[x].push_back(y); 31 | ++grad[y]; 32 | } 33 | for (i=1; i<=n; ++i) 34 | if (grad[i]==0) q.push(i); 35 | sortaret (); 36 | 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /speeding.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | # include 3 | #include 4 | #include 5 | #define NMAX 1000 6 | using namespace std; 7 | ifstream f("speeding.in"); 8 | ofstream g("speeding.out"); 9 | int n,m,sum1,sum2,i,j,maxx,x,y,st1,st2; 10 | int ap1[NMAX],ap2[NMAX]; 11 | int main() 12 | { 13 | f>>n>>m; 14 | for(int i=1; i<=n; ++i) 15 | { 16 | f>>x>>y; 17 | for (j=1; j<=x; ++j) 18 | ap1[++st1]=y; 19 | } 20 | for(int i = 1; i <= m; ++i) 21 | { 22 | f>>x>>y; 23 | for (j=1; j<=x; ++j) 24 | ap2[++st2]=y; 25 | } 26 | sort(ap1+1, ap1+100+1); sort(ap2+1, ap2+100+1); 27 | 28 | for(int i = 1; i <= 100; ++i) 29 | maxx=max(ap2[i]-ap1[i], maxx); 30 | 31 | g< 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("spion.in"); 6 | ofstream g("spion.out"); 7 | bitset <50000005> ap; 8 | int i,n,x,s,d,grupuri; 9 | int main () 10 | { 11 | f>>n; 12 | for (i=1; i<=n; ++i) 13 | { 14 | f>>x>>s>>d; 15 | grupuri=grupuri+1-ap[s]-ap[d]; 16 | ap[x]=1; 17 | g< 2 | # include 3 | # define NR 1005 4 | # define inf 999999999 5 | using namespace std; 6 | ifstream f("split2.in"); 7 | ofstream g("split2.out"); 8 | int 9 | void init (int n, int m) 10 | { 11 | int i,j; 12 | for (i=1; i<=n; ++i) 13 | for (j=1; j<=m; ++j) 14 | cost[i][j]=inf; 15 | } 16 | int main () 17 | { 18 | f>>t; 19 | //cost[i][j]-costul minim sa impartim primele i numere in j subsecvente 20 | for (o=1; o<=t; ++o) 21 | { 22 | f>>n>>m; 23 | init (n,m); 24 | for (i=1; i<=n; ++i) 25 | { f>>a[i]; S[i]=S[i-1]+a[i]; } 26 | 27 | for (j=1; j<=m; ++j) 28 | for (i=2; i<=n; i=i+2) 29 | { 30 | 31 | } 32 | } 33 | 34 | 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /sport.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | using namespace std; 5 | ifstream f("sport.in"); 6 | ofstream g("sport.out"); 7 | vector v[10005]; 8 | int i,j,n,minn,MINN,VV,var; 9 | int a[1005],b[1005],poz[10005]; 10 | int main () 11 | { 12 | f>>n; 13 | for (i=1; i<=n; ++i) 14 | { 15 | f>>a[i]; b[i]=a[i]; 16 | poz[a[i]]=i; 17 | } 18 | sort(b+1,b+n+1); 19 | for (i=1; ipoz[VV]) {VV=v[VV][0]; ++minn;} 28 | else break; 29 | } 30 | if (n-minn 2 | using namespace std; 3 | ifstream f("ssm.in"); 4 | ofstream g("ssm.out"); 5 | int i,j,n,m,s,x,ci,cs,I,J,maxx; 6 | int main () 7 | { 8 | f>>n; maxx=-99999999; 9 | s=-999999999; ci=1; 10 | for (i=1; i<=n; ++i) 11 | { 12 | f>>x; 13 | if (s+x>=x) 14 | { 15 | s=s+x; 16 | ++cs; 17 | } 18 | else 19 | { 20 | s=x; 21 | ci=cs=i; 22 | } 23 | if (s>maxx) maxx=s, I=ci, J=cs; 24 | } 25 | g< 2 | # include 3 | # define NR 3000005 4 | using namespace std; 5 | ifstream f("sdo.in"); 6 | ofstream g("sdo.out"); 7 | int i,j,n,k; 8 | int a[NR]; 9 | int main () 10 | { 11 | f>>n>>k; 12 | for (i=1; i<=n; ++i) 13 | f>>a[i]; 14 | 15 | nth_element (a+1, a+k, a+n+1); 16 | g< 2 | # include 3 | # define NMax 505 4 | using namespace std; 5 | ifstream f("stiva.in"); 6 | ofstream g("stiva.out"); 7 | int n,i,d,t,j,o; 8 | char s[NMax+1]; 9 | int minn[NMax][NMax]; 10 | int main() 11 | { 12 | f.getline(s+1, 1005); 13 | n=strlen(s+1); 14 | for (i=1; i<=n; ++i) minn[i][i]=1; 15 | 16 | for (d=2; d<=n; ++d) 17 | for (i=1; i+d-1<=n; ++i) 18 | { 19 | j=i+d-1; 20 | minn[i][j]=minn[i][j-1]+1; 21 | for (o=i; o 2 | using namespace std; 3 | int i,j,n,VV,var,N; 4 | int a[30005],sol[20][30005],nr[20]; 5 | int main () 6 | { 7 | freopen ("stive.in", "r", stdin); 8 | freopen ("stive.out", "w", stdout); 9 | scanf ("%d", &n); 10 | for (i=1; i<=n; ++i) 11 | a[i]=i; 12 | N=n; 13 | while (N) 14 | { 15 | var=(N+1)/2; ++VV; nr[VV]=var; 16 | for (i=1; i<=n; ++i) 17 | if (a[i]>=var) a[i]-=var,sol[VV][++sol[VV][0]]=i; 18 | N=N-var; 19 | } 20 | printf ("%d\n", VV); 21 | for (i=1; i<=VV; ++i) 22 | { 23 | printf ("%d ", sol[i][0]); 24 | for (j=1; j<=sol[i][0]; ++j) 25 | printf ("%d ", sol[i][j]); 26 | printf ("%d\n", nr[i]); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /strategie.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define LB(p) ((-p) & p) 3 | using namespace std; 4 | ifstream f("strategie.in"); 5 | ofstream g("strategie.out"); 6 | int i,j,n,m,r; 7 | int a[100],AIB[100]; 8 | long long nr, VV; 9 | void update (int poz, int val) 10 | { 11 | for (int i=poz; i<=n; i+=LB(i)) 12 | AIB[i]+=val; 13 | } 14 | int suma (int poz) 15 | { 16 | int S=0; 17 | for (int i=poz; i>=1; i-=LB(i)) 18 | S+=AIB[i]; 19 | return S; 20 | } 21 | int main () 22 | { 23 | f>>n; 24 | for (i=1; i<=n; ++i) 25 | {f>>a[i]; update(i, 1);} 26 | 27 | for (i=1; i<=n; ++i) 28 | { 29 | r=suma(a[i]-1); 30 | if (r) //daca sunt elemente care trebuiau sa fie in fata lui 31 | { 32 | nr=1; //factorialul 33 | for (j=1; j<=n-i; ++j) 34 | nr=1LL*nr*j; 35 | VV+=(1LL*r*nr); 36 | } 37 | update (a[i], -1); 38 | } 39 | g< 2 | using namespace std; 3 | ifstream f("string.in"); 4 | ofstream g("string.out"); 5 | int i,j,n; 6 | int main () 7 | { 8 | string s="ABCDE"; 9 | 10 | s.push_back('F'); 11 | s.pop_back(); 12 | 13 | g< 2 | # define NR 100 3 | using namespace std; 4 | ifstream f("test.in"); 5 | ofstream g("test.out"); 6 | int i,j,n; 7 | char s[NR], s1[NR], s2[NR]; 8 | int main () 9 | { 10 | f>>s; 11 | strncpy(s1, s, 5); 12 | g< 2 | using namespace std; 3 | ifstream f("suma.in"); 4 | ofstream g("suma.out"); 5 | int n,p,i,S,S2; 6 | int v[5]; 7 | int main () 8 | { 9 | f>>n>>p; 10 | v[1]=n; v[2]=n+1; v[3]=2*n+1; 11 | for (i=1; i<=3; ++i) 12 | if (v[i]%2==0) {v[i]/=2; break;} 13 | for (i=1; i<=3; ++i) 14 | if (v[i]%3==0) {v[i]/=3; break;} 15 | S=(((v[1]%p)*(v[2]%p))%p)*(v[3]%p); 16 | S%=p; 17 | 18 | v[1]=n; v[2]=n+1; 19 | if (v[1]%2==0) v[1]=v[1]/2; 20 | else v[2]=v[2]/2; 21 | S2=(v[1]%p)*(v[2]%p); 22 | S2%=p; 23 | 24 | S=(p+S-S2)%p; 25 | g< 2 | # include 3 | # define N_Max 2100000 4 | using namespace std; 5 | ifstream f("sume.in"); 6 | ofstream g("sume.out"); 7 | int nr[N_Max+5],a[50005]; 8 | long long k,NR; 9 | int n,maxx,ci,cs,mij,var,sol; 10 | int main () 11 | { 12 | f>>n>>k; 13 | int i,j; 14 | for (i=1; i<=n; ++i) 15 | { 16 | f>>a[i]; 17 | ++nr[a[i]]; 18 | if (a[i]>maxx) maxx=a[i]; 19 | } 20 | sort (a+1,a+n+1); 21 | for (i=1; i<=N_Max; ++i) 22 | nr[i]+=nr[i-1]; 23 | 24 | ci=1; cs=2*maxx; 25 | while (ci<=cs) 26 | { 27 | mij=(ci+cs)/2; NR=0; 28 | for (i=1; i<=n && a[i]<=mij; ++i) 29 | NR=NR+nr[mij-a[i]]; 30 | if (NR>=k) cs=mij-1,sol=mij; 31 | else ci=mij+1; 32 | } 33 | g< 2 | # include 3 | # define MOD 578537 4 | using namespace std; 5 | ifstream f("sumk.in"); 6 | ofstream g("sumk.out"); 7 | int i,j,n,x,x2,y,y2,V1,V2,V3,k; 8 | void euclid (int a, int b, int &x, int &y) { 9 | if (b==0) { 10 | x=1; y=0; 11 | return; 12 | } 13 | int x0, y0; 14 | euclid (b, a%b, x0, y0); 15 | x=y0; 16 | y=x0 - (a/b)*y0; 17 | } 18 | int factorial (int K) { 19 | int nrsol=1; 20 | for (int i=2; i<=K; ++i) 21 | nrsol=1LL*nrsol*i%MOD; 22 | 23 | return nrsol; 24 | } 25 | int main () 26 | { 27 | f>>n>>k; 28 | 29 | V1=factorial (n*k+n-1); 30 | 31 | V2=factorial (n-1); 32 | euclid (V2, MOD, x, y); 33 | if (x<0) x=MOD + x%MOD; 34 | 35 | 36 | V3=factorial (n*k); 37 | euclid (V3, MOD, x2, y2); 38 | if (x2<0) x2=MOD + x2%MOD; 39 | 40 | g<<1LL*V1*x*x2%MOD<<"\n"; 41 | 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /tabara1.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 30005 4 | using namespace std; 5 | int i,j,n,m,x,VV,ci,cs,mij,poz; 6 | int ap[NR], a[NR], st[NR]; 7 | int main () 8 | { 9 | freopen ("tabara1.in", "r", stdin); 10 | freopen ("tabara1.out", "w", stdout); 11 | scanf ("%d", &n); 12 | for (i=1; i<=n; ++i) 13 | { 14 | scanf ("%d", &x); 15 | ap[x]=i; 16 | } 17 | for (i=1; i<=n; ++i) 18 | { 19 | scanf ("%d", &x); 20 | a[ap[x]]=i; 21 | } 22 | 23 | for (i=1; i<=n; ++i) 24 | { 25 | if (a[i]>st[VV]) st[++VV]=a[i]; 26 | else { 27 | ci=1; cs=VV; poz=VV; 28 | while (ci<=cs) 29 | { 30 | mij=(ci+cs)/2; 31 | if (st[mij] 2 | # include 3 | using namespace std; 4 | int a[5],minn,VV; 5 | int verificare () 6 | { 7 | if (a[1]+a[2]+a[3]<3) return 0; 8 | if (a[1]+a[2]+a[3]==a[3]) return 0; 9 | if (a[1]!=a[2] || a[1]!=a[3] || a[2]!=a[3]) return 1; 10 | return 0; 11 | } 12 | int main() 13 | { 14 | cin>>a[1]>>a[2]>>a[3]; 15 | sort (a+1,a+3+1); 16 | while (verificare()) 17 | { 18 | minn=min(a[2]-a[1],(a[3]-a[1])/2); 19 | minn=max(minn,1); 20 | a[2]=a[2]-minn; a[3]=a[3]-minn*2; 21 | VV+=minn; 22 | sort (a+1,a+3+1); 23 | } 24 | VV+=a[1]; 25 | cout< 2 | # include 3 | # include 4 | using namespace std; 5 | int i,j,n,m,k,l,minn,VV,I,cifre; 6 | char s[1000010]; 7 | int main () 8 | { 9 | freopen ("taie.in", "r", stdin); 10 | freopen ("taie.out", "w", stdout); 11 | scanf ("%d %d %d\n", &n, &k, &l); 12 | scanf ("%s", s+1); 13 | //incerc sa construiec cifra cu cifra 14 | VV=1; cifre=n-k*l; 15 | for (j=1; j<=cifre; ++j) 16 | { 17 | minn=s[VV]; I=VV; 18 | for (i=VV+l; i<=n-(cifre-j); i+=l) 19 | { 20 | if (s[i] 2 | #define INF 1e18+1 3 | using namespace std; 4 | unsigned long long x,y; 5 | int k; 6 | long long xmin,ymin; 7 | long long Min=INF; 8 | void verifmin(long long a,int b) 9 | { 10 | if (a+b=x) verifmin(cat,k); 19 | 20 | cat=x/p; 21 | while (cat*p=x && cat*p<=y) verifmin(cat,k); 26 | p=p*2; 27 | ++k; 28 | } 29 | } 30 | int main() 31 | { 32 | freopen("taste.in", "r", stdin); 33 | freopen("taste.out", "w", stdout); 34 | scanf("%lld%lld",&x,&y); 35 | gen(y); 36 | printf("%lld %lld\n",xmin,ymin); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /teamwork.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 500000 4 | using namespace std; 5 | ifstream f("teamwork.in"); 6 | ofstream g("teamwork.out"); 7 | int i,j,n,m,x,y,stop; 8 | int maxx[NR], bit[NR], a[20][20]; 9 | void biti () { 10 | for (i=1; i<=stop; ++i){ 11 | int VV=i; 12 | while (VV) { 13 | bit[i]+=VV%2; 14 | VV/=2; 15 | } 16 | } 17 | } 18 | int main () 19 | { 20 | f>>n; 21 | for (i=1; i<=n; ++i) 22 | for (j=1; j<=n; ++j) 23 | f>>a[i][j]; 24 | 25 | // maxx[i] - maximul pe care il pot obtine folosind 26 | // elevii bitii lui i, in biti[i] zile 27 | 28 | stop=(1< 2 | # include 3 | # include 4 | using namespace std; 5 | vector v[350]; 6 | int ap[35000]; 7 | int i,j,n,m,x,y,nrfii,M,N; 8 | void DFS (short k) 9 | { 10 | short i; 11 | ap[k]=1; 12 | for (i=0; i 2 | # include 3 | # define NR 15005 4 | using namespace std; 5 | ifstream f("date.in"); 6 | ofstream g("date.out"); 7 | int i,j,n,m,a[NR], b[NR]; 8 | int main () 9 | { 10 | f>>n; 11 | for (i=1; i<=n; ++i) 12 | f>>a[i]; 13 | for (i=1; i<=n; ++i) 14 | { 15 | f>>b[i]; 16 | if (a[i]!=b[i]) g< 2 | # define NR 100 3 | using namespace std; 4 | ifstream f("test.in"); 5 | ofstream g("test.out"); 6 | int i,j,n,m,val,x,y,z,k; 7 | char s[NR], *p, sol[NR], aux[NR]; 8 | int main () 9 | { 10 | f.getline (s, NR); 11 | p=strtok(s, " "); 12 | while (p) { 13 | strcpy(aux, p); 14 | if ('A'<=aux[0] && aux[0]<='Z') 15 | { sol[k]=aux[0]; ++k; } 16 | p=strtok(NULL, " "); 17 | } 18 | g< 2 | # include 3 | using namespace std; 4 | ifstream f("nrsubsircresc2.in"); 5 | ofstream g("nrsubsircresc2.out"); 6 | int i,j,n,m,P,nrsol,T; 7 | int var[50], a[50]; 8 | void back (int k) 9 | { 10 | if (k==P+1) ++nrsol; 11 | else { 12 | for (int i=var[k-1]+1; i<=n; ++i) 13 | if (a[i] > a[var[k-1]]){ 14 | var[k]=i; 15 | back(k+1); 16 | var[k]=0; 17 | } 18 | } 19 | } 20 | int main () 21 | { 22 | 23 | nrsol=0; 24 | f>>n>>P; 25 | for (i=1; i<=n; ++i) 26 | f>>a[i]; 27 | 28 | back(1); 29 | g< 2 | # define NR 100 3 | using namespace std; 4 | ifstream f("test.in"); 5 | ofstream g("test.out"); 6 | int i,j,n,m,val,aux,x,y,z; 7 | char s[NR], s2[NR], s3[NR], t[NR], *p, sol; 8 | int main () 9 | { 10 | f.getline (s, NR); 11 | p=strtok(p, ' '); 12 | while (p) { 13 | if ('A'<=p[0] && p[0]<='Z') 14 | sol[++k]=p[0]; 15 | p=strtok(NULL, ' '); 16 | } 17 | g< 2 | # define NR 100 3 | using namespace std; 4 | ifstream f("test.in"); 5 | ofstream g("test.out"); 6 | int i,j,n,m,val,x,y,z,k; 7 | char s[NR], *p, sol[NR], aux[NR]; 8 | int main () 9 | { 10 | f.getline (s, NR); 11 | p=strtok(s, " "); 12 | while (p) { 13 | strcpy(aux, p); 14 | if ('A'<=aux[0] && aux[0]<='Z') 15 | sol[++k]=aux[0]; 16 | p=strtok(NULL, " "); 17 | } 18 | g< 2 | # include 3 | # define inf 999999999 4 | # define NR 10005 5 | using namespace std; 6 | ifstream f("timbre.in"); 7 | ofstream g("timbre.out"); 8 | int i,j,n,m,x,y, I, minn, sol, K; 9 | int cs[NR], ap[NR], cost[NR]; 10 | int main () 11 | { 12 | f>>n>>m>>K; 13 | for (i=1; i<=m; ++i) 14 | f>>cs[i]>>cost[i]; 15 | 16 | for (i=n; i>=1; i-=K) 17 | { 18 | minn=inf; 19 | for (j=1; j<=m; ++j) 20 | if (! ap[j] && cs[j]>=i && cost[j] 2 | # define NR 10005 3 | using namespace std; 4 | ifstream f("towerx.in"); 5 | ofstream g("towerx.out"); 6 | int i,j,n,m,ok,last,act,nou; 7 | int poz[2][NR], sol[NR], Poz[NR]; 8 | int main () 9 | { 10 | f>>n; 11 | act=0; nou=1; 12 | for (i=1; i<=n; ++i) { 13 | poz[nou][1]=1; 14 | for (j=2; j<=i; ++j) { 15 | poz[nou][j] = poz[nou][j-1] + poz[act][j-1]; 16 | if (poz[nou][j] > i ) poz[nou][j]-=i; 17 | } 18 | Poz[i]=poz[nou][i]; 19 | swap (act, nou); 20 | } 21 | last=0; 22 | for (i=n; i>=1; --i) { 23 | ok=0; 24 | while (Poz[i]) { 25 | ++last; if (last==n+1) last=1; 26 | if (! sol[last]) --Poz[i]; 27 | } 28 | sol[last]=i; 29 | } 30 | for (i=1; i<=n; ++i) 31 | g< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "Hello world!" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /transformari.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define inf 999999999 4 | using namespace std; 5 | ifstream f("transformari.in"); 6 | ofstream g("transformari.out"); 7 | int i,j,n,minn,S,sol; 8 | int numara (int a, int b) 9 | { 10 | if (b==1) return a-1; 11 | if (b==0) return inf; 12 | 13 | //else 14 | return a/b + numara (b, a%b); 15 | } 16 | int main () 17 | { 18 | f>>n; minn=inf; 19 | for (i=1; i 2 | # include 3 | # define NR 200005 4 | using namespace std; 5 | ifstream f("tree.in"); 6 | ofstream g("tree.out"); 7 | vector v[NR]; 8 | int i,j,n,m,k,nrsol,x,S,ap[NR],ok; 9 | void DFS (int k) 10 | { 11 | int nr=0; 12 | for (int i=0; i1) nrsol=nrsol+nr-1, ap[k]=1; 19 | if (k==S && nr==1) ++nrsol; 20 | if (k==S && nr==0) ++nrsol; 21 | } 22 | int main () 23 | { 24 | f>>n; 25 | for (i=1; i<=n; ++i) 26 | { 27 | f>>x; 28 | if (x==0) S=i; 29 | else v[x].push_back(i); 30 | } 31 | DFS(S); 32 | nrsol=nrsol*2-1; 33 | 34 | if (n==0) nrsol=0; 35 | g< 2 | # include 3 | # define mil 1000005 4 | using namespace std; 5 | ifstream f("trigrame.in"); 6 | ofstream g("trigrame.out"); 7 | int i,j,n,m,L,maxx,N,nr1,nr2,nr3,K,l,q; 8 | int ap[200], VV[70][70][70]; 9 | char ch; 10 | void verif (int nr1, int nr2, int nr3) 11 | { 12 | ++VV[nr1][nr2][nr3]; 13 | if (VV[nr1][nr2][nr3]==1) ++N; 14 | if (VV[nr1][nr2][nr3]>maxx) maxx=VV[nr1][nr2][nr3],K=1; 15 | else if (VV[nr1][nr2][nr3]==maxx) ++K; 16 | } 17 | int main () 18 | { 19 | for (i=1; i<=3; ++i) 20 | { 21 | f>>ch; 22 | if (! ap[ch]) ap[ch]=++q; 23 | if (i==1) nr1=ap[ch]; 24 | else if (i==2) nr2=ap[ch]; 25 | else nr3=ap[ch]; 26 | } 27 | verif(nr1,nr2,nr3); 28 | 29 | while (f>>ch) 30 | { 31 | if (! ap[ch]) ap[ch]=++q; 32 | nr1=nr2; nr2=nr3; nr3=ap[ch]; 33 | verif(nr1,nr2,nr3); 34 | } 35 | g< 2 | using namespace std; 3 | ifstream f("triplet.in"); 4 | ofstream g("triplet.out"); 5 | int a,b,c,k; 6 | int main () 7 | { 8 | f>>k; 9 | if (k%2==1) c=0; 10 | else --k, c=1; 11 | a=(k-1)/2+1; 12 | b=-(k-1)/2; 13 | 14 | g< 2 | # include 3 | # include 4 | # include 5 | # define NR 100005 6 | using namespace std; 7 | ifstream f("turneu.in"); 8 | ofstream g("turneu.out"); 9 | int i,j,n,m,y,T,ok; 10 | long double S, Sreal, x; 11 | int main () 12 | { 13 | f>>T; 14 | for (int t=1; t<=T; ++t) { 15 | f>>n; ok=1; Sreal=0; 16 | 17 | for (i=1; i<=n; ++i) { 18 | f>>x; Sreal+=x; 19 | if (x > n-1) ok=0; 20 | if (1LL*(i-1)*(i)/2 > Sreal) ok=0; 21 | } 22 | if (Sreal != 1LL*1.0*(n)*(n-1)/2) ok=0; 23 | if (n==1) ok=0; 24 | 25 | if (ok) g<<"YES\n"; 26 | else g<<"NO\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /unordered_map test.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # define mp make_pair 3 | # define f first 4 | # define s second 5 | using namespace std; 6 | ifstream f("test.in"); 7 | ofstream g("test.out"); 8 | typedef pair mapkey; 9 | struct hashname { 10 | size_t operator()(const mapkey &key ) const { 11 | return hash()(key.first) ^ hash()(key.second); 12 | } 13 | }; 14 | unordered_map M; 15 | 16 | int i,j,n,m,x,VV; 17 | int main () { 18 | M[mp(1, 2)]=5; 19 | g< 2 | # define mp make_pair 3 | # define f first 4 | # define s second 5 | using namespace std; 6 | ifstream f("map.in"); 7 | ofstream g("map.out"); 8 | typedef pair mapkey; 9 | struct mapcmp { 10 | size_t operator() (const mapkey &key) const { 11 | return hash()(key.f) xor hash()(key.s); 12 | } 13 | }; 14 | 15 | int i; 16 | 17 | int main () 18 | { 19 | unordered_map M; 20 | 21 | M["ADA"]=2; 22 | M["MAIA"]=5; 23 | M["PANA"]=7; 24 | 25 | for (auto it=M.begin(); it!=M.end(); ++it) 26 | g<first<<" "<second<<"\n"; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /vectori pari.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | ifstream f("test.in"); 7 | ofstream g("test.out"); 8 | int n,i,ok,j,s; 9 | int main() 10 | { 11 | f>>n; 12 | ok=1; 13 | for(i=2; i<=n; i++) 14 | { 15 | ok=1; 16 | for(j=2; j<=sqrt(i); j++) 17 | if(i%j==0) ok=0; 18 | 19 | if(ok==1) 20 | s=s+i%3; 21 | 22 | } 23 | ok=1; 24 | for(i=2; i<=sqrt(s); i++) 25 | if(s%i==0) ok=0; 26 | if(ok==1) 27 | g<<"este prim"; 28 | else 29 | g<<"nu este prim"; 30 | 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /verifi pare.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,i,a[1000][1000],m,j,ok,s; 6 | 7 | int main() 8 | { 9 | cin>>n>>m; 10 | for(i=1;i<=n;i++) 11 | { 12 | for(j=1;j<=m;j++) 13 | cin>>a[i][j]; 14 | ok=1; 15 | for(j=2;j<=m;j++) 16 | if(a[i][j]!=a[i][j-1]) 17 | ok=0; 18 | if(ok==1) 19 | s++; 20 | } 21 | 22 | cout< 2 | # include 3 | # define NR 100005 4 | using namespace std; 5 | int i,j,n,rez,S,act,nou; 6 | int var[NR], ap[NR], g[NR]; 7 | int main () 8 | { 9 | freopen ("viena.in", "r", stdin); 10 | freopen ("viena.out", "w", stdout); 11 | 12 | scanf ("%d", &n); 13 | for (i=1; i<=n; ++i) { 14 | scanf ("%d", &g[i]); 15 | S+=g[i]; 16 | } 17 | 18 | var[++act]=0; 19 | for (i=1; i<=n; ++i) { 20 | nou=act; 21 | 22 | //le prelucrez pe actualele 23 | for (j=1; j<=act; ++j) { 24 | if (! ap[var[j]+g[i]]) var[++nou]=var[j]+g[i], ap[var[j]+g[i]]=1; 25 | if (g[i]%2==0 && ! ap[var[j]+g[i]/2]) var[++nou]=var[j]+g[i]/2, ap[var[j]+g[i]/2]=1; 26 | } 27 | act=nou; 28 | } 29 | rez=NR+5; 30 | for (i=1; i<=act; ++i) 31 | rez=min(rez, max(var[i], S-var[i])); 32 | 33 | printf ("%d\n", rez); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /vot1.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | ifstream f("vot1.in"); 5 | ofstream g("vot1.out"); 6 | queue q; 7 | int ap[1005],a[1005],nr[1005]; 8 | int i,j,n,K,x; 9 | void eliminare () 10 | { 11 | while (! q.empty()) 12 | { 13 | x=q.front (); q.pop (); 14 | ap[x]=1; ++K; 15 | --nr[a[x]]; 16 | if (nr[a[x]]==0) q.push(a[x]); 17 | } 18 | } 19 | int main () 20 | { 21 | f>>n; 22 | for (i=1; i<=n; ++i) 23 | { 24 | f>>a[i]; 25 | ++nr[a[i]]; 26 | } 27 | for (i=1; i<=n; ++i) 28 | if (nr[i]==0) q.push(i); 29 | eliminare (); 30 | g< 2 | # include 3 | # define NR 1000005 4 | using namespace std; 5 | int i,j,n,m,P; 6 | int a[NR]; 7 | long long S, solutie; 8 | int main () 9 | { 10 | cin>>n; 11 | for (i=1; i<=n; ++i) 12 | cin>>a[i]; 13 | cin>>P; 14 | 15 | for (i=1; i<=n; ++i) { 16 | S=0; 17 | for (j=i; j<=n; ++j) { 18 | S+=a[j]; 19 | 20 | if (S / (j-i+1) >= P) ++solutie; 21 | } 22 | } 23 | cout< 2 | # include 3 | using namespace std; 4 | ifstream f("xerox.in"); 5 | ofstream g("xerox.out"); 6 | int i,j,n,m,x,XOR,T,N; 7 | int main () 8 | { 9 | f>>T; 10 | for (int t=1; t<=T; ++t) 11 | { 12 | f>>n>>x>>x; 13 | XOR=0; 14 | for (j=1; j<=n; ++j) 15 | { 16 | f>>N; XOR^=N; 17 | for (int o=1; o<=2*N; ++o) 18 | f>>x; 19 | } 20 | if (XOR) g<<"1\n"; 21 | else g<<"0\n"; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /xorin.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 2005 4 | using namespace std; 5 | int i,j,n,m,X,aux,i2,j2; 6 | int a[NR][NR]; 7 | int main () { 8 | cin>>n>>m>>X; 9 | for (i=1; i<=n; ++i) 10 | for (j=1; j<=m; ++j) { 11 | cin>>aux; 12 | for (i2=1; i2<=X; ++i2) 13 | for (j2=1; j2<=X; ++j2) 14 | a[(i-1)*X+i2][(j-1)*X+j2]=aux; 15 | } 16 | 17 | for (i=1; i<=n*X; ++i) { 18 | for (j=1; j<=m*X; ++j) 19 | cout< 2 | # using namespace std 3 | # define NR 10005 4 | -------------------------------------------------------------------------------- /zlego.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # define NR 250005 4 | using namespace std; 5 | ifstream f("zlego.in"); 6 | ofstream g("zlego.out"); 7 | int i,j,n,m,o,t; 8 | int pi[NR], H[NR]; 9 | long long cost[NR]; 10 | void procesare () 11 | { 12 | int i,j,k=0; 13 | long long S=0; 14 | //prefix 15 | for (i=2; i<=n; ++i) 16 | { 17 | while (k>0 && H[k+1]!=H[i]) 18 | k=pi[k]; 19 | if (H[k+1]==H[i]) ++k; 20 | pi[i]=k; 21 | } 22 | for(i=n; i>=1; --i) 23 | cost[pi[i]]+=cost[i]; 24 | for(i=1; i<=n; ++i) 25 | g<>t; 30 | for (o=1; o<=t; ++o) 31 | { 32 | f>>n; 33 | for (i=1; i<=n; ++i) 34 | f>>H[i]; 35 | for (i=1; i<=n; ++i) 36 | f>>cost[i]; 37 | 38 | procesare (); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /zvon.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # define NR 100005 5 | using namespace std; 6 | ifstream f("zvon.in"); 7 | ofstream g("zvon.out"); 8 | vector v[NR]; 9 | int i,j,n,m,o,t,x,y; 10 | int ap[NR], timp[NR]; 11 | bool cmp (int a, int b) 12 | { 13 | if (timp[a]<=timp[b]) return 0; 14 | else return 1; 15 | } 16 | void DFS (int k) 17 | { 18 | for (int i=0; i>t; 28 | for (o=1; o<=t; ++o) 29 | { 30 | f>>n; v[n].clear(); timp[n]=0; 31 | 32 | for (i=1; i>x>>y; 37 | v[x].push_back(y); 38 | } 39 | DFS (1); 40 | g<