| # | User | Rating |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3390 |
| 6 | Um_nik | 3387 |
| 7 | tourist | 3384 |
| 8 | heuristica | 3322 |
| 9 | turmax | 3319 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 144 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 6 | AmShZ | 137 |
| 8 | BledDest | 132 |
| 8 | maroonrk | 132 |
| 10 | qwexd | 129 |
|
0
When the $$$2 \times 2$$$ matrix is empty, there are actually $$$6$$$ ways to fill it such that every square will add to $$$2$$$. Here are the options: Options So when we set the cell with coordinates $$$(1, 1)$$$ we get only first $$$3$$$ options out of the above. |
|
+3
Your input/output is too slow. This is caused by using iostream (cin/cout) with stdio (printf/scanf) synchronisation. Add the following lines to boost the speed considerably. Beware, however, that this makes it dangerous to use cin/cout alongside printf/scanf. I submitted your code with these two lines and it works within the time limit (129564251), albeit still a bit slow. |
|
+3
I do not understand what the variable names mean exactly but based on what I've written in my solution, the first bit of code should be the embodiment of the following train of thought: The second bit of code I couldn't decipher, but it's likely something similar. |
|
+5
OK, I implemented my own version and I think the code is a bit more self-explanatory. If anyone has trouble understanding Roms' implementation (as I did), then maybe looking at mine (129556708) will help. |
|
+5
People used a funky priority_queue based Dijkstra implementation! A very clever approach in my opinion. Each vertex is a build and each build is a vertex. However, these vertices aren't stored anywhere in memory but rather, they are procedurally generated. Two vertices (builds) are joined by an edge if and only if you get one of the builds by degrading exactly one item in the other build. Then, just implement a Dijkstra on these builds and remember to skip the neighbours of a vertex if the vertex is not banned, since the neighbours (degraded builds) can only be worse, as noted in the editorial. |
|
+1
As far as I can tell, I think I did it using a traverse of a trie structure without the structure itself. Take a look at my solution if you want to. |
|
0
Thanks! |
|
0
In problem E, we only have to keep track of same-colour cells with an even number of cells between them? What about differently coloured cells with an odd number of cells between them? Doesn't that force a strip of width two as well? |
|
0
So assume we have $$$n$$$ knights with strengths $$$a_1 \leqslant a_2 \leqslant \cdots \leqslant a_n$$$. Now assume that the dragon has defense $$$x$$$ and attack $$$y$$$, and let's say that $$$i$$$ is such, that $$$a_i$$$ is the smallest of the strengths greater or equal to $$$x$$$. Now I will show why we only need to check $$$a_i$$$ and $$$a_{i-1}$$$ (if they exist). First, we do not have to check any $$$a_j$$$ for $$$j \gt i$$$ because using greater attack than necessary will not give us any advantage, but may cost us defense points, and thus gold. I think this is fairly straight forward. Second, we do not have to check any $$$a_j$$$ for $$$j \lt i-i$$$ because: |
|
0
SoonTM |
|
-10
Yes, One another note, Another bit of advice: your way of hashing (don't worry, it's pretty much the only popular way of hashing) by taking elements and multiplying them by a constant and then taking the remainder modulo another constant is rather slow, because the modulo operation is slow. So I wouldn't be surprised if using hashing is still slower than using the logarithmic Better luck with all this new knowledge next round! |
|
+5
So you used some form of hashing and then stored whatever data you needed on a set either way? At that point I'd use std::unordered_set... That being said I used a |
|
+3
Does CodeForces compile into 32-bit executables? I'm asking because long longs are slower only in that case. Another competitive programming site changed compilation to 64-bit and now there is no difference besides memory use. But additional memory use is not something completely unimportant. Usually it doesn't matter, but problems can easily be made to require better memory use. I've seen a problem (not on CodeForces) which actually required the use of short ints! Also, having templates with a couple of useful things like |
|
0
Just add at the beginning of the main function. This boosts iostream, but makes using both iostream and stdio dangerous, as the two are now desynchronised (as the name of the invoked method implies). |
|
0
The system tests were ran from the very beginning. Notice, how submission status was never "Pretests Passed (3)" or something like that, but straight up "Accepted". I was surprised when I saw that! |
|
0
Based on how you explained it here, I think I have the same! Pretty interesting to think of it as a trie. Then again, I only "know" trie in theory and never consciously used it. |
|
0
This would then require a custom comparator, though. Unless you do another funky thing and let the strength be the first (zeroth?) element of the vector. |
|
+9
Yes, because the Quicksort algorithm, while having "quick" in its name is not that quick after all. Firstly, its O(n log(n)) complexity is just the average case, although admittedly by randomizing the pivot, the only thing stopping your case from being "average" is EXTREME bad luck, so this is negligible. But... Secondly, std::sort is a wicked hybrid algorithm optimized for all kinds of stuff and well... it's faster. |
|
0
That would indeed force you to change the comparator and I think it wouldn't be worth it because: You'd have to recompute the sum of the values every time you need it, which increases the time complexity constant, which isn't good, and You'd lose time on writing a custom comparator which is not exactly the easiest thing to do and can easily go south, so unless you've already done similar stuff, it's risky, and even if you've got experience with that, it's still a waste of time during the round. The only "pro" of this approach would be to save some memory, which is negligible. Much more so than the time you would otherwise save. |
|
0
If you want to keep using cin and cout add these two lines at the beginning of the main function: As far as I can remember these lines desynchronise iostream and stdio and perhaps do something more which makes using both input methods dangerous, but as long as you are using only cin and cout and these two lines, you shouldn't run into any time limit problems caused by input/output. |
|
0
Hi, so I have a question for the community as well, the answer to which influences your case. I see that the limits for a solution are the same regardless of the language in which the solution is written. Does that mean, that using Python (without extensive Python optimization knowledge) instead of a much faster (in common use) language like C++ can greatly influence scores on CodeForces? I am asking this, because this is exactly what happens on another competitive programming website on which I am a regular organiser (instead of participant) and thus, we don't allow Python there. |
|
0
I took embarrassingly long too! I had it slightly differently. Here's how Instead of generating a sequence of i nested parentheses and then another sequence of n-i nested parentheses, I did first, a sequence of i nested parentheses and then i sequences of the string "()" haha. Yours is better. And, well, you must admit, this is a very simple few lines of code. It's just that problem A was probably not the usual stuff you'd expect and that's why it took so long to think of! |
|
+3
Perhaps you have a logic mistake in your algorithm. I thought I had it too but it turned out that I made a mistake and had to think of a different way to save myself from checking all exponentially many possibilities. Edit: oh, derp. I misread and thought that the question was about problem D. Sorry! |
|
0
I am sorry to be "that guy" but I think your question isn't very clear. I'd happily help (I solved D) but I can't if I don't understand the question! |
|
0
Yes!.. No? Maybe. Check this solution out! |
|
0
Oh holy crap this is brilliant. And here I got stuck with some greedy ifological strategy which... I'm reasonably confident would work but I didn't manage to implement it. |
|
0
This work is O(nlog(n)) though due to the heap! But it's still a fine approach. |
|
+8
Oh I completely misunderstood that comment. I got it now, thanks! |
|
0
Yes, and? |
|
0
Doesn't this require sorting, which yields linearithmic time complexity either way? |
|
0
Using SCC is a bit overkill and definitely a waste of time for this problem. The goal (when checking if understanding the book is possible) is to check if there is a cycle. We can do that with a DFS (or multiple, in case of a DAG, which we are dealing with here) which, instead of marking a vertex visited, can set two different kinds of flags. The DFS works as follows:
We can count the result with a DFS too, using dynamic programming on a DAG. Every vertex with no outgoing edges receives value 1, because that chapter will be understood during the first reading of the book. Every other chapter will be understood after all its prerequisite chapters are understood, so the result for the chapter is the maximum of the results for the prerequisite chapters... but slightly modified to account for the order of the chapters in the book. |
|
+3
Using multiplies() is probably a very bad idea because it will most likely overflow but yeah, using a function, perhaps a lambda |
|
0
Oh, now this strikes a bell. So what you are suggesting, is to find the largest square that divides every number in the range, then replace every number in the array by itself, divided by that largest square divisor, and we will be left by the product of primes (with exponent equal to 1), which we are looking for. Darn, simple and elegant. Then, let's say we are given x and y. Then let x' be x divided by its largest square divisor, similarly define y'. Then, x is adjacent to y if and only if x' = y'. Did I get it right? Brilliant. (And well in the range of my abilities, but oh well...) |
|
0
It seems we have fallen victim to a minor misunderstanding. I wrote "what you wrote IS TRUE for any x and y". Which, in that case, says nothing about x and y themselves, when the goal is to determine whether they are adjacent. |
|
0
There is no counterexample because this works for all x and y. What you wrote: if k=x*y, then (k/gcd(x,y))^2 is a perfect square. It doesn't even matter what k is. You have written a tautology. Edit: nevermind, it does matter what k is. But as long as k = x*y, then k/gcd(x,y) = lcm(x,y) is a whole number, so that squared is a perfect square. Still a tautology. |
|
+8
cin.tie(0); cout.tie(0); also helps. One of them does next to nothing but the other one has a significant impact as well, although will make it so that your input flows to the console at the moment that the program comes to an end, which means it's rather bad for debugging. I never remember which one is which. |
|
0
What you wrote is true for any x and y. You essentially wrote that LCM(x,y)^2 is a perfect square. |
|
0
The editorial mentions, that LCM(a,b) = a*b/GCD(a,b). This is a well known fact. It is easy to prove, I will assume I do not need to. What is LCM(a,b)/GCD(a,b) then? Well that is equal to (a*b/GCD(a,b))/GCD(a,b) = (a*b)/GCD(a,b)^2 And the numbers a and b are adjacent if and only if that number is a perfect square, so (a*b)/GCD(a,b)^2 = X^2 for some integer X. Which means, that a*b = GCD(a,b)^2 * X^2 for some X. Now that is true if and only if a*b is a perfect square itself. Then, we can divide that perfect square by GCD(a,b)^2 and we will receive another perfect square, denoted by X^2. |
|
+4
Didn't even read F, got stuck on D and for way too long. The (simple in hindsight) observations took me too long and ultimately I ran out of time, trying to think of how to find a solution in O(nlogA)... which admittedly, I am still searching for, and the editorial mentions it's "simple". Alright then, keep your secrets haha. It probably is simple though. Apparently I just had one of them bad days. |
|
0
The example with persons A and B is not an example, but a proof, that the optimal solution does not contain a situation such that a person with higher k_i got a more expensive gift. I don't know if proof of the correctness of the greedy approach is simple, I for sure, cannot formalize it. But I understand it intuitively. Essentially, by giving the cheapest gift to the person with the greatest k_i, you will be always as well off as in any other situation. Then, you have to repeat the process for the same set of gifts, minus the cheapest gift and the same set of persons, minus the person with the highest k_i |
|
0
Will this round influence our ratings? If so, then when will the ratings be updated? |
| Name |
|---|


