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

N29's blog

By N29, 13 months ago, In English

Hello, Codeforces!

I am very excited to invite you to our contest Codeforces Round 1054 (Div. 3), which starts on . You will be given 7 problems and 2 hours and 15 minutes to solve them.

The problems were authored by me and __rose and soullless to solve and alter them.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them)

  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

We would like to thank:

UPD : the editorial is out.

  • Vote: I like it
  • +264
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

first comment!!

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

Nagi proving once again that being a lazy genius is still genius enough for CF

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

__baozii__ really wants to Reach igm

»
13 months ago, hide # |
← Rev. 2  
Vote: I like it -56 Vote: I do not like it

.

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

As a blue tester, I am not a blue tester.

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

Codeforces x Bluelock?

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

As an orange tester, I am purple

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

Nice Image

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

^_^

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

100% goated round

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

Blue Lock mentionedddeddd!!!!! Goated round

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

As a tester, I encourage you to participate in the round. Nice problems.

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

GOATED ROUND BLUE LOCK MENTIONED

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

Anything the authors can do to help with the crawling bans during the hacking round would be greatly appreciated.

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

    And I've been banned for crawling...

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

      Why are you hacking problems if you're not participating in the contest? Maybe you should go outside, touch the grass, and breathe some fresh air?

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

        Why are you saying I wasn’t in the contest?

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

          Because it wasn't rated for you, why hack other people's solutions if you don't get points for them? It seems like you really have nothing better to do.

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

            A 12 hour hacking session is actually a great practice area to get better at hacking for div1/2 rounds. In those rounds, you are under time pressure, and there is a penalty for a failed hack. Are you suggesting I learn how to hack with my rating on the line and with bigger downsides, both in time to solve other problems + the negative points for a failed hack?

            In terms of the net effect on you from my activities, you would have been hacked anyway. My efforts simply notified you sooner of the outcome + you can see the full test case that specifically hacked your code. If you had TLE on the final test set instead (other people were also doing hashmap hacks), it would take much greater effort to figure out what that hack generating code was.

            It seems in general your concern is that you submitted code, it passed, and then it failed later. That possibility occurs because of the rules set up by codeforces, and this possibility is in all rounds (div1 through div4). My view on hacking rounds is the following: It's already a lot of work to create good problems, and hacking rounds lower the burden on problem authors for generating great contests.

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

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

Sorry if I'm missing something obvious, but can't seem to find how long the contest is. 2 hours? 2:15? 3:00 (unlikely)?

»
13 months ago, hide # |
 
Vote: I like it -14 Vote: I do not like it

Me to div3 when i was a struggling cyan

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

As a participant,I'll do my best to solve all problems of this contest

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

As a participant, i hope to AK the round!

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

Hope to have a good contest

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

Hope to reach expert :)

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

Blue lock x codeforces?!

Can wait for Rin destroyer mode to destroy me (╯˘ -˘ )╯

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

fire!

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

I am doing this contest in the airport as my flight has been delayed. I hope my flight is delayed longer so that I can get more submits.

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

Wish to AC 4 questions

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

Codeforces is really fast and smooth today. How can you achieve this?

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

    It’s fast and smooth because we are there , monitoring every cheater, scaring them, and we built strong tests.

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

This was the weirdest contest I have done in my life. great work !!

very fun problems

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

I hope G isn't intended to be solved with randomization

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

    I solved G with random because of very simple realization, but I also believe that solution which uses kth-stat on the interval to get possible values, is able to get AC

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

      You can also overkill with MO's

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

      Really neat idea with kth statistics! 10 lines of implementation for online, generalizable, fast solution: 340616457

      And harder version as well: 340601606

      Works in $$$O(\frac{n}{k} \log(n))$$$ per query for getting all the numbers that appear at least $$$k$$$ times in the segment.

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

    my solution to problem G does not rely on randomization.

    solution

    edit: this got hacked, its correct but it's not good enough

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

    It can be solved using extended boyer moore's algorithm with segment tree.

    Hint 1
    Hint 2
    Hint 3
  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    i solve with randomiztion but got wa so i use boyer moore

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

G is not original, infact it has appeared on codeforces itself. 840D - Destiny

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

very nice contest, loved F. couldn't find how to optimize G.

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

Please tell me E was sliding window

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

    Correct

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

      Yes, but with a little trick, exactlyK(k, [l, r]) =
      countAtMost(k,r) -
      ( countAtMost(k,l−1)+(countAtMost(k−1,r)+countAtMost(k−1,l−1)) )

      where, countAtMost(k,x): answer of k distinct element and length at most x

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

