Recent actions

Is there any difference between submitting code with commented solution of other problem in it and pasting it in an open blog ( or social media, IDE, etc. ) ?

When will you announce random T-shirt winners?

Dear contest team,

I received a message that two of my solutions (B, D) significantly coincide with what user "gamegame" submitted. If you take a look at them, they are significantly different, especially D. I wrote and compiled my code locally without using any online resources. This round was my best contest in years, and I would be very sad if the rating changes were rolled back even though I didn't share my code with anyone or copy gamegame's code in any way.

omg, how haven't I seen this?)

Dear contest team,

I received a message that two of my solutions (A, B) significantly coincide with what user "V_e_N_o_M" submitted. This cannot be a coincidence as I use some non-standard patterns in the code, which differentiate it from what people normally do. With that I can clearly see that V_e_N_o_M used my code.

If you check the time of the submissions, you will see that I am the original author. In addition, other submissions of mine can be checked — they are very similar and follow the same patterns.

I believe that the code was taken by "V_e_N_o_M" from my GitHub repository — I submitted the code to Github before the end of the contest. Apologies for that — I will make sure it won't happen again.

P.S. I also saw that a user with nickname "__VENOM___" did such things before (see the comments to

Dear MikeMirzayanov, Dormi,

I think there is a coincidence in my submission of C, F1 for the latest contest. During the contest, I was just using my own compiler and not using any third-party platform to communicate or use the online compiler. So I hope you will see my comment and thought about this again.

Also, you can see that the code is a bit similar because I use global(well-known) method for coding, that's why it's kind of similar, I don't know how does dakwamim code is the same as me.

I am currently using Code::Block for coding and save it locally.

P/S:Thank you for reading my messages.

Nice idea to escape using too much space. Really liked that sorting idea! I never thought of using that to make the code simpler! Thanks for the help!

the author

Can anyone please tell me what is wrong with my code 119381067

This 3 changes need , actually for ask query format should be like "? x"...
[32 line] -> cout << "? 1" << endl;
[54 line] -> cout <<"? "<< j << endl;
[68 line] -> cout <<"? "<< j << endl;
your modified code accepted link

Still don't understand why my solution on D catches: "Idleness limit exceeded on test 1". I even do cout.flush() after endl. Can anyone help me?

My last submission:

In my C solution 119368225, the array formed of upper/lower pairs simply gets sorted by the value of the upper element in each pair (since this doesn't change the answer). After this is done, the upper elements became the identity permutation and the bottom elements became a derangement of it. The rest is the same.

The only difference is that my solution has $$$O(n \log n)$$$ time complexity because of applying sort. And yours is a smarter $$$O(n)$$$ solution, achieving the same end result. My reasoning was "let's sort the input data and see if the problem becomes more simple" and indeed that's what happened! I overlooked the fact that this degraded time complexity, but humongous sizes of the input data typically have i/o as the performance bottleneck (to the extent that C++ people are forced to use the sync_with_stdio voodoo magic). While sorting the input data rarely or even never becomes a real performance problem.

You could simply use "assign" instead of "resize" and you won't have to worry about global variables.

Accepted Submission

probably You :))

I love the way how i went to learn from tourist by looking at his code , and returned even more confused

Really liked C. I am not sure if this was already commented by someone on problem C, but here is what I did. Let the first row be the permutation $$$a$$$ and let the second row be $$$b$$$. We have the property that $$$a_i \ne b_i$$$ for all $$$1 \leqslant i \leqslant n$$$. Now, since this does not change the answer, apply the permutation $$$a^{-1}$$$ on both arrays.(by this I mean changing indice $$$i$$$ to $$$a^{-1}_{i}$$$) Now we have the identity permututaion and some derangement of it at the bottom. Let this derangement be $$$c$$$. Note that $$$c$$$ is equal to $$$b \cdot a^{-1}$$$. The important observation is that if you swap $$$i$$$ with $$$c_i$$$, then continuing you must swap $$$c_i$$$ with $$$c_{c_i}$$$ and so on until you "cycle" back to $$$i$$$. This inspires to think of the cycles in the permutation $$$c$$$. So, if there are $$$X$$$ cycles, we have $$$2$$$ possible states for each of them. Either you go through that cycle once or you do nothing.(note that going through a cycle brings you back to where you started). Thus the answer is $$$2^{X} \pmod {10^9+7}$$$. So, we can say more about the graph in the tutorial, each vertex has degree $$$2$$$.

First, rephrase the whole thing as: you've got a directed graph where some vertices are marked (the $$$a_i$$$-th sand in $$$i$$$-th column), find the smallest set of vertices such that each marked vertex is reachable from at least one chosen vertex.

I compress to DAG, note that only topmost components should be chosen, then note that from the way the graph is constructed, no two topmost components can share a column, so they're easy to sort. Also, paths in the graph are actual paths in the grid, so the set of topmost components from which a given vertex/component can be reached is a contiguous interval.

