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

Автор null_awe, 2 года назад, По-английски

Thank you for participating! We put a lot of effort into this contest. Special thanks to TheScrasse for contributing to these problems.

Rating Predictions

Also, check out this video editorial for problems A through C2 by one of our testers! https://www.youtube.com/watch?v=hS8Z3k57f6Q

Solutions

1984A - Strange Splitting

Problem Credits: buffering
Analysis: buffering

Hint 1
Hint 2
Solution
Code (C++)
1984B - Large Addition

Problem Credits: flamestorm
Analysis: null_awe

Solution 1

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
1984C1 - Magnitude (Easy Version) and 1984C2 - Magnitude (Hard Version)

Problem Credits: buffering
Analysis: null_awe

Hint 1
Hint 2
Solution (Easy Version)
Solution (Hard Version)
Code (C++)

1984D - ''a'' String Problem

Problem Credits: le0n
Analysis: null_awe

Hint 1
Solution
Code (C++)

1984E - Shuffle

Problem Credits: null_awe, thanks to wavelets for helping with brainstorming
Analysis: null_awe

Solution
Code (C++)

1984F - Reconstruction

Problem Credits: buffering
Analysis: buffering

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)

1984G - Magic Trick II

Problem Credits: null_awe
Analysis: null_awe

Hint 1
Hint 2
Solution
Code (C++)

1984H - Tower Capturing

Problem Credits: flamestorm
Analysis: flamestorm

Hint 1
Hint 2
Solution
Code (C++)
Разбор задач Codeforces Global Round 26
  • Проголосовать: нравится
  • +294
  • Проголосовать: не нравится

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

Judge solutions are currently being posted. Please enjoy the analyses in the meantime.

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

What's MIS?

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

E is nice

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

very fast editorial! problems are also really interesting, thank you for the round

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

F can be solved in $$$O(n \log n)$$$ time: consider the same DP, and sweep the sum over all possible values. All that changes when the sum changes are transitions PS (valid when B[i] + B[i+1] == sum) and transitions SP (valid when sum - 2*M <= B[i] + B[i+1] <= sum + 2*M). Thus, you can store the transition matrices of the DP in a segment tree and do a sliding window sweep over the sum.

H can also be solved in $$$O(n \log n)$$$ time using fast Farthest-Point-Delaunay-Triangulation: the triangles we're allowed to pick are exactly those in the FP-Delaunay Triangulation. There are algorithms for this in linear-time after computing the convex hull.

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

H is doable in $$$O(n \log n)$$$. It's a fun problem to solve in that time, but takes more effort for sure (but still definitely doable from scratch within contest time)

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

    Can you tell more details about the $$$O(n\log n)$$$ solution? I'm very curious about that.Thx

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

      I do not know where to find any description of FP triangulation, but it indeed relies on the correspondence between them. I want to find the partition of the plane into regions such that every region has one of the input points (which I assume form a convex polygon) as the furthest point (as points where three such regions meet are points determining a triangle whose circumcircle contains everything else). All of these regions are infinite and the only two infinite rays for regions $$$R_i$$$ are bisectors between consecutive pairs of points $$$(P_{i-1}, P_i)$$$ and $$$(P_i, P_{i+1})$$$. It is a good start to understand when a region consists of these two rays only — if I'm not mistaken, that's just a local check for intersections of these two and two neighboring bisectors. When you find such a pair then you can remove both of these bisectors from the set of "active bisectors" kept on a cyclic set and insert bisector between $$$(P_{i-1}, P_{i+1})$$$ and continue in a similar manner

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

        Omg, I get it. It's so magical. Thank you.

        I think it works as this :

        We use a priority queue to maintain a set of radii of circumcircles formed by every set of three adjacent points. Each time we take out the one with the largest radius, it can be proven that this circle definitely covers all the points.

        I have come up with a way to prove it, and the general idea is as follows:

        First, we prove a lemma: The circumcircle with the largest radius can always be taken at three consecutive points on the convex hull.

        After proving this, we prove that the circumcircle with the largest radius definitely contains all points, which can be done using proof by contradiction.

        I apologize for my poor English; the above text was translated by AI.

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

        265618123

        I make a submition. It's accepted.I think it's completily correct! Thank you!

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

          Nice, glad to hear that and congrats :)! I am actually not 100% sure about my own claim about local check for when I can commit a triple, but looking at it your way with the radius of the circumcircle certainly sounds convincing :)

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

    Oh , I see it(Farthest-Point-Delaunay-Triangulation) in another comment. Thank you.

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

What was problem E asking for. Was it saying you recursively are doing the step 1 and 2 until you can't anymore and that is considered as doing the shuffle exactly once. I know I'm not understanding because I don't know how they get 6 for example 4 in the sample test cases.

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

super fast editorial, thanks but i sleep now. Farewell!

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