how to solve F?

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

Fantastic round. Njoyed D a lot:)

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

nice balanced round !! Appreciate it

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

Is G solvable with Mo's algorithm? I can't eliminate the O(logN) part when updating.

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

My thought process for $$$F$$$ was as follows:

  • the final $$$ans$$$ can be written as $$$d + x$$$ where $$$x$$$ is the number of turns spent in rest.
  • we know the sum of natural numbers series for $$$i = 0, 1, 2, 3, 4, ...$$$ is $$$0, 1, 3, 6, 10, ...$$$
  • for a fixed value of $$$x$$$, we want to choose atmost $$$x + 1$$$ indices $$$i$$$ such that $$$i_1 + i_2 + \dots + i_{x+1} = d$$$ and $$$\frac{i_1(i_1+1)}{2} + \frac{i_2(i_2+1)}{2} + \dots + \frac{i_{x+1}(i_{x+1}+1)}{2} \lt h + x$$$
  • the range for $$$x$$$ is $$$0 \le x \le 10^9$$$ ($$$x = 10^9$$$ when $$$d = 10^9$$$ and $$$h = 2$$$) (is this range correct?)

  • and we can binary search over this range and find the minimum value of $$$x$$$, but how to check the condition?

Is my approach even remotely correct lol?

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

    your idea is correct

    let $$$d = p \cdot (x+1) + q$$$ $$$(q \lt x + 1)$$$ then we can prove that an optimal answer for the problem is $$$i_1 = ... = i_q = p + 1, i_{q+1} = ... = i_{x+1} = p$$$ using exchange argument, which we can calculate in $$$O(1)$$$

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

      As I passed the problem just now with your construction,will you mind being pointed out a mistake that for $$$ i_1 $$$ to $$$ i_q $$$, they shoule be $$$ p + 1 $$$ ,and for other $$$ i $$$,they should be $$$ p $$$.

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

      What is exchange argument ?

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

        It's like a method of proving by exchanging some arguments

        For example: in this problem if there exist $$$a, b$$$ such that $$$i_a - i_b \ge 2$$$ then we can prove that if we make $$$i_a := i_a - 1, i_b := i_b + 1$$$ then the value that we need to check is smaller. So we know that the optimal solution guarantees that $$$|i_a - i_b| \le 1$$$ which is only true when array $$$i$$$ is a permutation of what i've said

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

    Yes,i have same idea but I used x-1 not x ,and then you can make bin-search on x,because best I values are d/x and d%x values +1 this can be calculated in O(1). My approach : 340527265

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

    Thanks for posting , I liked the mathematical thought process

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

      You're welcome :) It still hurts that I was this close to solving the problem but I couldn't get the trivial solution of $$$p$$$ and $$$p + 1$$$ :(

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

        yeah , I am also pondering about how to think these things during contest.

        but good reveal of patterns and maths

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

Is E need persistent segment tree or it is simpler than this ?

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

ts was ass icl

not only was there a complete lack of problem solving in this contest up to including e (probably later problems as well if i had to guess)

half of these were knowledge checks or leetcode ah problems

when its very obvious how to solve the problem, and it takes the entire later part of the contest to implement... hint hint, probably not a fun problem, we use this site for problem solving, go set on leetcode if you think these are good tasks

oh and a side effect of it being very standard!!!!!! a lot of indians will be solving it! theyre very good at standard implementations huh?????

anyways tldr: tspmosmicl

update: I was doing binsearch on BIT for e, turns out spamming pdbs is easier, but my argument about it being too standard still stands.

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

    E was a 1 line modification of this and just f(k) — f(k-1). Usually I am very good at leetcode style problems, but I did this on D so I am losing 60 yippee

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

Overall great contest

»
13 months ago, hide # |
← Rev. 2  
Vote: I like it +21 Vote: I do not like it

For the problem G, WHY NO -1 IN THE SAMPLE CASE ??????????????????????????????????????????????????????????????????????????????????????????????????????

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

    I believe the reason behind this is to not confuse answers for different queries with each other, in case you suggest to output nothing if there is no suitable values

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

    I got a wrong answer because of it and the sorting It would have been more convenient if they have used a custom checker.

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

GPT passed G with Mo's Aglo. Link

Can someone check if its hackable or not?

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

At first I thought, “Wow, the Kazakhs organized a contest, the problems must be great.” While participating, I found problems A–C quite good, but the rest felt kind of strange. On top of that, with AI one could easily AK this contest.

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

    Every div 3 is AKable with AI tho?

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

    Can you please provide a hint to solve D?

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

      Calculate for a and b. Take the minimum.you have to take the median of a for the lowest cost of consecutive a and same for b. And at last just compare and print the minimum cost. If n<=2 then it will always be 0 and if a or b is already consecutive then it will be zero.

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

I solved A-E in around 45 minutes, official ranking was 300, and then so many people solved F and G using LLM and I dropped to 1300. (A problem similar to G already exist on CF and is rated 2500 but there is no way low rated people knew it).

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

    F was standard binary search , the solve rate does not seem too high. (Not sure — I was not in the contest)

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

I think the time limit is so tight, here 340510152 I was compressing the array using a set and a map but it didn't pass. But when I compressed using sort and binary search instead it passed. 340511269 I understant that it should be a bit faster but they are still the same time complexity O(n * log n).

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

can anyone hack my cheese in D? I only find the "stick spot" around the average index +- 100

340513009

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

I noticed that today’s Div. 3 Problem G feels very similar to 840D — Destiny . I know Codeforces usually avoids repeating problems, so I was a bit surprised. It doesn’t seem entirely fair, since people who have already solved 840D might have an advantage in today’s contest.

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

    But that is a 2500 problem. If a rated Div3 participant has already solved that problem; I think he / she deserves that advantage..

    Anyways, I agree with your point that the statement was also same (just k was restricted to 3) and we had to get all elements (at most 2) rather than the minimum element and the setters could make it a bit indirect inspiration from problem 840D.

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

Can someone explain that why we should calculate the operations from median on question D?

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

    to minimize the cost. If we take the middle one then the left ones and right ones will give the lowest cost by swapping. If we take any random a or b then the opposite side will not give the lowest cost that's why median is the answer.

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

    The answer can be calculated by accumulating the elements to a particular position i. For such a i, if it moves one position to the right, the answer will increase by rcnt — lcnt, where lcnt represents the elements with positions less than or equal to the i, and rcnt represents the elements with positions greater than the current position. Then for any i, moving towards the median position, the answer must be decreasing, so we have to consider the median.

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

DEEPWOKEN MENTIONED

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

A lot of newbies in top 100 .They literally are not letting us to know our real level !!

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

is f greedily make as many consecutive moves as possible and restore 1 hp if needed?

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

Proud to present screencast again

About the channel
»
13 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Crazy E . Felt like dp problem looking at first

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

__rose and soulless, there are some unexpected verdicts on problem G that need to be resolved. Thanks

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

Should we use lambda function in questions involving mo's algo

as it is very common to create insert , remove function in lambda , however such problems are usually along with high constraints and lambda function have additional overhead as compared to normal functions declared globally

so should we adapt y-combinater

, so is the risk valid?

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

Tutorial when ? Really interest about last problem -> majority elements for multiple query !!

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

    I made $$$O(n \sqrt{n} \log{n})$$$ pass with this Mo's order, lol.

    std::sort(queries.begin(), queries.end(), [&](const query &x, const query &y) {
      int bx = x.l / b, by = y.l / b;
      if (bx != by) {
        return bx < by;
      }
      if (!(bx & 1)) {
        return x.r < y.r;
      }
      return x.r > y.r;
    });
    

    4.1s (very close to 4.5s) but it counts :D

    But to 'really' solve this, I'd suspect you'd use something like random sampling ($$$1/3$$$ probability per attempt) coupled with the fact that there can only be $$$2$$$ elements to maybe get $$$\log^2$$$ per query.

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

      $$$O(\log{n})$$$ per query is possible, using segment tree that keeps the top elements.

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

        How would you combine nodes efficiently? As far as I know, there's always been problems with segment trees when you try to combine for any case $$$ \gt \frac{r-l}{2}$$$. Maybe a merge sort tree would work (to update counts on merge) but otherwise I'm not sure how you'd use a segment tree.

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

Got stuck on F for 1.5 hours during the contest and another 2 hours after it. Then carefully translated the problem on paper into another one: find min(k) such that there exists a set of natural numbers xi with x1+…+xk = d and h+k-1 > Σ(xi(xi+1)/2). Output d+k-1. The last approach took 20 minutes and no need to debug. Submission

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

Nice Div But it was full of CHEATERS --_--

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

People are still hacking using Python hash collisions. Didn't we agree to stop that already?

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

More Blue lock themed Questions!!!!!

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

16 times submit on problem G. What's a nightmare :(

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

please quick editorial otherwise problem C will haunt me for days

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

For people who solved G using randomized algorithm, what is the lower bound on the number of indices you search per query and is there any way to derive it for a specific n?

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

    Let's assume the worst-case: r-l+1 = 2 mod 3, and there are 2 numbers which occur (r-l+2)/3 times. The probablity of not getting a correct answer with k iterations is approximately (2/3)^k*2, let's denote it as p. We can choose k to be 50 to make this probability roughly 3*10^(-9). Since we didn't use n in our calculations, there are no bounds on n. k that we choose depends on the total number of queries. Math. expectation of the number of queries needed to get the first wrong answer is 1/p and we want it to be much more than the total number of queries.

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

Codeforces Round 1054 (Div. 3) , this was my first contest in this platform , I registered for it beforehand but it is showing as an unrated contest , I did not get any rating from this contest. Can anyone explain me why ?

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

    After the open hacking phase, all submissions are rejudged with the tests submitted as hacks. After that you will get your rating. This process takes some time for Div. 3 competitions.

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

It seems that problem G can be simply solved by Mo's Algorithm without thinking.

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

Can someone please check why my solution for D is wrong?

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define mod 1000000007

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int op1 = 0;
    int op2 = 0;
    
    int l = 0;
    int r = n-1;
    while(l<n && s[l] == 'a')
    {
        l++;
    }
    while(r >= 0 && s[r] == 'a')
    {
        r--;
    }
    for(int i=l; i<=r; ++i)
    {
        if(s[i] == 'a')
        {
            if(i-l > r-i)
            {
                op1 += r-i;
                r--;
            }
            else
            {
                op1 += i-l;
                l++;
            }
        }
    }
    l = 0;
    r = n-1;
    while(l < n && s[l] == 'b')
    {
        l++;
    }
    while(r>= 0 && s[r] == 'b')
    {
        r--;
    }
    for(int i=l; i<=r; ++i)
    {
        if(s[i] == 'b')
        {
            if(i-l > r-i)
            {
                op2 += r-i;
                r--;
            }
            else
            {
                op2 += i-l;
                l++;
            }
        }
    }
  
    cout<<min(op1,op2)<<endl;
}


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

