Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Sanae's blog

By Sanae, 6 months ago, In English

Thank you for helping Marisa, Reimu, Cirno, Sanae, Amanojaku and Momoyo!

Leave a comment!

2228A - Marisa Steals Reimu's Takeout

Author: Sanae

Solution: Sanae

Step 1
Step 2
Step 3

2228B - Remilia Plays Soku

Author: Sanae

Solution: Sanae

Solution

2228C1 - Cirno and Number (Easy Version) and 2228C2 - Cirno and Number (Hard Version)

Author: Sanae, Sugar_fan

Solution: Sanae, Sugar_fan

Solution

2228D - Sanae, Cross and Color

Author: Sanae

Solution: Sanae, fanhuaxingyu

Solution 1
Solution 2

2228E1 - Amanojaku and Sequence (Easy Version) and 2228E2 - Amanojaku and Sequence (Hard Version)

Author: Sanae

Solution: Sanae

Tutorial: CirnoNine, fanhuaxingyu

Sanae's Solution
CirnoNine's Solution
fanhuaxingyu's Solution

2228F - Momoyo and the Network

Author: Sanae

Solution: Sanae, juan_123, SDSXC

Sanae's Solution
juan_123's Solution
SDSXC's solution
  • Vote: I like it
  • -263
  • Vote: I do not like it

»
6 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