With a simple graph traversal, for each component, I find the leftmost and rightmost of the top components which are above it (minimum and maximum of their numbers in sorted order) and the problem reduces to picking the smallest number of points that cover all given intervals, which is well-known.

Thankyou so much for taking out the time to look into this and getting back to regarding the issue. I definitely learnt something new today. I understand why this happened now. Have a nice day :)

Mark vertices that you need to cover, make scc, mark respective vertices in scc, unmark those that are reachable from another marked.

Now you have set of marked vertices none of which is reachable from the other.

I claim that you can sort them in some order that any source in SCC will cover segment of marked vertices, just sort them by column id of any marked representative in scc vertices.

Now you have to figure out minimum and maximum reachable marked vertex from each source and cover array with minimum number of segments, which can be done greedily without actually finding segments: take first unmarked vertex, go through back edges and mark every node as visited, from each marked node go down and mark all nodes as visited as well. You will reach all sources that cover first marked vertex, which is precisely what greedy on array does. Then take next marked unvisited vertex and so on.

congratulations winners

Do you mean that somebody uploads their solution for A instead of a solution for B by mistake? But a solution for A is very unlikely to pass pretests for B. And it makes no sense to show the source code of failed submissions to hackers (I don't know if that's how it really works, because I have never tried hacking other solutions in non-educational rounds yet).

Or do you mean that somebody submits a valid solution for B, together with a commented out solution for A in the same source file? Is anyone ever doing something like this? I do sometimes use my A solution's source code as an initial template for B. But by the time when I'm ready to submit it, no parts of A remain there.

Thanks a lot

congrats for all the winners and I hope one day I can compute at you're level

Make the arrays bigger, e.g. char a[n+1][m+1], c[n+1][m+1]. Alternatively, use 0-based indexing in the rest of your code.

An array int a[50] only has valid positions a[0], a[1], ..., a[49].

Thanks for the information. Is there any way to overcome this error?

this is what i did :)

how's the new macbook benq!lol

I thought there should be a natural extension in F. So I continued with the SCC formulation and reduced it to finding a minimum size set of vertices in a DAG such that every leaf is reachable from some vertex in the chosen set. Then I tried to solve it with some (wrong) flow models. Does anyone know if this problem admits a good solution in general?

I'm not the lowest:)

become newbie!

What’s your solution then?

Mythical Grandmaster or Chimeric Grandmaster. Chimeric Master for 4000-5000 and Mythical or Chimeric Grandmaster for 5000+ works.

You may get it after removing cheaters, Congratulations!

When your local submissions behave differently from codeforces submissions, it often indicates that your code may have undefined behavior. In your case, I think you are trying to access an element out of bounds of the done array: see 119406377 where the assertions I added fail. I think it is due to the line fire2.pb(mp(x,b+1));, where b can be up to n-1

Waiting for the +1. I want the IM.

I suggested this in the past:


But now that Benq got the highest max rate on Codeforces history, The competition has become strong!

but you forgot Radewoosh, He also get a rating of 3700+

now (Benq VS tourist VS Radewoosh), The trio with a rating of 3700+

In practice mode (i.e. after the contest), runtime errors on codeforces can be caught by the C++ diagnostics compiler automatically. I resubmitted and it shows that your char arrays a and c are too small: 119406134

its just another way of checking it*

Thank you, that was the problem, I can't believe that was the reason, well now I will never forget about that lol. Thanks for your help!

It would still give chess-like board

To not keep you waiting, the ratings updated preliminarily. In a few hours/days, I will remove cheaters and update the ratings again!

Neither of them.

You can also implement bfs or dfs and color the graph while doing so. Not that it would be better, but it also works.

Since the highest ever rating title was most likely taken (at least for now) from tourist by Benq, do you think he will take his revenge and first reach the 3800 mark?

Any bets who will be first over 4000?

ah, I'm blind, sorry, you don't fill it with zeros for every testcase, that's the reason, it is global

Well, I used SCC and didn't have to erase and rewrite, so I think it was a good path to take.

I made a few little changes in the cases where n = 1 and n = 2, and it passed: 119404096

I gave hist a size of 4 * 100005 which is 4 * (1e5 + 5) so that shouldn't be the problem. Also, I just tried with hist[(int) 4e6] and again got WA on test 4.

can some one tell why I am getting WA on this submission my friends solved literally the same idea and they got AC I literally can't find any wrong I am getting wrong on pretest 2 my program is printing 01234501234512345623456734567845678956789100 how can the program prints smth like this plz help

hist[i+1] causes an undefined behavior because the max n is 4e5 and the size of hist is 4e5, enlarge hist by 1 element and soln will pass

good to be back

Well, I took my code to F2, erased the whole thing with SCC, did some obvious stuff and it worked, so I don’t find SCC useful here at all.

Hi. Can someone explain me why I got WA on test 4 in B? The idea is correct but I can't find the mistake in my solution. Thanks