this my code

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

    for the string "baabbabb", your code is giving answer as 3, but the correct answer is 2 (swap 'a' at index 5 two times with b).

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

Whoa!! A round that wasn't tested by __baozii__

Great problems either way, tho I couldn't participate

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

When the editorial will be released ?

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

Hello, my handle is ShashS02. I am a new user and I participated in this round. I registered more than 24 hours before the contest started, but my participation was marked as unofficial and I did not receive a rating. Could you please look into this? Thank you.

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

The questions are interesting (and relatively simple; I like this round),but I need the editorial TAT

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

After a long time a proper div 3 contest, problems were balanced according to div 3 and also I achieved expert :)

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

thanks for this wonderful round!

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

Yay im specialist now

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

Hii can anyone help me here, Why is my solution to Problem C giving TLE on 7th test case Submission Details

t = int(input())
for _ in range(t):
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    if k == 0:
        print(a.count(0))
    else:
        curr = a.count(k)
        seta = set()
        for i in a:
            if i < k:
                seta.add(i)
        required = k
        available = len(seta)
        print(max(curr, required - available))

According to my understanding this is still O(n) or max O(nlogn) I'm all ears, It's been a while since i started CP again, maybe I'm missing something Thank you in advance

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

    You would normally be correct that this should be O(n) average time complexity; and the sum of all n is 2*10^5 so this should pass. However, since you are using python, you should know that sets in python are unordered, which means they have O(1) insert on average but O(n) worst case; in the very worst case your code takes O(n^2) to run after inserting n elements each in O(n) time.

    This is opposed to c++'s set which is ordered (and does doesn't fall to this issue but instead runs in O(n log n)). The alternative solution to this problem that works in python would've been instead to not use a set to check if an element is present but use a frequency array; a list that counts how many times a number has been seen (e.g. a list named frequency has frequency[2] count how many times 2 has been seen among all numbers in the input).

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

      Alternatively, see https://codeforces.me/blog/entry/101817 for how to make set not immediately break on standard test cases; to put it simply using this class makes it so set becomes much harder to force into the O(n^2) worst case and instead your performance becomes closer to the O(n) average case.

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