i feel bad that i missed n=3 case in B :(

»
6 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

today is more cheaters in this contest than expected cf should take strict action on this

»
6 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

how did people use fenwick trees for D? I tried this but got 6-7 TLEs / MLEs, despite trying to optimize constant factors, use lighter trees, rewrite in C++, etc

eventually I had to use a prefix/suffix approach to pass

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it

    That wasn't even enough for me. I ended up passing with O(n) inner loop and pragma AVX. I'm going to run some benchmarks once practice opens up and will report back

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    I passed easily with $$$O(n)$$$(without optimizations) and got TLE in Pretest #19 with $$$O(n \log n)$$$. I guess that's normal.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

let d be the number of digits of a,can any tell if we generate all possible numbers with the 2 given digits of length=d and check for min difference (2^18, recurrsion), i dont know digit dp, and check for the largest number with (d-1) digits and smallest number with (d+1) digits , will it work??

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    No because there are up to 10,000 test cases, and you might be doing 2^18 operations for each one

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      you would think so, but notice there are up to 10 choose 2 oprion for 2 digits, so you can just save it for each pair, for a testcase, dont go over all the number but just upper_bound, lower_bound on the vector with the 2 digits you need

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    so for your question, if implemented correctly YES

    now the solution isnt truly digit dp but more just logical thinking of what you can do and the common observation that

    10^i > sum over j < i of 10^j

»
6 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I wasted too much time on D because it doesn't allow $$$O(n \log n)$$$ algorithms to pass, so i didn't finish calculating E1's equation :(

Feeling bad because I succeeded to pass the example of E1 ten minutes ago, which is just 25 minutes after the contest :(

Hope that my rating won't decrease for that..

»
6 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Maybe the problem F is so much similar to 2222G - Statistics on Tree?

»
6 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

In Problem D, What is the idea behind forcing the constraints that some (N log N) solutions pass and others not ??

If the author think that this kind of forcing constraints will make the problem anti AI, I think he made it harder for humans than AI.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it -8 Vote: I do not like it

    Initially, I only intended for the $$$O(n)$$$ solution to pass...

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I feel like a more explicit decision should have been made. As of now, it seems the n log n editorial solution works only when written very tightly and in C, and java/python/etc users also get screwed.

      Also visually n log n with 2 million * 21 looks like it should run fine. Even when I sped up the inner loop to O(n) (but still had std::sort and std::set to do coordinates), I still got TLE.

      • »
        »
        »
        »
        6 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I got rid of set and only used sort and that managed to pass. I also think there was a way to remove sets by first storing it in a vector of vectors then later adding it adding precomp of like n but not that much.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Make your complaint.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Stupid D.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it -32 Vote: I do not like it

    AI-solveable E.

  • »
    »
    6 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I believe the contest was good in it's core, and I am still thinking on F

    but my only complaint is this, in problem E you can't take a question from a combinatorics exam, (I dont really means it's from that but what I am saying is that it's only math and not common one, like the tricks are really just math and not ordinary one, like a question you would see in the end of a combinatorics semester in University)

    and I belive that solving just math, and then saying ohhh segment tree to do it faster is not a true cs question. like I believe everyone which is above like 1600 understood that once you solve E1 segment tree will solve E2.

    so thats the only thing that bothered me just because I was hoping for something beautiful and got a page of math instead :(

    anyhow, thanks for the contest it had been a lot of fun!

»
6 months ago, hide # |
 
Vote: I like it +42 Vote: I do not like it

I am a fan of wdoi, but this contest is not good enough.

E is too complex and meaningless as Div2 E. I don't think any problem with difficulty <=3000 should use so looong calculation.
And F has a very classic and simple solution: just use binary search, then use simple dp and sorting to check. You can just pass with $$$\Theta(n\log n\log V)$$$ complexity, or sort before binary search and use two-pointer to get $$$\Theta(n(\log n+\log V))$$$.

Plz bring better problems to participants at next contest of wdoi, and accept suggestions about problem. Thx.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +20 Vote: I do not like it

    Addition: I expect E2 worth >=2600 difficulty, but 100+ participants pass this problem, and F is easier with less pass. How many cheaters in Div2??? That is insane.
    If an(/a) expert/specialist pass this E2 in 1 hour is common, I think people can still challenge AI :)

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Strongly agree that F is easier and requires significantly less time than E (even a single E1). The amount of AC's is probably caused by nominal problem difficulty. E.g. I spent 40+ minutes on E1 (without success) and read F just 5 minutes before contest end. Finally solving F took me 50 minutes, but for E1 I spent half of next day and still confused with tons of formulas, still no AC. But in overall I liked problem F, I think it's suitable as Div2E. E is a math problem, not very good for a programming contest at all.

    • »
      »
      »
      5 months ago, hide # ^ |
      ← Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      E makes me vomit, the hell is this calculation. I thought the same thing as tutorial but couldn't collect patience to sit and write all this.

      (though so much to learn)

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Someone passed in 30min.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    In the testing, the average time to solve is E is within 1h.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Oh, crazy. But I think, if the same difficulty (E1+E2 worth 3500 points, same as F) costs very different time, this is unacceptable for participants who try E and ignore F most of the time.
      And, someone passed in 30min can't show anything. The implementation complexity is very different for rating<2100 and rating>=2800. (Maybe same as C2, it also needs clear thinking and implement.) Many of the hard problem can be solved in 30min, but if participants fall into cases of counting and coding in this problem, it is normal to spend >=1.5 hour.

      (By the way: I think may be more CNOI style than Codeforces style, as you can spend more time on a difficult problem, because most of CNOI contests have 4 problems and >=4 hours.)

      Thx for your reply.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    f looks so classic.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my submission:- https://codeforces.me/contest/2228/submission/374854997

can anybody tell me what's wrong with this

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    plz mention what approach you are using for anyone to read your code easily.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    so first of all we get the string of a and remove first charecter until it is not in D

    then we make two cases

    b > a

    in this case pick sallest number > d if no then don't compute this case and make all other numbers smallest possible

    compute both numbers

    and take abs difference

    same is done with the second case

    now when b has less digit then a just get x = number of digits in a and take maximum digit in d x — 1 time to get this value and again update answer

    the case with more digits is handled this way

    if(d[0] || d[0]==0&&n>1) {
                    ll tr=0;
                    for (int i = 0; i < sz+1;i++) {
                            tr=tr*10+(d[0]==0?d[1]:d[0]);
                    }
                    ans=min(ans,abs(tr-a));
            }
            if(d[0]==0&&n>1){
              
              ll tr = d[1];
              for (int i = 0; i < sz; i++) {
                tr *= 10; 
              }
              ans=min(ans,abs(a-tr));
            
            }
    
    

    here sz is number of digits in a

    • »
      »
      »
      6 months ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it +8 Vote: I do not like it

      605 4 2 5 6 9

      Correct answer: 6

      Use this test case to debug. It is incorrect to remove all the numbers in the beginning that match. There are cases where it is optimal to not match all the beginning digits.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      correct testcase pointed out by pancakes. Another simple testcase could be:

      149 0,1,4,5 Answer = 150-149=1 If we try to match the longest prefix, we have to make 145 as the closest possible number. Then, you will report 149-145=4 as your answer.

      One good advice for these adhoc problems is trying to prove whatever you assumed as your solution. Or even trying to find testcases where your solution might not work. If you find a suitable test case, you will end up finding the solution by just trying to solve the problem for that test case.

»
6 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Misunderstood B :(

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If Remilia does not move at turn 1, k is still 1, so Remilia can move at turn 2. Not "can move before turn k", true is "can move most k turns".

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Just got it, thankyou for explaining!

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      In problem B, Lets say n=4, x1=2, x2=4 and k>0, won't the distance between them reduced by 1? Help me understand this situation.

      • »
        »
        »
        »
        6 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        If Remilia moves at turn 1, the distance will become 1, and Reimu can catch in her turn 1. If Remilia doesn't move, the distance still 2 at turn 1 of Reimu, Reimu move to position 1 or 3, distance=1, then at Remilia turn 2, she move to the other position, then the distance still 2.
        The key is, if move cannot increase the distance, Remilia should wait and save the moving chance for following turns.

        • »
          »
          »
          »
          »
          6 months ago, hide # ^ |
          ← Rev. 2  
          Vote: I like it 0 Vote: I do not like it

          Ohh Thank you. This makes clear. I misunderstood that "staying" would also decrement her 'k' value.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    if initially the distance of both sides are the same, The first player stops at its place for 1 round. And then the second player would decrease the distance by moving in either direction. After the 1st round, they start chasing each other in the same direction. So it's still min_dist + k.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yep! Misunderstood this one, as k is the time going on, Thanks for making it clear!!

    • »
      »
      »
      6 months ago, hide # ^ |
      ← Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      But, somehow I had to add $$$1$$$ to the answer if the $$$\operatorname{abs}(dist1-dist2)\leq1$$$, because $$$\text{Remilia}$$$ would choose not to move in this case, so $$$k$$$ remains the same but the initial $$$min\_dist$$$ decreases by $$$1$$$.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Same Here

»
6 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

I didn't like this one :(

A was fine B wasted a lot of time because I thought k was the total number of Remilia moves (it's total number of moves Remilia makes where she doesn't stay in place). It's my fault for misreading but still feels bad. C isn't that bad conceptually but it got REALLY bad once I started implementing. idk I find these kinds of questions where there isn't an insight just caseworking super boring. D looks interesting but I didn't get to it because of ABC :(

»
6 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

What was the intended solution for C1? Is it the same as C2? If so, why did you split C into two subtasks? The editorial's solution doesn't seem like it would be more complex to implement for 10 digits instead of 2. I started writing a brute-force solution for C1 (checking all 2^18 possibilities), but then realized that there are 10^4 tests per case and abandoned it.

»
6 months ago, hide # |
← Rev. 3  
Vote: I like it +1 Vote: I do not like it

I used binary search for C1 and C2. I don't really know how to explain it look at my submission: 374842701, if you struggled with implementation I would look at it because it's a lot simpler than greedy

would say L contest but I got paid off with expert performance

Also, are hacks disabled for any problems?

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Bro wtf is your code doing? please explain

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it +14 Vote: I do not like it

      Ok, so first we define a function $$$\operatorname{gen}(x, w, b)$$$ where $$$x$$$ is the list of numbers, $$$w$$$ is the the amount of digits of the generated number, and it finds the $$$b$$$-th smallest number (0-indexed). We can do this by representing $$$b$$$ as a base $$$n = \operatorname{len}(a)$$$ mask, for example:

      $$$\operatorname{gen}([1, 2], 4, 6) = \operatorname{gen}([1,2], 4, 0110_2) = 1221$$$
      $$$\operatorname{gen}([1, 2, 3], 4, 5) = \operatorname{gen}([1, 2, 3], 4, 0012_3) = 1123$$$

      For each $w$ from $$$1$$$ to $$$18$$$, we will binary search for the smallest value greater than $$$a$$$ that can be created from the digits, and use $$$\operatorname{gen}$$$ to create these values. The value with the smallest absolute difference per width will either be the value found from binary search, or the generated value that is just smaller than it.

      Sorry if this is unclear it's a bit difficult to explain as I said

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      https://www.youtube.com/watch?v=AzvIHqztzKg

      He as the same idea for C(1/2) like sc3developer. Maybe the video will help!

»
6 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

CaseForces

»
6 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

C has many cornercase without effective examples.What a "wonderful" problem.

»
6 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

B was super obvious but unfortunately I spent a lot of time trying to find the n=3 edge case. C1 and C2 are the same solution basically and problems like this are super boring, not creative just implementation hell.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E1 we can solve for sum of cubes or higher powers right?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

didn't C need some heavier formalism to really define if b = 0 is always a possible solution or not? For me, at least, that wasn't clear at all; but I might be bugging.

»
6 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

what is the point of asking n=2 soln for c1

»
6 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

So, I did some testing and I don't really like D.

During the round:

  • my first O(n log n) first attempt using sweep line: TLE pretest 19
  • I tightened inner loop to O(n), but I still used std::sort and std::set once at the beginning to filter out duplicate x coordinates: TLE pretest 19
  • Changing set filter to sorting: 0.95s AC
  • This is annoying in my opinion. All I wanted was a sorted list of x coordinates with duplicates removed. Doing that with a set/prio queue method vs sorting and then sweeping should not be that big of a difference. But, at least now we know, std::sort is fast n log n, sets and maps are slow n log n.

After, the round, I tried a true O(n) solution with counting sort: 1.79s AC, actually was worse.

My conclusion is that I feel like the time limits were set WAY too tight, and were not super effective at discriminating between O(n) and O(n log n) at all. This problem felt like constant factor hell in C++ and I'm not sure it's even solvable (in n or n log n) in java/python. One of my friends daniel.glabai had O(n) inner loop in java and TLE19'd as well.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it -8 Vote: I do not like it

    Java can pass and it’s fast enough.

    https://codeforces.me/contest/2228/submission/374837428

    • »
      »
      »
      6 months ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it +3 Vote: I do not like it

      I'm not sure how that runs so fast. Is it the manual input reader?

      I'm not sure how everyone else feels, but in general, problems where a correct approach TLEs or runs in very borderline time aren't interesting or fair in my opinion. It seems like many people with valid O(n) or O(n log n) approaches get TLE. What was gained by using 2 million instead of 1 million, or even 200k (I don't think there is any sqrt decomposition that needed to be killed)?

      PS: I hope you're not taking the negative feedback too personally. I am aware of and deeply respect the insane amount of effort it takes to write a round. Maybe I should put my money where my mouth is and start testing rounds :p (but I'm not sure if that's something you can just volunteer for)

      • »
        »
        »
        »
        6 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Yes, some correct approachs are killed, which is my fault. Thank you for understanding.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    yeah, i failed with O(nlogn) during contest as well with TLE in TC19. just a tiny bit disappointed as well because O(n) passed in 1.75s which is not super comfortable.

    But yeah, good to learn that if n ≤ 2e6, then O(nlogn) might not be a safe option, and if you can think of O(n) approach, you should go with that implementation.

    Here is my side by side O(n) and O(nlogn) implementation (commented out the O(nlogn) one): 375001273

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yeah, I think here it was sets being too slow since the fastest solution I had still had overhead from sorting. I guess it makes sense since mergesort is extremely cache friendly (I'm not sure that's the one std::sort uses but theirs is probably even faster) vs lots of address dereferences and cache misses when walking down tree nodes full of pointers.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone share their soln. to C1? Or it would be wonderful if you could point out the problem in mine..

https://codeforces.me/contest/2228/submission/374822532

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I feel in B there is a mistake for example let's take the case of 6 1 4 3

so now both are at a max possible distance and according to the submitted soln the ans comes out to be 6 but that's incorrect because when x2 moves in whichever direction x1 will move in the same and the suddenly their difference in distance decreased by 2.

so answer should be 4 instead of 6. pls correct me anyone if this is wrong !

Thanks !

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

CirnoNine's solution to E1 asserts that:

For all weak compositions of $$$N$$$ into $$$k$$$ parts, we have

$$$\sum_{\text{valid $$$x$$$}} x_p(x_p-1) = C \frac{2N(N-1)}{k(k+1)}$$$

and for $$$p \neq q$$$,

$$$\sum_{\text{valid $$$x$$$}} x_px_q = C \frac{N(N-1)}{k(k+1)}$$$

Why do these properties hold? Or are these just "well-known" identities of weak compositions? (If it's the latter, any reference?)

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Wait I can't really understand question D's second solution, can someone pls explain to me? Thx

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    hi sir if u have time could you please help me i want to get a good job i just want to ask:- 1. how many problem should i solve a day 2. what to do when i am not able to solve low rated problem 3. any secret for faster progress?

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Just do more problems, learn some Data Structures, and actually reason them out and understand what they mean. If you can't solve low rated problems just do more of them. Took me around 200 questions to build intuition for around 800-1200 range. For low rating problem just stack all your free time solving them and try to get them as fast as possible.

      • »
        »
        »
        »
        6 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Thanks for the advice, The 200-question milestone gives me a realistic target to shoot for. I'll start stacking my free time and grinding the low rated ones to build that speed and intuition.

»
6 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

In 2228B lets say n=7 x1=1 x2=4 and k=2

1st second

-Now Remilia moves to x2=5 from x2=4 optimally, this is the optimal move for Remilia because going to x2=3 will decrease the distance between the two.

-Since Remilia chose x2=5, Reimu will try to minimize distance so he will come to x1=7 from x1=1 optimally.

2nd second -Now Remilia moves to x2=4 from x2=5 optimally.

-Since Remilia chose x2=4, Reimu will try to minimize distance so he will come to x1=6 from x1=7 optimally.

further seconds

Now Remilia cannot move anymore so she will stay at x2=4 and Reimu is at x1=6 and the difference between then is 2

So ans is 2(initial second) + 2(last differene between the two after Remilia is out of moves)=4

But according to this tutorial ans = min(7-(4-1),(4-1))+k = min(4,3)+2 = 3+2 = 5

Why?

  • »
    »
    6 months ago, hide # ^ |
    ← Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    Same doubt. But initially, Remilia at x = 4 can also stay there, right? Going to x = 5 will be the same distance as staying at x = 4 initially.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Remilia is not required to move on every turn. If she doesn't move it doesn't count towards decrementing k so the optimal 1st second choice is to not move. I had the same misread in contest it's not worded well imo.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yup, so considering staying as the optimal choice, even when we have another choice for moving. So, in the example n=7, x1=1, x2=4, k=2, Remilia initially has two equally good choices before Reimu moves: staying at 4 or moving to 5, since both keep the current distance at 3. So, we should consider staying? right?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This might be the worst contest of all time, the one that eats up your rating by providing garbage trash test cases, it seemed like intentional and of no use except giving you a -50, makes you feel like trash after the contest and ruins your day, fuckass implementation problems, all the future contest makers should take a learning from this shit

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I solved 4 problems, thank you for the competition, I liked it

»
6 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

It may be easier to understand D after discretisation? Because the number of ways to place a dividing line would just be Max — Min. We can sort all points in increasing order of x and then iterate the position of horizontal line. Then the number of valid, distinct ways to place vertical line will be max(0, min(prefMax, suffMax) — max(prefMin, suffMin)). prefMax is the maximum y, after discretisation, of all points on the left of horizontal line, and similarly for suffMax, prefMin, suffMin.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem B, Lets say n=4, x1=2, x2=4 and k>0, won't the distance between them reduced by 1? Help me understand this situation.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    My interpretation was, as long as the one being chase has a remaining move k yet, the min distance will not decease, only when k becomes zero the distance will start closing in. So in other words the total distance is actually k + the minimum distance.

            long n = in.nextLong(), x1 = in.nextLong(), x2 = in.nextLong(), k = in.nextLong();
     
            if (n <= 3) {
                out.println(1);
                return;
            }
     
            long d1 = Math.abs(x1 - x2);
            long d2 = Math.abs(n - d1);
            long d = Math.min(d1, d2);
     
            out.println(d + k);
    
  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yeah that's what I thought. Let me know if u find understand this bit

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Liked the problems a lot. Great contest

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hated the constraints in D, you can use O(nlogn) but not so much.

Also missed a very crucial case for C1 and C2, took very long to find. example: 1 99 3 0 1 2 I hate that I noticed the case where I could be getting the bug and proceeded to fix it incorrectly.

Lets not talk about A :(

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain me in question B if the distance is going to decrease if remelia moves either way then won't the answer be max(D1,D2)-2+k. In the case 4 1 3 1. In first move distance decreases by 2

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I thought the same, but look, Remilia is not forced to move every turn. "k" is the number of moves she may use, not the number of turns she must move. So, in your example, she stays there; seeing that, Reimu will move to either 2/4, and from there, Reimilia will move farther for k times, and finally will be caught after 3 seconds.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it only me to pass C by digit DP lol :(

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    could you tell your way?the way find the string close to array a is so tedious.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

does anyone has a more in depth explanation or tutorial of C1 & C2? or a visual explanation? I don't get how we got the longest common prefix of a and b when we still don't know what b is? or are we building b as we read the digits of a from the most significant digit to the least significant digit? In O(n log a) I assume the n part is iterating the digits of b? or a? and in log a is it a binary search? and what are we searching here exactly?

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yes , the longest common prefix is match a and b from high to low. b can longer or more less to the a,and use the min di or max di get two possible b.if a , b have the same length. we need to from high of a and find the char in d.it use log10 (a) times,log a is mean the digits of the a.and we can use the way of tutorial.the way means find all possible close numeber to a.and write a function to find the closest b.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

well I have a doubt regarding problem b in the case suppose if n = 4 and they are in opposite positions ex 1 and 3 and k is 2 so in the first step rameilia skips and reimu goes to 2 and then again rameilia goes to 4 and reimu goes to 3. time is 2 sec till now and in next second she will catch rameilia so ans is 3 in this case but according to k + min(n-abs(x-y),abs(x-y)) comes out to be 4 so am I wrong somewhere in my resoning please help me

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

it was impossible to get accepted on D in python :( nobody succeeded

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem C:

I know the thinking for greedy to solve it, but I really don't want to think. So I use binary search to solve it.

We could calc the k-th smallest digit we can constructe. So it's possible to find the two digit greater and less than a nearest.

However, if d[0] is $$$0$$$, things will become very troublesome. In the end, the competition was not resolved.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The problem C sucks.

»
6 months ago, hide # |
← Rev. 4  
Vote: I like it 0 Vote: I do not like it

My answer to Problem C1:

someone explain me more easy approach for this

Spoiler
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for Problem B If the two paths from Reimu to Remilia have the same length (i.e., the distance is exactly n/2 and n is even), then Remilia cannot make the shortest distance longer by moving. Her best move is actually to stay. So her k moves don't help at all, and the answer should just be that distance, not distance + k. Am I wrong? Thanks.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    if the both paths between them has same distance (leaving n=2 and n=3 cases), for that particular moment Remilia will stay but Reimu will move to any one of the two paths to catch her, then Remilia will shift again to make distance of both paths equal (she can do this k times). so eventually answer is k shifting + shortest distance between both (that is n/2 in this case for n even).

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thanks a lot! I was totally reading k as a time limit at first, but now it makes sense — it's the total moves she gets. Your example really cleared it up for me. Appreciate the help!

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In B

if diff1 and diff2 are same then why answer is not k + diff — 1

cause for 1st sec --> Remilia will not move

cause if she moves ---> new diff will become worse

so she wont move then --> diff--

then normal operations again !!

what did i missed then ???

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

SDSXC what is dep in your solution to F?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi, could you please elaborate on the O(n) solution for problem D?

I understand the O(n log n) idea, and I can imagine getting O(n) if we use counting sort because coordinates are in [1, n]. But I do not understand the intended O(n) observation from the editorial.

Specifically:

  1. What exactly are "the two groups determined by the smaller y-coordinate"?

  2. What does it mean that a valid dividing line must cross one of these groups?

  3. What point are we enumerating?

  4. What is the "appropriate pre-computation"? Which values should be precomputed?

  5. How do these precomputed values give the feasible vertical dividing position x?

  • »
    »
    6 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    You can implement this in O(n) with count sort but here is my idea to visualise better and has O(nlogn) complexity. Sort all the points based on their x co-ordinate. Now, imagine there is a set "Y" that contains all the y co-ordinates from the n points. Now, we iterate over all the points in sorted order and when we see that the current points' x co-ordinate is greater than the last one, that means, we can draw a vertical line between current and previous point.

    Vertical Line image

    Now, we will add the number of ways we can add a horizontal line for this vertical line to the answer. To calculate number of horizontal lines, we keep two multisets y1 and y2. y1 = multiset of y co-ordinate to the right of our vertical line y2 = multiset of y co-ordinate to the left of our vertical line Initially y2 = all y co-ordinates, y1 = empty When we move to points, we move its y co-ordinate from y2 to y1

    Now, for calculating number of horizontal lines, let's take a cut at y=a, then y1 will be divided into 2 parts, all points less than 'a' and all points greater than 'a'. Lets call these as left and right part of y1. Similarly for y2. We need to choose 'a' such that the left and right parts of y1 and y2 are not empty (to make sure that no quadrant is empty).

    Example: y1 = [1, 2, 5, 8], y2 = [3, 6, 7], Y = [1, 2, 3, 5, 6, 7, 8] In this example, we need to make cuts in Y. So if we make cut between 2 and 3 (a = 2.5), y2 will be cut such that its left part if empty ([] and [3, 6, 7]). If we make cut between 3 and 5, y1 cuts as [[1, 2] and [5, 8]] and y2 cuts like this [[3], [6, 7]]. basically element ≤ 3 will be in first part, and elements ≥ 5 will be in other part and we want both parts to have atleast one element to make sure all quadrants have some points In above example, the quadrants will have following y co-ordinates: 1st [1 and 2] 2nd [5 and 8] 3rd [3] 4th [6 and 7]

    Lets call e = max(min(y1), min(y2)) and f = min(max(y1), max(y2)). To achieve the above, we need to make cuts in Y between e and f. Let: pos[x] = position of x in set Y. Number of possible cuts = pos[f] — pos[e] We add this to answer.

    Here is my O(nlogn) submission: 374843238

  • »
    »
    5 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Bro, I solved this problem in O(n). But, I always try to understand and learn from editorial. And, guess what? I'm trying to understand Solution 2 from last 30 minutes but literally can't get a single word of this solution. I think, this is the most terrible solution of a problem I've ever seen.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For C1/C2, even the $$$10^{17}$$$ seems too much. In some cases, you need to take a number which has more digits than $$$a$$$, which leads the numbers go above the upper bound for long long. My solution passed after finally using __int128_t. This affected my score very badly. I got 10 unsuccessful submissions before realizing long long wasn't enough. For a Div. 2 C1/C2, requiring __int128_t just because of unexpected intermediate overflows feels incredibly misleading.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I also used __int128, but later realized that the only case when __int128 is needed is a = exactly 10^17 and only when trying to use b composed of 18 digits. However, if a = exactly 10^17, using 18 digits for b is never optimal, because, for example, using a 16 digits (or even 1 digit) b is clearly better. Thus, to avoid __int128, just handling "a = 10^17" separately (skipping 18 digits attempt) should be enough.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it only me or did C1 feel quite more difficult compared to other Div 2 contests?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C killed me... but please share code for C, I would love to see if there is a simpler way to code it.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is such an excellent contest! I love it(only except the problem D with a tight time limit).

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone explain to me in detail about the problem D im a bit of confused and didnt get clear about that :( TMT

»
6 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

I thought you were supposed to brute force c1? since per test case n=2 gives you about 2^17+2^18+2^19 operations. (brute forcing on the length of b, from a.size-1 to a.size+1. wasn't that the point?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

horrible to put such difficult to calculate in E,and meaningless to divide it E1,E2

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there code for juan_123's solution for Problem F? If so, please link me to it, can't find it in juan_123's submissions.

»
6 months ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

Is the "first solution" of F an intended solution? I was barely able to pass (2800ms) and that is with some optimizations. Edit: nvm optimizing to 1 log is trivial.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i struggled very hard to solve problems and i solved 5 out of 8. previously i got a rating of 744 now it became zero(unrated in my account) why i don't know.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Guys, I solved problem D in O(n) time complexity. 377025802. After that, I'm trying to understand the editorial of this problem. Solution 1 is very clear. But, I'm not getting anything of Solution 2. Can anyone explain Solution 2 properly?

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For B, if the distance between the two is n/2 exactly when n is even, then would it not be optimal for x2 to not move initially?

»
8 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone share digit dp sol for c