I finally found a problem with a good upgrade in this F. Not like F1 has an interesting idea, just a straightforward "build graph, do SCC", where the main point of failure is building the graph in a wrong way, but there's an element of double checking — if F1 passes, you can expand on it to solve F2, while if your SCC is wrong and pretests for F1 don't catch it, then pretests for F2 might because it's way more than SCC!

There's a good reason to go for SCC in F2 even if you don't have F1. As soon as you have it abstracted as a directed graph, compressing to a DAG gives you plenty of guarantees for the next step — actually figuring out the solution. It's not hard to write either, just reproduce those 20 lines of Tarjan from whichever online resource you want. Why did this fst? Can't seem to figure out.

Edit -> Don't use global variables when you don't have to.

Benq has raised the bar of highest cf rating to 3796 now. Beating Tourist . Congratulations Benq.

119382434 Can someone tell me why I'm getting runtime error?

I found a way, just go to the status bar and check all rejected submissions keeping the tests greater than the number of pretests.

Created or updated the text

Two questions:

F: Does anybody remember a similar situation when solving a small version and then trying to upgrade it was a mistake? Normally it's rather a good way, but there the small version required only SCC while the big one doesn't (which may lead you to really long code).

H: Isn't an interaction with $$$10^5$$$ flushes rather slow/dangerous/generally not CF-friendly?

They will never show that as people will backfire for weak pretests. Although this contest had strong pretests. No one on my friend list got FST.

In your solve function, for clearing the g[i], i should be from 0 to n, i.e., for(int i=0;i<=n;i++) (you did i<n instead of i<=n)

Looks like highest rating record on codeforces is going to be broken.


Thanks for the great problems and strong pretests!

Can somebody try this out on their machine. I submitted this in contest and it gave WA on pretest-1 and i tried it on my machine multiple times and it worked well. I'm really frustrated as I don't understand how the same code in 2 machines can give different output (my strategy isn't random, the program will always query the same nodes for a particular tree everytime it runs).

Sorry I just realized my question was utter nonsense. I was asking how this didn't become $$$O(n ^ 2)$$$ even though degree could be upto $$$O(k)$$$ per node. I forgot $$$n \leq 500$$$ in the problem.


Now it's time to wonder if I got a great place thanks to competing drunk or despite competing drunk.

Failed system test

Padding the array with one extra 0 element in the beginning and one extra 0 element in the end removes the need to handle special cases.

What is FST?

vi query(int r) {
    // cout << "! " << r << '\n';
    printf("! %d\n", r);

The query format differs from what you print here.

Here was my approach:

Arbitrarily choose some node to be the root. Query that node. That gives you the rank of each node in the rooted tree. Our goal is to find the parent of each node.

Iterate over the nodes in any order. Query each node whose parent is not yet known. We can use the result of the query along with the rank information to find that node's ancestors, siblings, and children.

Notice that if we associate each query with the node and its parent, these pairs don't overlap. This proves that we won't exceed $$$\lceil\frac{n}{2}\rceil$$$ queries.

Please can you check my submission 119395523? I calculated 2^(connected comp) but it's giving WA on tc4.

I mean, there is no other solutions

Yes, I didn't notice the announcement first. I felt really dumb noticing it after few minutes.

Fst on D coming :(

You are right :)

I spent half an hour, read several times, and don't understand what it means by "only by swapping numbers in a column". and finally I ask a question to admin, and then I got it.

2^(Cycles) is the answer

Finally Tutorials are here. I was thinking of finally offering some goat to the devil. Thanks to problem setters for fast update.


This is the intended solution.

Were your queries more than N/2?

Yes, basically all connected components will be pure cycles

What if i tell you, that in problem A you just need to check whether given matrix satisfies:




Realized this in post-contest discussion with my friend.

Is there a way to see how many people failed system test for a particular problem ?

will the number of cycles and number of connected components be equal in C?

i could't submit D even after solving it cuz even though i saw a sample problem of interactive problem i could not submit it without idleness, please hack my account and put me out of my missery , basically i am under water its too much raining

i literally did the same thing but got WA in pretest 2 :( . :(:(:((((((((((((((.

Because admins hasn't made solutions public yet.

Big ups to the authors for the nice problems, and bigger ups for including the answers to the possible sample queries in the interactive problems where it's reasonable. That's such a nice thing to do <3

I was thinking the same. Clicking on solutions, but nothing is happening.

You can use cf predictor extension. It gives the real time Delta changes during the contest. Just Google it

Consider the i, i — 1 and i + 1 position.

  1. So, in bipartite graph every node belongs to one of two parts. Part that contains more nodes than other is bigger part, other part is smaller part.

  2. So, as I said if distance between two nodes is odd, nodes belongs to different parts. So, ask about first node, every node that has even distance to the first one, is in the same part with first node, otherwise, if distance is odd, it is in different part

The subproblem I generate to consider problem B i guest?

use cf predictor chrome extension