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

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

2148A - Возвышенная последовательность

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148B - Лазеры

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148C - Тест на выносливость

Solution (written by cry)
Code (C++) (litfan)

2148D - Уничтожение полей одуванчиков

Solution (written by cry)
Code (C++) (AksLolCoding)

2148E - Разделение

Solution (written by cry)
Code (C++) (kwant)

2148F - Гравити Фолз

Solution (written by cry)
Code 1 (C++) (cry)
Code 2 (Python) (Vladosiya)

2148G - Последнее желание фермера Джона

Solution (written by avighankc)
Solution 2 (written by Jteh)
Code (C++) (Jteh)
Разбор задач Codeforces Round 1050 (Div. 4)
  • Проголосовать: нравится
  • +74
  • Проголосовать: не нравится

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

Fast as light

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

Fast editorial! (please like im farming)

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

I am a noob, I can't understand the rules does it mean that if I haven't participated in 5 previous rounds and solved a Question I won't get rated?

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

Problem E was a beautiful problem for a div 4.

Enjoyed the round.

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

Problem-F: How it works step by step:

Read all the lists Keep track of their lengths. Start building the final list Look at all lists that still have numbers left. From the remaining numbers in each list, pick the list whose numbers are smallest when compared from the current position. Add numbers from that list Take all remaining numbers from that list and add them to the final list. Mark that list as used so we don’t pick it again. Repeat Keep repeating until all lists are used or we have added all numbers. Print the final list This is your combined list that is as small as possible in order. Key Idea: Always pick the next list whose remaining numbers make the smallest sequence possible. Once picked, take all remaining numbers from that list. This is called a greedy approach.

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

B was easy but the problem statement was tricky to understand.

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

Got problem F accepted 10 minutes after the round got completed :( Still ENJOYED the contest :D

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

Fast editorial thanks! E and F was awwsome

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

F possible to solve with $$$O(\sum k)$$$ time

Oops, my solution wrong. But anyway this time complexity exist — read: https://codeforces.me/blog/entry/146112?#comment-1308911

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

Fast editorial fr, fr.

orz to The coder, The myth, The legend, cry

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

Is anyone else having the same messed up rankings as me? AK, penalty time 217, 10th in common standings (but not shown), 69th in friend standings

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

Wrong interpretation for a solution for F, nvm. :)

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

    Interesting idea! So clear, and also have "one pass through the data" vibe!OwO

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

    what if we don't check the unique minimum case? will it time fail directly?

    and even if we do check it suppose there are 2 identical arrays(minimums) so leading to no unique element case. In this scenario isn't this method leading to a (mx*n) time algorithm? is that fine? (could you please explain how it runs fine?)

    my similar solution also passed that didn't check for unique case but kept track of when a minimum array ends(since it gives more options) however i am not able to analyse the worst case complexity. During the contest i assumed it will exceed TL. 338529461

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

      This is true. Nice catch.

      The current implementation runs in $$$\mathcal{O}(n \cdot mx)$$$, but it can be improved to $$$\mathcal{O}\left(\sum k\right)$$$ by storing, for each column, only the indices of arrays that actually have an element there. This way every element is processed at most once.

      In the given code, however, $$$mx$$$ and $$$n$$$ are dependent — the worst case occurs when all arrays are identical (same size and same values). Even then, the bound is still manageable, since $$$\sum k = n^2$$$ which means that $$$n = \sqrt(\sum k))$$$ yeilds to $$$\mathcal{O}(\sum k * \sqrt(\sum k))$$$

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

By the way there's a typo in the editorial for E:

"There is can only be one way that all multisets can contain must the exact same elements"

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

how does the order not matter in E? like the order must matter right?

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

Hi guys!

This was my first contest using c++, can somebody please explain to me why did my code output 33? https://codeforces.me/contest/2148/submission/338397788

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

    Very cool bug, lol. You are getting 33 because scanf is expecting the memory address where to store the int read from the stdin. Since you have not provided any, it just ends up using the register value that was in %rdi earlier. This is undefined behavior, but here it happens to be the address of the variable n. So, all new values are read to n actually. And, since the last value in test case 2 was 32, you have n + m = 32 + 1 = 33. For test case 1, the last value and the original n value both happen to be 1 so it somehow works.

    For quick fix you can replace your scanf lines with scanf("%d", &x);. We are reading new values to x because we have no use for x and these new values. Ideally, you would declare a new int and then read in that.

    Read https://usaco.guide/general/input-output for C++ specific I/O guide.

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