Ain't using unordered_map anymore....F hash collisions :)

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

well done, good contest. but i can't understand problem G till now, what a dispiriting problem.

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

340744591 why is my solution wrong cant think of a test case where this would go wrong please lmk o/w

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

I have received a notification that my submission for problem 2149E (https://codeforces.me/contest/2149/submission/340450859) has been flagged for similarity. I would like to clarify that this is a misunderstanding.

This problem is essentially a standard sliding window (two pointers) template problem. There is a very similar problem on LeetCode with the same core idea:

https://leetcode.cn/problems/subarrays-with-k-different-integers/

The solution approach is well-known and widely shared in public resources long before this contest. Many participants likely used the same standard technique independently.

I confirm that I did not share my code with anyone, nor did I view or copy anyone else's code during the contest. The similarity arises solely from the fact that this is a classical algorithmic pattern with a natural and common implementation.

I kindly request a re-evaluation of this case. Thank you for your understanding and fair judgment.

»
13 months ago, hide # |
 
Vote: I like it -12 Vote: I do not like it

Hello Codeforces, I have received a notification that my submission for problem 2149E (https://codeforces.me/contest/2149/submission/340465979) has been flagged.

The question is basically the most commonly found pattern questions based on the sliding window, which can be found on leetcode. So since I am used to this pattern, implementation in the way that I had done, was the most intuitive, and I was used to it. The following are the leetcode questions: https://leetcode.com/problems/subarrays-with-k-different-integers/description/ https://leetcode.com/problems/binary-subarrays-with-sum/description/ https://leetcode.com/problems/count-number-of-nice-subarrays/description/ https://leetcode.com/problems/number-of-subarrays-with-and-value-of-k/description/ and many more Basically, the technique of using sliding window, but for finding at most k, and then at most k-1 and then subtracting to get exactly k. This algorithm is pretty common, so similarity is based upon mere coincidences, and re-evaluation should be done to give a fair judgment.

I ensure that I have never copied or used any unfair means to write any code. The similarity is all because of its too basic, standard algorithmic nature.

I kindly request you to re-evaluate and give a suitable judgment regarding the same

Thanking you, Solandra

»
13 months ago, hide # |
← Rev. 4  
Vote: I like it -8 Vote: I do not like it

Hello Codeforces team, During the contest I submitted three different solutions. Two of them got Wrong Answer and only the last one was accepted, which shows that I was trying to solve the problem myself.

First submission (WA): [https://codeforces.me/contest/2149/submission/340427928]

Second submission (WA): [https://codeforces.me/contest/2149/submission/340477792]

Final submission (Accepted): [https://codeforces.me/contest/2149/submission/340479653]

I kindly ask you to understand my situation and review my case. Thank you.

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

    Obvious AI

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

      Hello,

      I usually work on one file and when I move from one problem to another, I just delete the old code and write the new one. For this problem, I submitted three times.

      In my second submission I handled freq[k] with a separate +1 condition, which was not correct, because it could overcount or undercount depending on the test case. In the final submission I fixed this by using ans = max(missing, freq[k]), which correctly balances between the missing numbers below k and the occurrences of k. That’s why the third submission was accepted. Best regards, Mohamed

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

Subject: Appeal re plagiarism flag — submission [340485399] for [Problem 2149E] Dear Codeforces team and round coordinators, An automated message was sent to me that my submission [34048539] for [2149E] has considerable concordance with submissions with the IDs (beardly/340475079, Skylight_ 422/340481158, IamKeviN69/340481986, Vimlendu2003/340485399, AdelO_mcc/340502599), although one of the Id among them is mine itself as Vimlendu2003, cited in the notice. I would like to put forth an explanation and request some leniency on blocking my account. The problem was solved by me in the actual contest. While testing on an online compiler/paste service, I accidentally left my code public. Now, I do realize that this was a violation because code exposure can lead to a sudden presence in the realm of other contestants. So to be clear: I never intended to share the code with anyone, nor was it handed over to me by anyone. This was my slip-up, and I take full responsibility for the accidental leakage. The following measures have been adopted in order to ensure that such an incident never occurs again: 1. I will not be using any paste/online judge service for contest code. 2. My tools have been set by me for only private/local testing by default; 3. I have gone through the Codeforces rules (blog entry 8790) for a better understanding. I accept fully any penalties given by the jury in accordance with the rules (e.g., disqualification of submission/rating rollback), and I respectfully request that my account not be blocked as the action was unintentional and the cause has been eliminated. Codeforces means much to me, and I want to stay fair and continue learning in future rounds.

Thank you for your time and consideration.

Vimlendu Sharma/Vimlendu2003