Блог пользователя Intellegent

Автор Intellegent, 7 месяцев назад, По-английски

Thank you for participating!

Special thanks to reirugan for writing the analysis for B, D, E and to Proof_by_QED and Friedrich for helping to optimise F1, leading to the creation of F2.

Rating Predictions

2154A - Notelock:

Hint 1
Solution
Implementation(C++)
Implementation(Minecraft)

2154B - Make it Zigzag:

Hint 1
Hint 2
Solution
Implementation(C++)

2154C1 - No Cost Too Great (Easy Version):

Hint 1
Hint 2
Solution
Implementation(C++)

2154C2 - No Cost Too Great (Hard Version):

Hint 1
Hint 2
Hint 3
Solution
Implementation(C++)

2154D - Catshock:

Hint 1
Hint 2
Solution
Implementation(C++)
Bonus

2154E - No Mind To Think:

Hint 1
Hint 2
Solution
Implementation(C++)

2154F1 - Bombing (Easy Version):

Hint 1
Hint 2
Solution
Implementation(C++)

2154F2 - Bombing (Hard Version):

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Implementation(C++)

Bonus editorial by Friedrich:

Solution 2
Разбор задач Codeforces Round 1060 (Div. 2)
  • Проголосовать: нравится
  • +178
  • Проголосовать: не нравится

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится -61 Проголосовать: не нравится

first.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Wowee C !!!

»
7 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится +4 Проголосовать: не нравится

FAST EDITORIAL! C + TLE :)

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Auto comment: topic has been updated by reirugan (previous revision, new revision, compare).

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Auto comment: topic has been updated by reirugan (previous revision, new revision, compare).

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

fast editorial!

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

Let's say, we sort the array by increasing value of 'b' array.

then...

The second case is the more tricky case, we need to check the optimal way to make more than one operations for each element, and it is probably the crux of the problem

