Hello Codeforces!
mesanu, flamestorm, MikeMirzayanov and I are glad to invite you to Codeforces Round 835 (Div. 4)! It starts on Nov/21/2022 17:35 (Moscow time).
The format of the event will be identical to Div. 3 rounds:
- 5-8 tasks;
- ICPC rules with a penalty of 10 minutes for an incorrect submission;
- 12-hour phase of open hacks after the end of the round (hacks do not give additional points)
- after the end of the open hacking phase, all solutions will be tested on the updated set of tests, and the ratings recalculated
- by default, only "trusted" participants are shown in the results table (but the rating will be recalculated for all with initial ratings less than 1400 or you are an unrated participant/newcomer).
We urge participants whose rating is 1400+ not to register new accounts for the purpose of narcissism but to take part unofficially. Please do not spoil the contest for the official participants.
Only trusted participants of the fourth division will be included in the official standings table. This is a forced measure for combating unsporting behavior. To qualify as a trusted participant of the fourth division, you must:
- take part in at least five rated rounds (and solve at least one problem in each of them),
- do not have a point of 1400 or higher in the rating.
Regardless of whether you are a trusted participant of the fourth division or not, if your rating is less than 1400 (or you are a newcomer/unrated), then the round will be rated for you.
We would like to thank:
RedstoneGamer22, tibinyte2006, haochenkang, badlad, qwexd, nyaruhodo, Phantom_Performer, tolbi, AlperenT, Bakry, prvocislo, Gheal, keta_tsimakuridze, KrowSavcik, BucketPotato, pashka, MikeMirzayanov for testing the round!
Max_Calincu, TimDee, MikeMirzayanov for helping with Russian translations!
We suggest reading all of the problems and hope you will find them interesting!
Good luck!
UPD: Editorial is posted.
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
k.,
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
Luceafărul
A fost odată ca-n povești, A fost ca niciodată. Din rude mari împărătești, O prea frumoasă fată.
Și era una la părinți Și mândră-n toate cele, Cum e Fecioara între sfinți Și luna între stele.
Din umbra falnicelor bolți Ea pasul și-l îndreaptă Lângă fereastră, unde-n colț Luceafărul așteaptă.
Privea în zare cum pe mări Răsare și străluce, Pe mișcătoarele cărări Corăbii negre duce.
Îl vede azi, îl vede mâini, Astfel dorința-i gata; El iar, privind de săptămâni, Îi cade draga fată.
Cum ea pe coate-și răzima Visând ale ei tâmple, De dorul lui și inima Și sufletu-i se împle.
Și cât de viu s-aprinde el În orișicare sară, Spre umbra negrului castel Când ea o să-i apară.
...
Și pas cu pas pe urma ei Alunecă-n odaie, Țesând cu recile-i scântei O mreajă de văpaie.
Și când în pat se-ntinde drept Copila să se culce, I-atinge mâinile pe piept, I-nchide geana dulce;
Și din oglindă luminiș Pe trupu-i se revarsă, Pe ochii mari, bătând închiși Pe fața ei întoarsă.
Ea îl privea cu un surâs, El tremura-n oglindă, Căci o urma adânc în vis De suflet să se prindă.
Iar ea vorbind cu el în somn, Oftând din greu suspină: - O, dulce-al nopții mele domn, De ce nu vii tu? Vină!
Cobori în jos, luceafăr blând, Alunecând pe-o rază, Pătrunde-n casă și în gând Și viața-mi luminează!
El asculta tremurător, Se aprindea mai tare Și s-arunca fulgerător, Se cufunda în mare;
Și apa unde-au fost căzut În cercuri se rotește, Și din adânc necunoscut Un mândru tânăr crește.
Ușor el trece ca pe prag Pe marginea ferestei Și ține-n mână un toiag Încununat cu trestii.
Părea un tânăr voievod Cu păr de aur moale, Un vânăt giulgi se-ncheie nod Pe umerele goale.
Iar umbra feței străvezii E albă ca de ceară - Un mort frumos cu ochii vii Ce scânteie-n afară.
Ca în cămara ta să vin, Să te privesc de-aproape, Am coborât cu-al meu senin Și m-am născut din ape.
O, vin'! odorul meu nespus, Și lumea ta o lasă; Eu sunt luceafărul de sus, Iar tu să-mi fii mireasă.
Colo-n palate de mărgean Te-oi duce veacuri multe, Și toată lumea-n ocean De tine o s-asculte.
Străin la vorbă și la port, Lucești fără de viață, Căci eu sunt vie, tu ești mort, Și ochiul tău mă-ngheață.
...
Trecu o zi, trecură trei Și iarăși, noaptea, vine Luceafărul deasupra ei Cu razele-i senine.
Ea trebui de el în somn Aminte să-și aducă Și dor de-al valurilor domn De inim-o apucă:
Cum el din cer o auzi, Se stinse cu durere, Iar ceru-ncepe a roti În locul unde piere;
În aer rumene văpăi Se-ntind pe lumea-ntreagă, Și din a chaosului văi Un mândru chip se-ncheagă;
Pe negre vițele-i de păr Coroana-i arde pare, Venea plutind în adevăr Scăldat în foc de soare.
Din negru giulgi se desfășor Marmoreele brațe, El vine trist și gânditor Și palid e la față;
Dar ochii mari și minunați Lucesc adânc himeric, Ca două patimi fără saț Și pline de-ntuneric.
O, vin', odorul meu nespus, Și lumea ta o lasă; Eu sunt luceafărul de sus, Iar tu să-mi fii mireasă.
O, vin', în părul tău bălai S-anin cununi de stele, Pe-a mele ceruri să răsai Mai mândră decât ele.
Mă dor de crudul tău amor A pieptului meu coarde, Și ochii mari și grei mă dor, Privirea ta mă arde.
Dar cum ai vrea să mă cobor? Au nu-nțelegi tu oare, Cum că eu sunt nemuritor, Și tu ești muritoare?
Nu caut vorbe pe ales, Nici știu cum aș începe - Deși vorbești pe înțeles, Eu nu te pot pricepe;
Dar dacă vrei cu crezământ Să te-ndrăgesc pe tine, Tu te coboară pe pământ, Fii muritor ca mine.
Da, mă voi naște din păcat, Primind o altă lege; Cu vecinicia sunt legat, Ci voi să mă dezlege.
Și se tot duce... S-a tot dus. De dragu-unei copile, S-a rupt din locul lui de sus, Pierind mai multe zile.
...
În vremea asta Cătălin, Viclean copil de casă, Ce umple cupele cu vin Mesenilor la masă,
Un paj ce poartă pas cu pas A-mpărătesii rochii, Băiat din flori și de pripas, Dar îndrăzneț cu ochii,
Cu obrăjei ca doi bujori De rumeni, bată-i vina, Se furișează pânditor Privind la Cătălina.
Dar ce frumoasă se făcu Și mândră, arz-o focul; Ei, Cătălin, acu-i acu Ca să-ți încerci norocul.
Și-n treacăt o cuprinse lin Într-un ungher degrabă. - Da' ce vrei, mări Cătălin? Ia du-t' de-ți vezi de treabă.
Ce voi? Aș vrea să nu mai stai Pe gânduri totdeauna, Să râzi mai bine și să-mi dai O gură, numai una.
Dar nici nu știu măcar ce-mi ceri, Dă-mi pace, fugi departe - O, de luceafărul din cer M-a prins un dor de moarte.
Dacă nu știi, ți-aș arăta Din bob în bob amorul, Ci numai nu te mânia, Ci stai cu binișorul.
Cum vânătoru-ntinde-n crâng La păsărele lațul, Când ți-oi întinde brațul stâng Să mă cuprinzi cu brațul;
Și ochii tăi nemișcători Sub ochii mei rămâie... De te înalț de subsuori Te-nalță din călcâie;
Când fața mea se pleacă-n jos, În sus rămâi cu fața, Să ne privim nesățios Și dulce toată viața;
Și ca să-ți fie pe deplin Iubirea cunoscută, Când sărutându-te mă-nclin, Tu iarăși mă sărută.
Ea-l asculta pe copilaș Uimită și distrasă, Și rușinos și drăgălaș, Mai nu vrea, mai se lasă,
Și-i zice-ncet: — Încă de mic Te cunoșteam pe tine, Și guraliv și de nimic, Te-ai potrivi cu mine...
Dar un luceafăr, răsărit Din liniștea uitării, Dă orizon nemărginit Singurătății mării;
Și tainic genele le plec, Căci mi le umple plânsul Când ale apei valuri trec Călătorind spre dânsul;
Lucește c-un amor nespus, Durerea să-mi alunge, Dar se înalță tot mai sus, Ca să nu-l pot ajunge.
Pătrunde trist cu raze reci Din lumea ce-l desparte... În veci îl voi iubi și-n veci Va rămânea departe...
De-aceea zilele îmi sunt Pustii ca niște stepe, Dar nopțile-s de-un farmec sfânt Ce nu-l mai pot pricepe.
Căci amândoi vom fi cuminți, Vom fi voioși și teferi, Vei pierde dorul de părinți Și visul de luceferi.
...
Porni luceafărul. Creșteau În cer a lui aripe, Și căi de mii de ani treceau În tot atâtea clipe.
Un cer de stele dedesubt, Deasupra-i cer de stele - Părea un fulger ne'ntrerupt Rătăcitor prin ele.
Și din a chaosului văi, Jur împrejur de sine, Vedea, ca-n ziua cea dentâi, Cum izvorau lumine;
Cum izvorând îl înconjor Ca niște mări, de-a-notul... El zboară, gând purtat de dor, Pân' piere totul, totul;
Căci unde-ajunge nu-i hotar, Nici ochi spre a cunoaște, Și vremea-ncearcă în zadar Din goluri a se naște.
Nu e nimic și totuși e O sete care-l soarbe, E un adânc asemene Uitării celei oarbe.
O, cere-mi, Doamne, orice preț Dar dă-mi o altă soarte, Căci tu izvor ești de vieți Și dătător de moarte;
Reia-mi al nemuririi nimb Și focul din privire, Și pentru toate dă-mi în schimb O oră de iubire...
Din chaos, Doamne,-am apărut Și m-aș întoarce-n chaos... Și din repaos m-am născut, Mi-e sete de repaos.
Tu vrei un om să te socoți Cu ei să te asameni? Dar piară oamenii cu toți, S-ar naște iarăși oameni.
Ei numai doar durează-n vânt Deșerte idealuri - Când valuri află un mormânt, Răsar în urmă valuri;
Ei doar au stele cu noroc Și prigoniri de soarte, Noi nu avem nici timp, nici loc Și nu cunoaștem moarte.
Din sânul vecinicului ieri Trăiește azi ce moare, Un soare de s-ar stinge-n cer S-aprinde iarăși soare;
Părând pe veci a răsări, Din urmă moartea-l paște, Căci toți se nasc spre a muri Și mor spre a se naște.
Iar tu, Hyperion, rămâi Oriunde ai apune... Cere-mi cuvântul meu dentâi - Să-ți dau înțelepciune?
Vrei să dau glas acelei guri, Ca dup-a ei cântare Să se ia munții cu păduri Și insulele-n mare?
Vrei poate-n faptă să arăți Dreptate și tărie? Ți-aș da pământul în bucăți Să-l faci împărăție.
Îți dau catarg lângă catarg, Oștiri spre a străbate Pământu-n lung și marea-n larg, Dar moartea nu se poate...
Și pentru cine vrei să mori? Întoarce-te, te-ndreaptă Spre-acel pământ rătăcitor Și vezi ce te așteaptă.
...
În locul lui menit din cer Hyperion se-ntoarse Și, ca și-n ziua cea de ieri, Lumina și-o revarsă.
Căci este sara-n asfințit Și noaptea o să-nceapă; Răsare luna liniștit Și tremurând din apă
Și umple cu-ale ei scântei Cărările din crânguri. Sub șirul lung de mândri tei Ședeau doi tineri singuri:
Cu farmecul luminii reci Gândirile străbate-mi, Revarsă liniște de veci Pe noaptea mea de patimi.
Și de asupra mea rămâi Durerea mea de-o curmă, Căci ești iubirea mea dentâi Și visul meu din urmă.
Hyperion vedea de sus Uimirea-n a lor față: Abia un braț pe gât i-a pus Și ea l-a prins în brațe...
Miroase florile-argintii Și cad, o dulce ploaie, Pe creștetele-a doi copii Cu plete lungi, bălaie.
Ea, îmbătată de amor, Ridică ochii. Vede Luceafărul. Și-ncetișor Dorințele-i încrede:
El tremură ca alte dăți În codri și pe dealuri, Călăuzind singurătăți De mișcătoare valuri;
Dar nu mai cade ca-n trecut În mări din tot înaltul: - Ce-ți pasă ție, chip de lut, Dac-oi fi eu sau altul?
Trăind în cercul vostru strâmt Norocul vă petrece, Ci eu în lumea mea mă simt Nemuritor și rece.
1883, aprilie
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
114 spoilers later: where are them upvotes at?
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a maprticipant, I am asking myself: "When will ratings change?"
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I can assure you really good quality problems. The contest in worth spending time. All the setters and testers have put a lot of work and effort. Good luck everyone !!
As a tester, I am happy to represent my fellow newbies. The round has good and enjoyable problems. Good luck!
"As a tester, I am happy to represent my fellow newbies." don't believe him, he is a lgm in disguise.
As I tester, I'm sure you'll find the problems fun and interesting. I wish good luck and positive delta to everyone!
Shouldn't this blog be in the main page?
Looking forward to my first unrated round ever!
As a tester I did nothing like (some) other testers.
Congratulations once again for putting div.4 round on Monday.
omg div 4 , will try to score high
Better, stronger and faster.
Yes bro ;)
oh no cringe
OKAY, it's just a meme
Yayyy ! Won't miss my first unrated contest ^_^
Same xD
Same xD
Same xD
🗿
It would be nice to finally fix language selector issue and remove excessive use of flags.
Sources with supporting arguments:
Codeforces Language Picker -- chrome extension to see how fixed codeforces language picker would look like.
Please support the initiative and stop reinforcing poor UX practices.
Stop farming downvotes
I just became pupil. How can I become a specialist? Should I learn new things? Please advise me. I want to reach there quickly.
Hey, i reached pupil yesterday aswell, to reach specialist our goal is simple get A,B,C done as fast as possible.Try to do D,if not upsolve it
By doing A B C fast you can reach 1500+ easily maybe expert aswell.
in div 3 right? i don't think you can get specialist just by solving A B C fast on div 4
i was talking about div 2 mate
LOL
In order to get to Specialist, I suppose you've got to solve AB(C) in Div.2 / ABC(D) in Div.3 / ABCD(E) in Div.4. () means that if your speed is fast enough, the () problem can remain unsolved.
Can we really become Specialist,by just solving AB fast??? In less than 30 minutes or more fast?
In 5 minutes or something
omg cyan round
OMG Green Round
I'm really looking forward to this game, it's going to be an interesting game
Good luck everyone!
Good Luck to you!
The funny thing that nobody pointed out is that all the testers are at least expert level. However, it does not have to mean that the problem difficulty was poorly judged, especially because many of the testers and setters are experienced in setting/testing rounds.
As a Arch Linux user, how do I exit vim I am still in it since the Div. 3
:wq
or even easier:
:x
good luck guys <3
.
.
aaaaaaaaaa
leetcode monthly contest fun
why downvote me??????????? wuwuwuwuwuwuwuwuwuwu T_T_T_T_T_T_T
solved 3 problems!!!
if you stay focused and don't waste time on looking at comments, you can probably solve even more
SpeedForces
manforces :)
Nice Contest. Enjoyed solving the problems.
Can someone please tell for which test case my code for D is failing?
https://codeforces.me/contest/1760/submission/181970514
19th token in second test case. Look at the 19th test case
1
6
2, 2, 2, 7, 10, 4
YES
NO
Actually, before printing "YES", you again have to check whether $$$c>0$$$ or not. And also before the last for loop, change the conditions (if(v[1]>v[0]) --> if(v1[1]>v1[0])) and (if(v[n-1]<v[n-2]) --> if(v1[n1-1]<v1[n1-2]))
What's wrong in my submission for E? Lots of people got testcase 7 WA too
use long instead of int
Thanks
Sample tests were really bad for E and G!
Well, tests for G also seem to have sucked. Got TLE on system tests. Changed unordered_set to set and it got accepted. Welcome to cf I guess.
You have exposed yourself to danger by using
unordered_set
. During the hacking stage in div3/div4/edu codeforces contests, such solutions are specifically targeted by hackers. See the https://codeforces.me/blog/entry/62393 blog for more details. Even if your solution wasn't hacked directly, all successful hacks become a part of the system test and still ruin your day.Python users are also in danger for exactly the same reason, see the https://codeforces.me/blog/entry/101817 blog. This made solutions like 182003822 vulnerable.
So do you mean no one should use hash maps on cf because there will always be someone who can hack your solution and make the hash operations O(N) instead of O(1)?
You can use hash maps wherever they meet your needs. But you have to ensure that there is little to no possibility of constructing custom input data by abusing the hashing function, provided that an attacker knows it.
Personally, I would not rely on out-of-the-box usage of
unordered_map
even at Div.1/Div.2 contests. Hash map hacks did happen there as well.I'd really appreciate if someone could help me with the logic for F.
-> If we can't collect the coins when k = 0, answer is Impossible
-> If any of the A[i] >= C, answer is Infinity
-> Other than that, we can binary search on the possible k
Am I somewhat close to the solution, or my approach is completely far off?
The answer can also be infinity : when the sum of a[i] over min(days,n) >= C
I think answer is Infinity if sum of min(n, d) greatest A[i] >= C since we still can do different tasks
Can anyone help me with my submission for 1760G - SlavicG's Favorite Problem : 182028374.
Take a look at Ticket 16547 from CF Stress for a counter example.
Thank you.
can someone share the idea and intuition behind G?
One important property of XOR is that a^a = 0. So if you do two BFS, one rooted at A and one rooted at B, you can find nodes in the A BFS and B BFS where the XOR value is equal, so you can teleport from one path to another and reach B with XOR of 0. If this exists (there are some edge cases to consider), then it is possible.
oh thanks alot. sorry i have another question is applying dfs with the same concept you mentioned should fail? because i tried to do this using two dfs but it failled in test2 or its just an implementation issue?
I think you forgot this case: You should not consider the vertices in A's DFS/BFS where B coincides with the (unique) simple path starting from A.
solved all problems in div4 for the 2nd time. feels amazing.
What's the 53rd case of second test case in G?
It's about the fact that we can teleport from a too. That means if there exist any
(prefix xor starting from b) == 0
then also answer is True.can one explain why in D
10 10 8 10 10 4
output NO ?
because it has more than 1 valley. one at value 8 and another at value 4.
Did any1 else mess up F for the infinity case?
yup
Lmao. I just checked if biggest element was enough instead of the biggest d-elements, or just all if d is big.
My solution (as following) gives
wrong answer 2653rd numbers differ - expected: '4', found: '3'
for 1760E — Binary Inversions.Can anyone help me with testcases that gives wrong answer on test 2.
check once with input "10". I think you need to initialize with ans=0.
My rating is 1400 and my standings show that this contest is rated for me. So, I am a little bit confused that will my rating will change or not ...
:)
t seemed like mimemamomu warmuping
How to solve F?
Binary Search on Answer(value of k)
Can anyone help in problem G? I'm getting MLE. My Solution
Approach: Starting bfs from 'a' and calculating zor as i move and checking if zor becomes equal to any edge weight that is adjacent to 'b'(so that i will teleport from here).
There are too many statements during bfs. You can save the weight of not only the adjacent edge but from any point to "b", so that the amount of statement will be small.
Apologies if this isn't the correct place to raise suspicions, I'm new here and couldn't figure out how to report users.
There is something weird I noticed about this user — https://codeforces.me/submissions/9999999999/contest/1760
You can see him making multiple submissions specifically designed to be hacked if there is a single testcase (on the first and trivial problem). He does it by hardcoding wrong input when there is only 1 test case like so:
(example submission https://codeforces.me/contest/1760/submission/182047190 )
I'm not sure what the purpose is. Maybe it's a multi-account of the hacker — https://codeforces.me/profile/Adel_Mahmoud and he's just farming points? Can you think of any other explanation?
gimme downvotes pls
So, I promise that as soon as I become pupil, I will try to give my perspective of how I make my solutions, I don't think that my code is worth but maybe my perspective can give you help in the future.
This one is the easiest, but I think that always that you read that you must give a number that is not the minimum or maximum of a list, you must think in make a vector, sort and print the position that you are interested. Like for example the second minimum would be a[1] or the second maximum a[n-2].
The important thought that you must find is that if the maximum letter is 'a' you only need one and 'z' you need 26 and with only make in your mind the solution of two case you began to see what you need to do, I was a little nervous when I was writing the code and was thinking what is better if sort the string and see the last letter or used the function max_element, when you have dudes but you know that the code that you are in the middle of writing will work too, is best to commit to what you are writing in the moment that change to another solution in my experience. This work good in first or second problem for me because the solutions that you think probably will be right because they try to make easy for beginners like me, this is my way to be faster.
Another useful type for the problems that want you to make a letter a number is remember that 'a'-'a' is 0 or a character minus the same character will return 0.
Here strike again the idea that we see in the problem A, in this problem you only care about the maximum and the second maximum so you make a vector, sort and use a[n-1] when the value x is not the maximum and a[n-2] if x is equal to the maximum, but I used a different method of only stored the two maximum numbers in a vector because I think a better version before beginning to write.
Is curious because I have come across this kind of problems many times that they want you to search there is a "Valley" or a "Peak" in the vector I still don't have a good way of approach this kind, but they always give you the conditions that must meet so the idea is always searching in a for if the condition is meet and see what are the corners case.
In this case you want to focus in every point because you can make L=R, the segments with same numbers but for example if you have a segment equal to {3,3,3,3} you don't want to waste your time with {3},{3,3},{3,3,3} because they will contradict the condition a[l−1]>a[l] or a[r] < a[r+1] other that this is good to keep in mind that l=0 or r = n-1 are free passes.
this one is just in my reach of knowledge so when I find problems that seem difficult at the beginning, I always try to see what type of input I can solve and corner case to corner case I will build my solution.
Now it's apparent that the best is to make the last one a zero or the first one converted to one and see how much we gain or lost for each operation and after seeing if it is good to make a change, go for all the vector and every see how much it will give to the answer. Another tip is to use comments when you feel that you are confused about what you have done and what not.
If you see my code is very inefficient but show that divide the problem in easy problems help you to see a solution.
I hope that was helpful this in some way, sorry if was not as good as you expect, when I became a better, I will make up for these bad tutorials.
It's not a bad tutorial. For some formatting tips I would recommend enclosing variables in dollar signs to get the mathematical look of $$$x$$$. You can use
a_{x}
for $$$a_x$$$ anda^{x}
for $$$a^{x}$$$. This is called latex and its quite commonly used in math. You should also use links for your codes instead of pasting them.For the solution themselves, you can use some advanced implementation tricks to make the code really simple and bug proof.
For problem D for example, we see 2 phases. decreasing, then increasing.
So we can define a phase function like
You could also get the exact values of $$$l$$$ and $$$r$$$ using the intermediate values of this calculation.
For problem E you need to only consider the change of inversion. This is the same as number of pairs $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i = 1$$$ and $$$a_j = 0$$$. If we consider what happens when we change a $$$0$$$ at index $$$x$$$ to a $$$1$$$ for example, we get more inversions from the $$$0$$$s to the right of $$$x$$$, and less inversions from the $$$1$$$s to the left of $$$x$$$. Therefore the best $$$0$$$ to flip would be on the left. But this also allows you to calculate the change in inversions from changing any index $$$x$$$.
Am I the only weirdo who used segment tree to solve C?
How did you do it?
How do we easily calculate the maximum of all array elements excluding the i-th element? It's possible to just do two range queries in a segment tree (the array part before the i-th element and the array part after the i-th element) and use the largest of these two results. In submission 181925712 I have only written the "main" function. Everything else is a copy of the segment tree implementation from the atcoder library.
Nice idea lol
Well, I just wanted to save time instead of inventing some original solution for this particular problem (and then proving that it correctly handles all corner cases). I'm not a particularly fast problem solver and taking care of A+B+C took me 13 minutes. Without segment tree this time could be even worse.
Your solution uses sort and you have beaten me by solving A+B+C in only 5 minutes. But now imagine not having sort function in the standard library. In this case you would need to find some decent bug free $$$O(N log N)$$$ sort implementation and copy/paste it as a part of your solution. Implementing your own sort from scratch during the contest would be a fool's errand and waste of time. Segment tree is pretty much the same and the only difference is that it is typically not provided in standard libraries of programming languages, so I need to copy/paste the atcoder's implementation.
My $$$O(N log N)$$$ segment tree solution implemented in D language can be even tweaked to remove all loops and branches 182184534 (except for the main loop iterating over testcases) and this reduces cyclomatic complexity. For comparison, a faster Wanderkind's $$$O(N)$$$ solution 182072909 also implemented in D language is more complicated. But both are fast enough and coding speed/convenience is IMHO more important during a contest.
I agree with you on that. But most programming languages already have sort function. I personally read the problem quickly and the sample explanations and coded it. I know that I can't solve a lot of problems so I depend on speed instead. The problem doesn't really need proving but if you're looking for special cases and a full proven solution then yes Segment Tree was much better
Is there a reason you didn't use the
sort
function instd.algorithm
?I didn't because I am new to this language and I am not yet familiar with handling arrays.
Because segment tree just happened to be my first idea after reading the problem statement. But I used
sort
for solving problems A and F.I imagine not having sort and finding first and second maximums
This was exactly the point of my comment. Both sort and segment tree are not necessary for solving this problem. They both actually degrade time complexity. But they both are also easy to use and save time (tourist used sort 181903982 and the editorial suggests sort too). Sort is included in the standard library, while segment tree has to be copy/pasted.
For E, missed test case 7, just changed int to long after the contest, it got passed.
Rule 1 : No matter what, always use long int
Rule 2 : Always follow Rule 1.
Or long long
Rule 3: sometimes memory limit might be tight and you'll need to use int
Yet to encounter such problems. Thanks in advance, will remember this.
My solutions (video):
A. Medium Number
There are many ways to do this. I simply output $$$a + b + c - \max(a, b, c) - \min(a, b, c)$$$.
B. Atilla's Favorite Problem
The answer is the letter with the largest position in the alphabet.
C. Advantage
If we are the strongest person, the strongest opponent is the second strongest person. If we are not the strongest person, the strongest opponent is the strongest person. Store the strongest and second strongest opponent in two variables to compute the answer in linear time.
D. Challenging Valleys
Play around with examples to find that the array must consist of a non-increasing segment followed by a non-decreasing segment. Anything else will create at least two valleys. So make sure there are no occurrences of $$$a_i<a_{i+1}$$$ before $$$a_i>a_{i+1}$$$.
E. Binary Inversions
For each zero, the number of inversions containing that zero is the number of ones before the zero. So keep a running total of the number of ones to quickly compute the number of inversions of $$$a$$$ initially. Consider flipping each element. If we flip a zero, the number of inversions will increase by the number of zeroes after, and decrease by the number of ones before. If we flip a one, the number of inversions will decrease by the number of zeroes after, and increase by the number of ones before. Take the maximum possible increase, which is at least 0 if we do nothing, then add this to the number of inversions initially.
F. Quests
The maximum number of coins we can get decreases or stays the same whenever $$$k$$$ increases. So binary search for $$$k$$$. The maximum number of coins can be made by choosing the $$$k+1$$$ greatest elements in decreasing order in cycles until $$$d$$$ days have passed.
For example if $$$a = [1, 2, 3, 10, 5, 4, 3]$$$, $$$k = 5$$$, and $$$d = 16$$$, we choose $$$10, 5, 4, 3, 3, 2| 10, 5, 4, 3, 3, 2| 10, 5, 4, 3$$$. I put a bar where our selections start repeating.
We can quickly compute the most coins we make by sorting $$$a$$$ in decreasing order then making a prefix sum array. Take the $$$k+1$$$th element in our prefix sum array, multiply it by the number of times we can fully cycle through our $$$k+1$$$ elements, then add the sum of our remaining incomplete cycle.
G. SlavicG's Favorite Problem
If we revisit a vertex, the walk starting and ending from the revisited vertex must've crossed each edge an even number of times, because each edge in a tree is a cut-edge. So there's no point of revisiting a vertex, and a potential solution will consist of walking from $$$a$$$ to $$$c$$$ (without crossing $$$b$$$), teleporting to $$$d$$$, then walking from $$$d$$$ to $$$b$$$. The case where we don't teleport can be treated as teleporting from $$$c$$$ to $$$c$$$.
The xor of the edges of the paths from $$$a$$$ to $$$c$$$ combined with the edges of the path from $$$d$$$ to $$$b$$$ must be $$$0$$$. So the xor of the path from $$$a$$$ to $$$c$$$ is equal to the xor of the path from $$$d$$$ to $$$b$$$. Using depth-first search, compute the xor going from $$$a$$$ to each vertex, and the xor going from $$$b$$$ to each vertex, and see if any two xor values match. Remember that $$$a=c$$$ is forbidden and when you start your depth-first search from $$$a$$$, don't go into $$$b$$$.
problem G:
Your task is to go from vertex a to vertex b, but you are allowed to enter node b if and only if after traveling to it, the value of x will become 0.
Why use "enter" instead of "arrive at" explaining the statement? I misunderstood when solving this problem and wasted 1 hour!
What does ios::sync_with_stdio(0); cin.tie(0); these 2 lines mean?
ios_base::sync_with_stdio(0); this code is used to make synchronization false. Because synchronization is initially true. And synchronization allows multiple objects to use a common resource (for example, Methods). cin.tie(0); tie(0) is a method which simply flushes before std::cin accepts an input. This is useful for interactive console programs which require the console to be updated constantly but also slows down the program for large input/output. Source: https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio https://stackoverflow.com/questions/31162367/significance-of-ios-basesync-with-stdiofalse-cin-tienull
is there any source apart from codeforces so that people from India and China communicate?
Can someone give a test case for which my code for D is failing?
https://codeforces.me/contest/1760/submission/182044338
Check this out:
The answer is obviously
NO
, whereas your algorithm printsYES
. Seems like an issue with dealing with consecutive equal elements.History repeats itself. Four hacking attempts (all are of the same submission) are now stuck either in "Waiting" or "In queue" state. MikeMirzayanov, can we do something about this?
UPD: still in queue after the final testing. Déjà vu...
Ok cool
Bro, why have you decided to use
unordered_set
, which has $$$O(N)$$$ worst case time complexity? It's like you made a special effort to be hacked.Ohh.. is that why my solution got hacked? Damn, I thought they have O(1) in all cases. Well, according to the approach I have used what would have been a more preferred data structure ?
set
would perfectly do it. Or even simpler: we may just sort all hashes and binary search over them.I would argue that sort and binary search isn't simpler. This requires a bit more code to be written and there is a bit higher chance to mess it up.
BTW what's a counterexample for binary inversions if I only flip either the first 0 bit, last 1 bit, or none?
there is none. thats the solution
Hi everybody! How can i register for the competition?
Go to https://codeforces.me/contests and you will find the list of future contests accepting registration.
why the rating is not increasing? I wanna see myself cyan
What is the difficulty of problems in this contest ??? I don't see any tag.
@Down Though my rating less than 1400 in whole codeforces rating history and I have given more than 5 contests still my rating has not been increased after securing 2000 rank.
I'm looking into it
For the G Question it is giving me wrong answer on test case 2 . Whats wrong in this code . I am first storing the xor of path till all the node from a and b as root respectively , Then checking for common elements . https://codeforces.me/contest/1760/submission/182136945
When starting from a, the dfs cannot cross b. Either arrive at b directly, or block at b because of the nonzero xor.
Thank you so much . Now i got what i was doing wrong . ;)
Have the ratings updated ?
No, not yet.
qwexd I have given 7 contest in which I have solve more than 1 problems in almost all..Can you please check why my rating is not increasing.I am grey rated which means I have rating less than 1400.
Assuming you have no competitive programming exp prior to coming to codeforces. Solving 1 problem in div 2 rounds places u somewhere between 9k-12k in rank, for getting a better rating, you need to have a better rank, for getting better rank you have to solve around 3-4 problems depending on round difficulty, A and B are generally ad-hoc/implementation type. However, from C you need to practice problems of specific tags.
bro I am asking him why has my rating not changed from the last Div 4 round.In simple words I am asking him to check why under my contest section , it is not showing the rating change from last contest..
It's been shown under unrated contest list for all users maybe...it could be under the unrated list until cf figures lut ratings for all users...maybe, not an official answer
I solved the same problems with another account because the other one made a lot of stupid mistakes, but the rating didn't increased.
can you please accept it from this account and ignore the other
No
Please Codeforces send Me a message said that "Your solution 181995500 for the problem 1760F significantly coincides with solutions Morad/181995500, Hussam-alwan/182013671, Rakhimov_Ans/182023461 If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. " and skipped all My Solutions And I Have not Any conclusive evidence But Only i submitted My Solution on 18:58 and anthor Person submitted on 19:26 So I Haven't an account on Idone and didn't Use it and I should Be a Specialist in this Contest !!!! please Help Me! Thanks For Your Time
In the last div 4, my solution for the problem E Binary Inversions link to problemgot skipped due to the similarity of code from the user merahijalwa/181973274. first of all I don't know him and the similarity in code is due to code available in the geeks for geeks platform for counting the number of inversions in the array link to code from geeks for geeks website .
please consider this as this is a legit case and this is fist time i am going to reach pupil rank. please MikeMirzayanov consider this case as my case is completely legit and nor i have use any online ides. If anyone know how to contact codeforces team..please comment.
Ah screw my luck. I'm 1399 now
You will be specialist by next contest hopefully!
Thanks. I hope so
Well, maybe you get added by one after the rating is rolled back =)
Why am I not rated for div4
You have to participate in atleast
n
contest and solving atleastx
problems in them to be eligible for being a rated participant, I don't remembern
andx
values, but you can find it in this post's description itselfThat's the prerequisite of being a trusted participant. You will be rated regardless of being trusted, if your rating is <1400.
Nice Contest, Quality problemset and Good tutorial!! Kudos to the CF team & contest team
I didn't share my code to ANYONE!!!!!!! What will happen if someone locked and try to hack me,and share my code to other? YOU HAVE WRONGED ME
Maybe try to share your code and prove that you've not plagiarized rather than screaming from next time on.
Blue coder is already out of competition for Div 4. Why bother?
Because i did't do such thing.i dont care the rating but i do care credict.
:sadge:
Same for me. I Solved 5 problems and yet got -2 rating
They were easy af
This is a BAD round. Problems aren't FUN at all. They are too STANDARD and ROUTINIZED. PLEASE refrain from setting such rounds from now on.
UPD: PLEASE don't downvote me! I am just saying my opinion.
For Div 4 these problems are very good
No, THIS ROUND IS BAD.
No, I find Div4 problems better than Div2. Of course first ones are pretty standard because they are very easy, but EFGH and sometimes D are really good
Nah, Div.2 problems are really BETTER than Div.4. You are JUST A PUPIL and why do you have the right to speak?
No, many Div2s have really bad problems and Div4 and Div3 are always made by the same people so they always have the same good quality. And yes I'm a pupil and I will speak as much as I want
You are allowed to speak as much as you want.
Then how am I speaking
Why my rating is not updated . yesterday i saw it was there but now its gone :(
Read above
What means "If k can be arbitrarily large, output Infinity" in the problem F?
idk if this answer your question but: If for every $$$k$$$ that i choose that is a solution, i can choose a bigger number $$$l$$$ that also is a solution, that means that $$$k$$$ is arbitrarily large.
For example, see this input:
2 20 10
100 10
The output is infinity, because it doesn't matter how big i take $$$k$$$ to be, because in the first day i can just take the first quest, gains 100 coins, and have more that 20 coins.