I solved D without Z-algo or hashing, with time complexity of $$$O(m \cdot sqrt(m))$$$ by only brute force. Don't know it is legal or not but it passed the system testing anyway with 93ms (pretty surprised).

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

Super fast editorial.

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

can anyone explain why i can't hack? there is no button

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

Wow, the solution to C turned out to be clever, I have a more general solution that doesn't use the fact we only need to use op2 once, rather it's just brute force + dp:

Solution

The solution for C2 is the exact same, maintain $$$cnt_{2, n}$$$ array where $$$cnt_{i, j}$$$ is the number of ways to get to $$$dp_{i, j}$$$, the rest is just case handling to check which one took the place of the current dp and updating the $$$cnt$$$ accordingly

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

DP solutions for C1 and C2:

C1: let dp[i][0] be minimum score when we made i operations, dp[i][1]maximum score

C2: let dp[i][j] be amount of times we can get score j after i operations. as we can look only at max and min values, let's clear useless conditions after every step, then there will be only O(1) new values every time, so total complexity is O(n) if u use hash table, O(nlog(n)) — if BST (for e.g. std::map)

C1 code: 264967072

C2 code: 264965726

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

can sm1 tell me what are the 3 strings that match in this tc , problem D , abbaaaabbb output : 3

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

Wow these editorials were fast. Thanks!

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

First solve for H was from rainboy.

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

Anyone solved C using dp,it was kind of more obvious for Easy version then u just add another state to dp for num_ways to make a value,nice contest, i really like the C1 and C2

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

    can you please explain c2 ?

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

      i think coin change on cses is very similar to c2 .c1 was very similar to knapsack

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

        yeah, it is knapsack dp cause u are kind of fillinf container,adding based on just the previous state,i still that was nice problem, we really need such high quality tasks in codeforces rounds.

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

      first i assume u understood how C1 is done using dp,now lets call dp[i][0] minimum value of c up to index i element and dp[i][1] maximum value,first we compute it using smae formula of C1,now count number of ways to do it,now at every step we have four choices either use the minimum value of i-1 or max value of i-1,both with or without abs value,we just update number of ways,however we need to be careful as if minimum value equals max value for index i-1 we only consider two choices with or without abs value(as the two others are same and we would be double counting),u can check my submission for implementation details.

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

        can you please elaborate on the last point, I couldnt understand

        • »
          »
          »
          »
          »
          23 месяца назад, скрыть # ^ |
          Rev. 2  
          Проголосовать: нравится 0 Проголосовать: не нравится
          I wrote clean code based on his idea and it AC's. Hope it helps
»
23 месяца назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

in E MIS was a big hint, is MIS very standard in many problems? when I heard MIS problem became relatively very easy, proving MIS (excluding root) is the answer was also not difficult, but how would someone think that MIS could be the answer, is it just more problem-solving of a similar type?

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

The sample for F is such a garbage.

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

G is similar to this problem

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

why c2 : Thus, we have the choice of using option 2 or option 1 at any index j<i where the prefix sum is non-negative

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

Can someone help me explain this solution for C2? I just guessed a conclusion during the contest

my submission

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

Both C1 and C2 are akin to the knapsack problem in dynamic programming, correct?

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

Hi, I got tle for C1 (easy). I tried dp (memorisation using maps)

https://mirror.codeforces.com/contest/1984/submission/264928809

Would be great if someone could give me insights on this and share a dp solution that got accepted for C. Thank you!

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

Hey Guys I solved C1 (not in the contest) using dynamic programming using two dp

dp_max: the max sum we could create till i taking ith 
dp_min: the min sum we could create till i taking ith

Transitions:

if(arr[i] < 0){
            dp_max[i] = max(dp_max[i-1] + arr[i], abs(dp_min[i-1] + arr[i]));
            dp_min[i] = dp_min[i-1] + arr[i];
        }
        else{
            dp_max[i] = abs(dp_max[i-1] + arr[i]);
            dp_min[i] = dp_min[i-1] + arr[i];
       }

with base case dp_max[0] = 0, dp_min[0] = 0 (---1 based indexing)

This solution got accepted now can anyone tell me how will I use these transitions to build the count array which will count all possible ways to acheive this maximum ?

Ps I guess it should be solved using the same way we find all the LIS, or All the min paths in Dijkstra algo. Pls help

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

In Problem C2, I am using below code to calculate power of 2, but this is giving stack overflow error. Any idea why?

using ll = long long;
 
long long power2(int n) {
    if (n == 1) {
        return 2;
    }
    long long p = power2(n/2);
    if (n & 1) {
        return p * p * 2;
    } else {
        return p * p;
    }
}
  • »
    »
    23 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    overflow. you need to use mod. Also, too many recursive calls will give stack overflow.

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

      Where?

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

        Also, note that if you are calling this function multiple times for large values of n and are not caching the results, it will give stack overflow error.This is because very large number of function calls will be made. So, its better to cache the results.

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