Can anyone hack my solution, don't know why it passed even though it is O(k^2logn) for F:

https://codeforces.me/contest/2148/submission/338467466

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

For problem G, it suffices to only check prime divisors, which lowers the time complexity a lot if you precompute those.

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

Super fast editorial... Thanks for the contest.loved problem F and happy to solve in the contest

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

I know this is not the place to ask such question, but still: is there anyway I can bypass "crawling" block, so that I will be able to continue hacking submissions?

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

    Apparently there's none; the only way to get unblocked is to just wait. From my experience, you sometimes get unblocked after a few hours, and sometimes blocking persists for more than 10 hours. So yeah, I don't know...

    I agree that it's silly to block someone who eagerly tries to hack solutions in the open hacking phase. Also the warning text is a bit too scary and unhelpful.

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

For some random array is the No. of times does the prefix gcd change almost O(1) ?

i.e # of times [g != __gcd(g, a[i])] this condition occurs found to be O(1) for large random array?

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

too short F with python slices. i think it can be hacked

338490282

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

Problem G can be done very easily by just going through each number. Say, gcd till now is g and after adding current number, gcd becomes g', then there are only two cases —

  1. g' == g: In this case, if current element is not part of longest subarray, then answer does not change. If current element is part of longest subarray, i.e. it affects our answer, then g' has to be one of the divisors of current element. Hence ans = max(ans, F[d]), where 'd' is any divisor of current number > g as g'> g and F[] is cumulative frequency of divisors till now.

  2. g'< g: this is best case, we already found best subarray till the last element & current element decreases the gcd which satisfies the problem condition, that's what the problem is asking for!