Above statement can be more optimised saying that we should never perform more than 1 operation on those elements, where b[i] != b[1](1 indexing for array rep. ) ( because, it is never optimal to perform two operation of some b[i], we can always perform one b[1] and one b[i] , which is bound to be less than 2 * b[i] ( because the array is already sorted by 'b' values ).

  • »
    »
    7 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +4 Проголосовать: не нравится

    I figured out that after sorting b[0]+b[1] will be the answer if we can't do better with b0 alone... but I was confused what if there are multiple elements with same cost to update... I thought If I check all them then it will give TLE.. because I was using a set to maintain all the prime divisors and checking the closest prime multiple which I can get for corresponding a[I] of minimum b.. but I can't do that for all n numbers right? if all costs are same... can you please help me...

    • »
      »
      »
      7 месяцев назад, скрыть # ^ |
      Rev. 3  
      Проголосовать: нравится +6 Проголосовать: не нравится

      actually, if there are multiple elements of all same costs in the beginning... then you will need no more than 2 operations of the b[1] ... think about it... 2 operations are always sufficient...

      So, now what remains is ( with '2' operation, we are certain we will get it , as established bove ), we need to find if we can do with only one operation in only first part... that is simple, you can do it easily by maintaining prime factors of each numbers and check through map, whether corresponding entry exists or not.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

I was cooked by C2

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

Amazing contest I think AI can't solve any question after C1 thats why this contest feels fair.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

C2 is so good!

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

C1 was a nice problem. Unfortunately I got a tle on my submission I used the same approach as the editorial but didnt precompute the primes. Isn't N * sqrt(N) good enough?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

C2 was such a nice problem !!!

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Loved implementation of A on Minecraft!!

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

My C1 FSTd on TC 21 (Runtime Error). Does anybody know what the error might have been. I must be overlooking something fairly obvious.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

nah that minecraft implementation is funny and crazy

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Last week in LeetCode biweekly in D que, got to know about the concept of SPF and today I used it in C1, hope +ve delta.

»
7 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

Man! Sometimes just 1 number can mess up your contest.

Contest Submission:344688102

Normal Submission:344750449

Btw these are my friend's submissions messed his contest rank.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

hey in the editorial for C1...

this part     for (int i = 0; i < n; i++){
        for (int x : pfac[a[i]])
            cnt[x]--;

        for (int x : pfac[a[i] + 1]){
            if (cnt[x] > 0)
                ans= min(ans, 1);
        }

        for (int x : pfac[a[i]])
            cnt[x]++;
    }

why do we need to decrease the cnt of prime factors I mean two consecutives numbers are always co-prime so there is no need to do that right?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone help with the error? 344753515 I couldn't find the output bug, how the cat is not reaching to n? (Test Case 1)

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Intellegent the test cases on C2 seem weak, the submission passes C2 but throws tle on C1, can you try rejudging C2 with C1 test case 17.

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

С1 is a nice problem. Is there a way to solve it in Python? I got TLE on the 7th test.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone check if my solution to C2 is hackable or not? I have suspicion that my solution will probably TLE: 344744359

»
7 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится +9 Проголосовать: не нравится

Bonus on D is funny because the moment I read the problem I asked myself how would someone implement a checker for such problem! I was 90% sure that instead of directly solving the problem, it's better to implement the checker and it'll naturally lead to the solution.

I came up with something like (spoiler: didn't work)

I really would like to know how is the checker implemented for this problem.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Real fast editorial!

I really loved the problems, but I did leave a little heartbroken.

I made a mistake in C1 of having MAX = 2e5 + 1 instead of MAX = 2e5 + 2(at least), and that passed the pretests but failed later on. I'm a little heartbroken because I had a good run, especially because I solved C1 rather fast. A lot faster than some people, and friends. In the end I went from +50 to -45 :(

I'm never making that mistake again, but I am still happy as I got the idea and I really enjoyed the problems

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My idea of D was, find the leaf nodes and the path from 1 to n, start from a leaf node and do operation 2 then 1 then 2 on it, this ensures the leaf node is removed safely, keep doing same on its adjacent node till you encounter a node which is either in the path from 1 to n or has a degree greater than 2, if it the latter case decrease degree of node by 1 and remove the edge connecting this node to previous node. repeat similar for all leaf node, this leaves us with only the path from 1 to n, now do as we did for leaf node starting from node 1 all the way to node n. so its kind of deleting the branches to main path safely then shortening the main path, takes exact 3n operation

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

So, i need ur help for C2. I understand that we need to check only the lowest bi, but what if all bi are equal. for example: a: 3 7 11 b: 1 1 1 we can see, that to solve this case we need to make a == 3 7 12 and for this we need to check all bi. It is O(n * (amount of common divisors)) where the second one is rather big. So i suppose this solution mustn't work

  • »
    »
    7 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    If the cheapest element is not unique, then you don't need to consider incrementing any element more than once, since incrementing the cheapest element by 2 already costs at least the same as making the two cheapest elements both even.

    More formally, assume the elements are sorted by $$$b_i$$$ ascending, then we can always get a solution at cost $$$b_1 + b_2$$$ by making the first two elements even (less if one of them is already even), so incrementing the first element more than once only makes sense when $$$b_1×2 \lt b_1 + b_2$$$, and when $$$b_1 = b_2$$$ (i.e., the cheapest element is not unique) then $$$b_1×2 = b_1 + b_2$$$.

    You can generalize this to: it only makes sense to increment $$$k$$$ times when $$$b_1×k \lt b_1 + b_2$$$, which implies $$$k \lt (b_1 + b_2)/b_1$$$ but this doesn't improve the worst case complexity so it's not really useful for this problem.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

W contest. Learned a lot from problems and solutions

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +45 Проголосовать: не нравится

Hey Intellegent, Please make more rounds!

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Upsolved D to find the exact same solution as the editorial. Very cool contest.

Can anyone help me with the time complexity analysis of my solution for C2? I know I missed the observation but I cannot figure out why mine TLEs. https://mirror.codeforces.com/contest/2154/submission/344750294

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Whats the intuition behind using bipartite nature of trees in D?

  • »
    »
    7 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Let $$$dist[u]$$$ = distance of vertex u from 1. The cat could be at any vertex $$$u$$$ after $$$m$$$ type 1 operations iff $$$dist[u] \le m$$$ and $$$dist[u]$$$ has the same parity as $$$m$$$. You can reason about why the parity should be the same. Now, considering the loose constraint of $$$3n$$$ operations, we don't need to care about the $$$dist[u] \le m$$$ condition. Any leaf vertex can be destroyed in at most 3 operations. So, we will choose to only destroy leaves.

    Suppose the previous operation was a type 2. Now, the next operation must be a type 1. After this, if the vertex we are interested in destroying has the same parity as the no. of type 1 operations so far then we can do another type 1 operation and the parity becomes different. Then a type 2 operation can be made to destroy that vertex.

    Edit: The reason why $$$dist[u]$$$ should have the same parity as $$$m$$$ is because if we take a simple path from 1 to $$$u$$$, then the path length will be $$$dist[u]$$$. Now, if the cat wants to reach $$$u$$$ in more than $$$dist[u]$$$ moves then it must wander off from this simple path and then come back to continue the path. Coming back retraces the moves made to wander off. So, this will increase the no. of moves taken to reach $$$u$$$ by some even number. This means the cat can reach from 1 to $$$u$$$ in $$$dist[u] + 2k$$$ type 1 moves, for $$$k \ge 0$$$. This is the same as the condition $$$dist[u] \le m$$$ and $$$dist[u]$$$ has the same parity as $$$m$$$.

    • »
      »
      »
      7 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      will this method work? find the leaf nodes and the path from 1 to n, start from a leaf node and do operation 2 then 1 then 2 on it, this ensures the leaf node is removed safely, keep doing same on its adjacent node till you encounter a node which is either in the path from 1 to n or has a degree greater than 2, if it the latter case decrease degree of node by 1 and remove the edge connecting this node to previous node. repeat similar for all leaf node, this leaves us with only the path from 1 to n, now do as we did for leaf node starting from node 1 all the way to node n. so its kind of deleting the branches to main path safely then shortening the main path, takes exact 3n operation

      • »
        »
        »
        »
        7 месяцев назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится
        1. Are you sure you want to do operations 2, 1, 2 on the leaf node?
        2. You cannot ignore the parity/color of the node that is getting destroyed. For example, if the tree has edges (1, 2), (1, 3), (1, 4), (4, 5), then the path from 1 to n will be 1 -> 4 -> 5, and leaves will be 2 and 3. You can remove either of the leaves at first, but then you cannot remove the other leaf immediately after. Because the cat might have jumped to that leaf node.
        3. You don't have to treat the path from 1 to n specially. If you never process the node n as a leaf, then in that case the node 1 will be the only remaining leaf. You can process it and the new leaf will be the next node on path from 1 to n. It helps to think of the path from 1 to n as a special case, but it is really not.

        You are on the right track.

        Edit: 2 1 2 is not feasible as for the next leaf node you cannot start it with a type 2 operation. |2 1 2|2 1 2| breaks the constraint that there cannot be two consecutive type 2 operations.

  • »
    »
    7 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    The subset of nodes that the cat can be in at any even turn (0,2,4,...) are always the same, the same for the odd turns (1,3,5,...), so in each turn you can distroy any leaf that are in the opposite subset because the cat can't be in it!
    That is simply!
    A small corner case is when for example cat is in an even turn, and the are no leaves in the odd subset!
    you can simply make the cat move to the odd turn, and delete a leaf from the even turn.
    Re-root the tree and make n is the root, and run bfs till you distroy all nodes expect n.

    BFS code
    • »
      »
      »
      7 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      I tried deleting non-path nodes that may or may not be leaves, while keeping track of their mark (color) and ensuring correct alternation between turns.

      However, I’m getting WA (Wrong Answer). Can you suggest a test case where deleting a non-leaf node actually affects the final answer? Because from my reasoning, it shouldn’t — so I’d appreciate an example or insight proving otherwise.

      Thanks.

      My code
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In question D I have done somewhat the same as in the editorial (destroying leaf nodes while checking you are not standing on it using distances) My code is failing on some tc 344776961 ,can anyone help me with this .

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I am quite sure my solution for C2 can be hacked(TLE).

Can someone please verify?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

3 19 17 14 7 17 18

in this above test case my output is correct meanwhile the judge say' answer should be 7 but your output is 24. Can anyone explain why is this happening ? my submission [link]

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please help me to understand for C2 why we are not able to do the operation on a number more than once? What if you have a really cheap operation and you just spam it to get to a number and this will be more optimal than any alternative.

I'm rlly confused because there is also an official test case that does more than one operation on a single element?

Testcase:

3
2 7 11
1 6 6

Correct Output:

5
  • »
    »
    7 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    we do more than one operation for only that element with smallest b[i], so you did 5 operations on 2 since its b[i] is 1, we don't do this kind of operation on any other values as say you do 2 or more operations on a[i] with second smallest b[i], instead we could have done 1 or 0 operation on this a[i] and 1 or 0 operation on value with smallest b[i] making both even and gcd>=2.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think D is a fun problem. But I didn't solve C1, and I spent a lot of time on it. My point of D is even less than others' C1's.

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

The solution's F2, step 3 part have a very small problem:

$$$(r \le i\le r)$$$ should be modify to $$$(r \le i\le n)$$$

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Alternative solution of D, without coloring.

Root the tree at vertex 1. Then, the following works:

Run DFS from the root, send instruction 1 when going down, send instruction 1 and then 2 x when going up from x. When running DFS in a node $$$x$$$ that can reach $$$n$$$, DFS the other childs that cannot reach $$$n$$$ first, then DFS the child that can reach $$$n$$$ and send instruction 1 and then 2 x. One actually see that this forms something like an euler tour so the steps won't go past $$$3n$$$. Obviously this is correct.

344706147

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

For D can somebody explain like why my parity approach that is whether the cat has covered odd or even distance doesnt give right ans when i delete farthest node (from root) of such parity instead of deleting some leaf of such parity(like the tutorial solution)

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

[problem:2154] Cleaner and More Efficient Implementation 344796757

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i just think c2 is much more difficult than D,but it's a interesting problem

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Might a O(n) solution to the problem E? 344800205

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Ternary search solution was mentioned in tutorial for problem E. If somebody is interested, there is an implementation (using Fibonacci search, which is valid for integers): https://mirror.codeforces.com/contest/2154/submission/344804780

»
7 месяцев назад, скрыть # |
Rev. 7  
Проголосовать: нравится +16 Проголосовать: не нравится

Solution for problem D bonus (implement checker):

Spoiler
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

344805176

Could someone tell me why it is causing TLE for C2, please?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

In 2154C1, what was the need of first removing all the primes of a[i], then checking for a[i]+1 and then again including the primes of a[i]?

»
7 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится -7 Проголосовать: не нравится

Intellegent I have questions in D, can't cat just go back to parent ( start from root 1 to 3 and then get back to 1) and also it is written that answer always exists for any tree but suppose root itself has 3 adjacent child and we can remove only one so cat can go to second child, how does answer exists here or am I missing a lot of things here?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

we need minecraft implementation for D, as we have in A

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Easy explaination for C2

Spoiler
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please tell me why my submission for B is failing on pretest 7? The algorithm that I used is the same as that given in the editorial.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://pastebin.com/22PxKa89 -- This is my submission for problem C2, can anyone please tell what is the issue with my code

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

is this ~~~~~ for (int i = 0; i < n; i++){ for (int x : pfac[a[i]]) cnt[x]--;

for (int x : pfac[a[i] + 1]){
        if (cnt[x] > 0)
            ans= min(ans, b[i]);
    }

    for (int x : pfac[a[i]])
        cnt[x]++;
}

~~~~~

in C2 std reasonable??

because gcd(a[i],a[i]+1)=1 so those cnt[x]++/cnt[x]-- cycle are useless

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone please tell me why this submisson 344840270 for C1 is giving tle

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

C2 is an amazing problem, I really liked it

combining Adhoc, Number Theory and some ez DS and implementation

Really a nice problem!! even it prevented me from being Expert :(

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain me sample test cases output of C1

Input
2
1 1
1 1
Output
2

Reason we have to increase both 1's to 2 to make gcd(2,2) > 1

Input
5
1 1 727 1 1
1 1 1 1 1
Output:
2

Why answer is not 5, to make sure for each 1<=i,j<=n gcd(a[i], a[j) to be greater than 2 we have to increase all of the numbers by 1 making array as 2 2 728 2 2

Now, if we choose any (i,j) gcd(a[i], a[j]) > 1.

When we are saying answer is 2, which two indices values will be increased? How for each i,j gcd(a[i], a[j]) > 1?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

was a bit too diffcult for someone like me

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

D is a nice problem.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone tell me a case where my code is failing. 345020227

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I used square root decomposition to solve problem E. My idea was that after a certain point, there would be a segment where the gain of the previous segment becomes greater than the current one — and those two segments would give the maximum gain for that point (or possibly the last segment).345001346

EDIT-> GPT code with comments so people can understand my messy code: 345025272

However, in the editorial, it mentioned using binary search. I thought about it for a while, but if for any point gain[mid] == gain[mid + 1], it seems like the binary search approach would fail. So I still can’t figure out exactly how it works. It would be great if someone could explain it.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

for C2 i did not get intended solution for checking only index with lowest bi. So i made a solution to check for every pair- Solution — Instead of checking how far each number is from every prime, we can reason as follows:

1.If ai is not a prime number, then it must have a factor less than or equal to 500. Therefore, for any aj, there will always exist a number between aj and aj+500 such that gcd (ai,aj) > 1.

2.If ai is a prime number, we only need to consider ai itself rather than its factors. We can sort all numbers in increasing order, and for each prime, we iterate by multiplying it with an integer x. If aj*x< ai , we remove aj*x and insert aj*(x+1). Here, x will be at most 500.

//This is my code - 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define input(a) for(auto &i:a)cin >> i;
#define srt(v) sort(v.begin(),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define vr vector
#define pb push_back
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fr(i, n) for (ll i = 0; i < n; i++)
const int mod=1e9+7;
int main(){
    fastio;
    ll t;cin>>t;
    vector<vector<ll>>fre(200449+1);
    for(int i=2;i<=200449;i++){
        if(fre[i].size()>0){continue;}
        for(int j=i;j<=200449;j+=i){
            fre[j].pb(i);
        }
    }
    while(t--){
        ll n;cin>>n;
        vector<ll>v(n),v1(n);
        input(v);input(v1);
        vector<pair<ll,ll>>pri;fr(i,n){pri.pb({v[i],v1[i]});}srt(pri);
        fr(i,n){v[i]=pri[i].first;v1[i]=pri[i].second;}
        ll mn=1e18;
        ll fl=0;
        ll g=0;
       unordered_map<ll,ll>s;
        vector<ll>v2;
        fr(i,n){
            fr(j,fre[v[i]].size()){
                s[fre[v[i]][j]]++;
            }
            if((v[i]%2)!=0){v2.pb(v1[i]);}
        }
        if(v2.size()>1){srt(v2);mn=min(mn,v2[0]+v2[1]);}
        multiset<pair<ll,ll>>s1;fr(i,n){if(v[i]<500){continue;}s1.insert({v[i],v[i]});}
        fr(i,n){
            fr(j,fre[v[i]].size()){
                s[fre[v[i]][j]]--;
            }
            if(s1.size()>0){
                auto it=s1.begin();
                while((*it).first<v[i]){
                    ll p1=(*it).first,p2=(*it).second;
                    s1.erase(it);
                    s1.insert({((p1/p2)+1)*p2,p2});
                    it=s1.begin();
                }
                it=s1.find({v[i],v[i]});
                if(it!=s1.end()){s1.erase(it);}
                if(s1.size()>0){it=s1.begin();mn=min(mn,v1[i]*(((*it).first)-v[i]));}
                if(v[i]>=500){s1.insert({v[i],v[i]});}
            }
            ll p=449;
            for(int j=0;j<=p;j++){
                ll n1=v[i]+j;
                ll g1=0;
                if(n1==1){continue;}
                fr(k,fre[n1].size()){
                    if(s[fre[n1][k]]>0){
                        g1=1;mn=min(mn,j*v1[i]);break;
                    }
                }
                if(g1){break;}
            }
            fr(j,fre[v[i]].size()){
                s[fre[v[i]][j]]++;
            }
        }
        cout<<mn<<endl;
    }
    return 0;
}

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Guyz can anyone tell why this submission to problem C2 is failing :3 (please welp)

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

C2 was really intresting .

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In D , was it necessary that only n must remain at the end , even if we can reach it beforehand ?

For example , for tree 1-3-2 , won't doing only operation 1 once sufficient ?

asking because I wrote solution considering that and got wrong answer on Pretest 2 , but later assumed that at last only n must remains , then it passes :(

Submission (pass) Submission (fail)

  • »
    »
    7 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    The problem is that the checker is verifies the depth also. Your logic works correctly only when the cat and n are positioned in a straight linear path, for example: 1 -> 4, 4 -> 2, 4 -> 3.

    However, consider a case where the path is like 1 - 6 - 2. lets say 1 connects also to -> nodes 3, 4, and 5 . So, at the very least, you’d need to remove them so have to do like 2 3, 1 ,2 4, 1 ,2 5.

    That means 1 is used twice at list so the cat can reach point 2. This is why it’s giving a wrong answer (WA).

»
7 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

[del]

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

classic hollow knight references :)

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D is beautiful.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i want to know why f2 step8 is correct,since the size of k is x

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi, I'm working on C1 and I had the exact same idea as the editorial. However, I always get TLE on testcase 5. Can someone help me figure out what is the issue?

Spoiler