Another approach for B problem: As all the digits are large, the sum is bound to increase by 1 digit, so if $$$x$$$ is large and has $$$n$$$ digits, then $$$a$$$ and $$$b$$$ must have $$$n-1$$$ digits.

What is the largest large number with $$$n-1$$$ digits?

Answer

After that, I subtracted the largest "large" number of $$$n-1$$$ digits from $$$x$$$, resulting in a number say $$$y$$$.

Now, we have to ensure two conditions:

  1. $$$y$$$ has a length of $$$n-1$$$.
  2. $$$y$$$ doesn't contain any digit as $$$0$$$ (why?)
Proof

Hopefully, this is easy to implement and you can see my submission here: 264891168

Please let me know, if there is some fault in the solution, or any other clarification is required?

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

    I think I have a far simpler answer that does require any integer conversions and works purely with strings, thus it can be used for very very large numbers:

    Basically, for any number to be right, 4 conditions must be met:

    • Number must not be a single digit.

    • The first digit must be a '1'.

    • The last digit must not be a '9'.

    • All remaining digits must not be a '0'.

    Please let me know if there's any holes in my logic.

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

I am struggling with a testcase right now on Problem B, the judge is saying that it expected an answer of YES on the number 793, which I believe should be a no.265101056

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

Почему нет разбора на русском??? Кто нибудь please объясните решение задачи C2

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

How can I fix the memory limit exceed for my solution for C2 ? 265166920

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

    The way you utilized the queue was actually a bruteforce, which will not work. Take this test for example:

    1
    40
    -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40
    

    Answer is just $$$1$$$, but due to constant doubling, you'll quickly MLE/TLE yourself.

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

Can someone elaborate on how implementation works for E ? Proving the MIS lemma is easy, but I can't figure out how to implement the dynamic computation. Like what is the dp formula ? I've been trying with rerooting and dp on edges as well

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

    Okay I figured something out, the implementation was harder than what I expected at first. Still, this problem is lovely, I don't regret wasting 2 hours on it instead of solving D during the contest !

    Basically my idea was to implement is to root the tree at a none-leaf node (exists if n > 2). Then I compute the MIS for going up and down the tree, starting at a given node (with dp). For going down, it's easy dp, it only depends on doing down for subvertices that are lower. But I need to store the state that I chose for each child when going down, that I will use for going up.

    Indeed, when going up from node i, whose parent is p, I need to add the value of going up with p, plus the value of going down with p (maybe minus one if p is set to be in the MIS), minus the value of going down with i, whose state is set by what I chose when going down with p.

    It would be clearer with maths formulae but I wanted to keep my comment short since idk if anyone will require my hindsight.

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

    For me I root the tree at a leaf node. a = MIS if choose root
    b = MIS if not choose root
    If a<=b, return b+1
    Else we check if the MIS containing the root also contains all the leaves. If MIS also contains all the leaves, return a, else return a+1 (because we can root the tree at that leaf).
    I use DP from a node to each of its children, state (a, b, a_spare_leaf, b_spare_leaf)
    Solution https://mirror.codeforces.com/contest/1984/submission/266256460

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

For A, if the array isn't [1, 1, 3, 3] also impossible? Hint #1 and the solution code show that it is impossible only if all elements are equal.

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

My code for problem D is failing for test case no.83 , can anyone please explain if double or multiple hashing is the only way to avoid this 265689130? i used first time polynomial hashing with mod 1e9+9 and prime 31 only 28 test cases passed , then later using 1e9+9 and prime as 53 it passeD 83 test cases. Is it possible that there exists a more better prime for this to pass with single hashing ? le0n null_awe

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

The problem ratings are out, you can maybe update the prediction table? null_awe

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

For Div-2 D
I think a much simpler solution can work,
We will try to find candidate $$$t$$$ where the first and the last characters are non-$$$a$$$
Such a $$$t$$$ must start from the first non-$$$a$$$ character. we will iterate over the endpoint to check for validity.
To check if we have a valid $$$t$$$ we will check for all non-$$$a$$$ characters if the number of characters in $$$t$$$ are divisors of the frequency of corresponding alphabet in $$$s$$$, and all of them leave the same quotient.
There will be at most $$$O(\sqrt[3]{n})$$$ such $$$t$$$, which will be even lower in practice.

And you can check the validity of this $$$t$$$ in $$$O(n)$$$.
Also you can compute how many prefix and suffix $$$a$$$ can be added to this $$$t$$$ and still result in a valid $$$t$$$.

Submission — 265896129

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

    Yeah did the same but used string hashing for faster check too, I believe my solution is just $$$\mathcal{O}(n + \sqrt[3]{m} * log{(m)})$$$ where $$$m$$$ in the number of non-a characters, 265886340

    if my time complexity is incorrect lemme know the correct one

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

Why is checking adjacent elements only sufficient for F?