[submission:https://codeforces.me/contest/2148/submission/338531912]

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

Problem G can be solved in $$$O(n\log n+\sum_{i=1}^{n}\tau(a_i)). $$$ My submission: 338537949

For each element, we must increment the count of each of its divisors by 1. Then, the problem boils down to finding the maximum count of a divisor such that it is not equal to the number of elements processed so far. Naively, this can be done with a multiset, but the heavy log factor TLEs. So, we can instead build a "buffer" which holds all elements with count equal to the number of elements processed so far (essentially, all elements in the buffer are divisors of the gcd so far). If the current element we process is divisible by some number x in the buffer, x remains. If not, we remove it (it does not divide the gcd anymore). The answer for the prefix is then the maximum of the count of every divisor not in the buffer.

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

I believe my solution for Problem F is $$$\mathcal{O}(\sum k_i)$$$. It's just about maintaining all the possible candidates for the current element. Here is The link.

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

Can someone tell me why is my code failing for F..

https://codeforces.me/contest/2148/submission/338427667

any failing testcases will be appreciated

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

Can my G be hacked? ( https://codeforces.me/contest/2148/submission/338510007 )?

Uses segtrees to find most occurring prime factor, and gets TLE with segtrees of size 2e5. Realised 1e5 works a bit later and got AC with that, but still seems slightly iffy imo.

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

E is much easier than F,i think F is a good problem! btw I solve A-E so slowly because of the bad network I took half of time to load the problem and used m1.cf.com to submit lol

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

These questions are very challenging(For Div4)! My friend's F code has been hacked, haha.

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

Man, what the heck! My Python code for E got a TLE on test case 10 during post-contest system testing. It has the same exact logic and time complexity as the editorial's C++ solution, which feels so unfair! :((

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

the test case #20 of problem F n=2 but it has only 1 following line? Am I missing something?

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

how the f*ck did i fst my code is literally fkn logically equivilant to the edi like wtf ts pmo sm like ok fine i have fst i dont care, but i literally do not see a single thing wrong with my code and i am not debugging 300 lines of shit to figure ts out. i literally asked like 4 masters to check my code and i still got fst great fucking vegatables ok go downvote me now

k srry for crashout ig

anyways uh can someone tell me whats wrong lol (i seriously got no idea)

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

There is a typo in Problem F:- - Then, ki space-separated integers ai1,ai2,…,aiki follow (1≤aij≤2⋅105). it should be aik instead of aij in the bracket

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

Can Somebody explain the editorial of F(Gravity Falls),in simple language, I am having difficulty understanding that

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

    Basically, you can stack the arrays in any order and the arrays must be left-aligned (A longer array on top of a shorter one is also ok). Then, elements in each array will fall down until it touches another element (In other words, no elements are "floating"). Finally, get the elements at the bottom of the stack from left to right and form an array. Let the array be a, your task is to find the lexicographically smallest a.

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

I solved F by O(sum(k) + n)

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

Hello, my solution 338490913 was flagged for coincidence with another user’s code. I do not know the other participant at all and did not share or receive any solutions anywhere (I compile my solutions offline). I solved the problem independently. The similar part of the code is generic, which I use snippets for, and the core logic seems to be analogous. Please review this case manually. Thanks!

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

omaralimm Sorry for tagging you, i saw one of your comment say that you like the Problem G, that is why i am tagging to get some quick reply, so here is my confusion, do you have any idea??

I am quite confused in solution 2 of problem G, why the time complexity goes to NlogN + N(cube root (N))?? Is there any formal proof?? It is quite of confusing to see NlogN term and even the cube root term!

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

    I can prove it.

    Firstly, let's get all the divisors of numbers up to $$$N$$$ using sieve like method before we start solving the testcases.

    That will be $$$O(NlogN)$$$, which comes from this equation — $$$n/1 + n/2 + ... n/n = n*log(n)$$$.

    And the number of divisors of a number $$$n$$$ is $$$cbrt(n)$$$.

    So, we do precomputation with a complexity of $$$O(NlogN)$$$ and solving the testcases with a complexity of $$$O(NcbrtN)$$$.

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

Problem G can be solved with complexity $$$O(n\log A)$$$, where $$$A$$$ is the maximum element.

Let's improve the Solution 2 in the tutorial:

Suppose $$$g_k=gcd(a_1,\cdots,a_k)$$$ and $$$g_{k+1}=gcd(a_1,\cdots,a_{k+1})$$$. If $$$g_k \gt g_{k+1}$$$, then there will be a prime $$$p$$$ satisfying $$$g_{k+1}p\mid g_k$$$.

Let $$$m$$$ be the maximum integer that satisfies $$$p^m\mid g_{k+1}$$$ but $$$p^{m+1}\not\mid g_{k+1}$$$, then we have $$$p^{m+1}\mid g_k$$$. Thus, we only need to try divisors in the form of powers of prime numbers.

Since the number of divisors in this form for a number $$$x$$$ is at most $$$\log x$$$, we get the complexity at the beginning.

My submission: 339058812

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

I feel a bit confused because of the analysis for problem E:"Say our left pointer l is fixed. Until the inequality is satisfied, we will keep increasing the right pointer r. Then, we will add r−l to the answer since all subarrays a[l,l],a[l,l+1],…,a[l,r−1] are satisfied. Then, increment the left pointer by 1 and repeat." Isn't this actually a different method from the code written in the solution? In the method described in the analysis, for each l, we find the largest r such that the subarray [l, r] satisfies the condition, and then we count the subarrays from l to r. But if we implement this method directly, it would require resetting the count each time l changes, leading to O(n^2) time complexity. This method isn't the sliding window technique, right? Am I misunderstanding something or is the analysis wrong?

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

Hello, I want to know that why this code for problem G (using segment tree) https://codeforces.me/contest/2148/submission/339214294

is NOT GIVING TLE

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

Is there a code implementation for solution 1 to problem G?

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

Isn't the expected solution for second testcase for 2148D - Destruction of the Dandelion Fields wrong? Shouldn't it be 12 instead?

cry can you respond to it please.

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

how is E nlogn in editorial solution seems n^2

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

to be honest, for E author's code is too hard for beginners... this is my solution very easy to understand #383158117 or https://codeforces.me/contest/2148/submission/383158117