Serval's blog

By Serval, 13 months ago, In English

Hi Codeforces!

I Serval am glad to invite everyone to participate in Codeforces Round 1011 (Div. 2), which will be held on Mar/22/2025 17:35 (Moscow time).

This round will be rated for participants with rating lower than 2100. We will be glad to see the participants with a higher rating to take part in our round unofficially as well!

You will be given 6 problems to solve in 2 hours, one of which will be divided into two subtasks. Scoring distribution will be announced later.

I would like to thank everyone that makes this round possible:

Good luck & Have fun! (∠・ω < )⌒☆

UPD: Scoring distribution: 500 — 1250 — 1250 — 1750 — 2500 — (2000 + 1000).

UPD2: Editorial is out. Congratulations to the winners!

Div. 2:

  1. sounansya
    DuyNgaDocTon1410 Disqualified.
  2. SoloRE
  3. nocap
  4. Asbjorn
  5. AksLolCoding

Div. 1 + Div. 2:

  1. potato167
  2. A_G
  3. arvindf232
  4. antontrygubO_o
  5. TKT_YI
  • Vote: I like it
  • +383
  • Vote: I do not like it

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

As a coordinator, I was playing Genshin with the author!

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

As a tester, I think Serval is a cool character in Star Rail

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

Here comes :

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

[deleted]

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

As a participant, I recommend all of you to watch Kemono Friends. (BUT NO ONE SHALL WATCH SEASON 2!!!)

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

;gimme 1603

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

How to be a tester ?

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

I wish we could have a

^-^

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

add this blog to the home page?

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

As a tester, I'm too late...

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

As a tester serval is a super cool character who displays indirect buffing so well. After the introduction of the herta serval skyrocketed into a meta sub dps due to driving her super so well when using s5 passkey. But she'll probs fall off again like every good 4 star like gallagher or Moze

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

WOW~~~~~~~~~

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

as somebody who was supposed to test, my pc still isnt fixed and im writing this from my phone :(

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

As an 8-year-old girl, Hope to solve two problems in my first codeforces round.

UPD: I do it!

»
13 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it
Some lyrics you might want to enjoy with this round
»
13 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

First contest I take this month, hopefully reach master

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

I hope the problems are not a pile of crap.

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

aiming for the blue color...

hope that it will be a good round for everyone... && hope that cheaters will not participate in this contest..

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

Why is this round special?

Spoiler

sorry sorry! I forgot..! tnx!

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

I wish this round is good and we all can reach high rating.

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

Good luck & Have fun! (∠・ω < )⌒☆

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

As a tester, I enjoyed the problems more than the bananas

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

There will, and there shall be a Serval round!

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

Good luck have fun everyone.

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

I hope it goes well.

»
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

I'm like very new, so how does a contest work?

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

    Note that the contests vary in difficulty. It can be Div.1, Div.1+2, Div.2, Div.3, Div.4, where Div.1 is the most difficult and Div.4 is the easiest. Normally Div.3 and Div.4 are for school pupils, Div.2 for university students and Div.1 for pros. Actually, you can participate in any.

    Practice with the problems from previous contests, register for the contest, prepare mentally for a sprint, start in time and do your best!

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

As a tester, I think the problems are very Serval.

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

Is there some specific reason the email announcement for this contest did not mention Rust in the list of accepted languages?

Допустимые языки C/C++, Pascal, Perl, Java, C#, Python (2 и 3), Ruby, PHP, Haskell, Scala, OCaml, Go, D, JavaScript и Kotlin.

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

    [off-topic] you are so nice man. you been 1600 rated by 4 contest nice. What's your first account? or it is first?

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

    Answering to myself: it was actually available during the contest, so likely just an error?..

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

GLHF everyone except cheaters!

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

Here's an image of the standings after 1 hour. Anyone can see a pattern here

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

Solved C in 5 minutes and then staring at D, i hate these speedforces.

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

after long time I made all questions (A -D) with logic and not much guesswork .. finger crossed for system test

unfortunately I made wrong submission for div2B .. indices should be with respect new array LOL...

hello "expert" my old friend / rank

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

how to solve C ?_?

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

    WLOG, let x < y. Then, add to x and y such that x only has a single bit. Then, if x and y still share a bit, do the same thing to y. You can easily enough see that x and y will not share bits after this due to x < y in the first place.

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

      can you show your code

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

        Since the range of x and y is $$$10^9$$$, and the range of k is $$$10^{18}$$$, we can always find a k such that max(x,y)+k is a power of 2.

        void solve() {
            i64 x, y;
            cin >> x >> y;
            if (x == y) {
                cout << -1 << '\n';
                return;
            }
            if (x < y) swap(x, y);
            i64 t = 0;
            for (int i = 1; t < x; i++) {
                t = 1LL << i;
            }
            cout << t - x << '\n';
        }
        
  • »
    »
    13 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +20 Vote: I do not like it

    Well, first if $$$x = y$$$, there is no answer, clearly.

    Otherwise, let's say $$$x \gt y$$$ (if not, we can swap), you want to make $$$(x + k) & (y + k) = 0$$$, which gives an idea of making $$$x + k$$$ having one set bit, which is $$$2^p$$$ ($$$2^p \ge x$$$). When we have $$$x + k = 2^p$$$, $$$y + k$$$ cannot reach $$$2^p$$$ since $$$x \gt y$$$, so they won't have common set bit.

    So result is $$$2^p - x$$$.

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

    2^30 — max(x, y)

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

      it will make the larger number something like 100...0000 (1 followed by many zeros). Xor of any number(y + k) will always be the sum of this number and y+k, since there will be no carries involved.

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

what is the general idea for solving c

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

    Make the maximum number power of 2 and if number same then -1

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

    One of xor identity: x + y = x^ y when there's no bit of x and y are equals.

    So you need to find a k to flood max(x,y) to 1 bit to the msb(most-significant-bit) only, the lesser number cannot reach there and there you have it.

    the formular:

    k = (1 << bit_width) - max(x, y)
    

    I accidentally AC, then realized this after AC rofl.

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

C was too difficult for me..

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

speedrun through ABC but stair at D and F1 till the end of contest.

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

lol, the terrible C did not allow to solve the interesting E and F1. Why do we have to play guessing games all the time?

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

how to F1

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

I really hate problem of kind C if you know the 'gimmick' a + b = (a & b) << 1 + a ^ b then it's free otherwise you are screwed

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

    I find the fact a + b = a ^ b <=> a & b = 0 pretty obvious, if you just observe the bitmasks.

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

    Well now in future problems u'll know, as it is pretty standard result used in multiple problems.

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

    First, it is well known; Secondly, it is not hard to observe that $$$(a+b)=(a\oplus b)\Leftrightarrow a\operatorname{\&}b = 0$$$. You just need to look at the binary representation.

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

    I didn't know that beforehand, derived it mid-contest

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

Please explain C in simple and step by step how to solve. Thanks in advance for your help....

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

    the easiest way to understand is to try and add two numbers by hand in binary, then try to xor them in binary. What you'll find is xor will equal addition if there is no "carrying" of the bit.

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

    note that a+b=(a&b)<<1+(a^b) so now you know that (x+k)&(y+k) must be 0 note that if x!=y one is larger, so if you add diff between larger one and 1<<(msb+1) to both of them, one will have all 0s in the original places and one in the larger place, other wont have that 1 in the larger place, meaning & of the two is 0, meaning its euqal a+b to a^b

    gg

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

    $$$2^{50}-\max(x,y)$$$

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

    use 'well known' equality a + b = (a & b) << 1 + a ^ b

    then you will find (x + k) + (y + k) = (x + k) ^ (y + k) iff (x + k) & (y + k) = 0

    wlog let x < y, let X = x + k, and d = y — x. then X & (X + d) = 0. then it's fairly easy to find X

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

I stuck at D by thinking about dp, nooo

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

Fun Contest! Thank you for the problems.

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

How to solve D ? Can we use dp ?

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

    We can use priority queue.

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

    Let's go backwards. If at some suffix you know what's the best you can do, then when you add another plate at the start, there are some choices:

    • Take it, if there's enough time to finish it in the future

    • If it can't be just taken, and before you took a plate with lower value, then you can switch them and improve the answer

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

      I did the same, I was very happy that I didn't miss any corner cases as well.

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

      I may be stupid but I don't understand why d[i] + extendable_suboptimal_solution_for_suffix can't be better than d[i] + best_solution_for_suffix — smallest_val_in_best_solution in case when we can't extend the best solution for suffix

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

        By definition, every extendable suboptimal solution can be extended to make it not extendable, and let’s say, it is extended in the best way. From that non-extendable solution, the best we can do is switch the current value by the smallest in the solution. And as the current solution is the best of that kind, then it is optimal to stay with it and make the possible changes

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

          I was confused about the case when it's extentable with the current element and isn't with any element to the right, but I think I got it now.

          It probably should be intuitive, it's totally not for me, but I did some math and found out that in this case the extended suffix will contain the maximum possible number of plates. And I spent some time understanding that the best solution for suffix should also contain this number of plates because it can't be extended(again, it wasn't intuitive for me that a good solution can always be extended if the number of plates in resulting solution won't be greater than the maximum for the extended suffix(I thought it may become bad after extending), so if a good solution can't be extended it should contain this maximum number of plates to "overflow" after extending, it's the only way it can become bad). And as the number of plates is equal the modified best solution is obviously better.

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

D was a cute problem.

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

Can anyone hack my submission for E?
It's basically just bruteforcing over all possible k(found from using the max of a and the differences with the elements of b), but pruning the amount of k with some optimizations.
I got a sum total of 8 WA by being stupid and not realizing I wrote it wrong :(

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

Interesting problems, really brainstorm. I like it and it let me become CM:))

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

Can anyone share solution to F2?

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

How does E work?

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

    yeah me too waiting for editorial for this.

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

      If $$$b$$$ is a permutation of $$$a$$$, then any number larger than $$$max(a)$$$ is OK.

      If $$$sum(b) \gt sum(a)$$$, the answer is $$$-1$$$.

      Otherwise, calculate $$$d = sum(b) - sum(a)$$$, $$$k$$$ must be a factor of $$$d$$$.

      Enumerate each factor of $$$d$$$ and test if it satisfies, with 2 optimizations:

      (1) $$$k$$$ is larger than $$$max(b)$$$; (2) If $$$k_0$$$ is not the answer, the multiples of $$$k_0$$$ is not, either.

      If no such $$$k$$$ exists, the answer is $$$-1$$$.

      my solution

      UPD: My solution was too complicated when calculating the factors of $$$d$$$. x_x

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

        oh thank you for sharing your thoughts.. I will try to understand this tomorrow and try to upsolve E

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

    Let's assume that array b is arranged correctly. This means that a[i]=k*q+b[i], where q is some non-negative number; This means that sum of a is equal to k*m + sum of b. So if we substract sum of a from sum b, we get some number that is divisible by k. So K is one of the divisors of (sum a — sum b)

    You can just iterate over each of the divisors of (sum a — sum b) and check if any of divisors can get you an array which is equal to b.

    Note that you can reduce the number of divisors that you have to iterate through, because k is greater than maximum of b (a % k < k) and a%k=a, if k > a, so k is less than maximum of a, if array a is not equal to b, or k is just any number bigger than maximum of a, if a is equal to b.

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

Fun fact: I Wrong answer on pretest 2 on B for 4 times, and the time I used to solve B is equal to the time I used to solve D + the time I used to solve E.

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

    whoa you solved E . please share the idea behind E

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

      $$$\sum a = \sum b$$$, so $$$\sum a \bmod k = \sum b \bmod k$$$, $$$\sum a - \sum b \equiv1\pmod{k}$$$. So just try every factor of $$$k$$$ and check if it's correct.

      By the way, if $$$\sum a \lt \sum b$$$, then it has no solution. If $$$\sum a = \sum b$$$, then just pretend $$$k = 10^7$$$ and check if it works.

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

A nice contest!

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

very fun and interesting round i loved b and c in particular, codeforces just doesn't get better than this

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

311834563

First time I'm commenting something, so my bad in case of any mistake.

I don't know why my code is giving WA on problem A. I tried to think of test cases which may be the issue but I failed to come up with that. After contest to check the failed test case, it was 353rd token on pretest 2, so I couldn't read that. Just as a last resort, I tried AI to understand the flaw in my code but that didn't work either.

Thanks in advance, for any reply/help

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

    try this case, although I didn't see your whole solution .. this caught my eye quickly

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

    it was 353rd token on pretest 2, so I couldn't read that

    You can actually

    just add this in your code
    and you can see failing case in checker log like this
»
13 months ago, hide # |
Rev. 4  
Vote: I like it +3 Vote: I do not like it

Could anyone prove the time complexity of my solution for E or hack it?

Here are two versions of it: 311889161 and 311897982. The only difference of them is explained in bold.

  • Sort both $$$a$$$ and $$$b$$$.
  • Check if any $$$a[i] \gt b[i]$$$ exists. In that case, the answer is $$$-1$$$, because $$$a[i] \mod k$$$ can only be smaller than $$$a[i]$$$ but not any larger.
  • Eliminate the longest prefix of $$$a$$$ and $$$b$$$ where they're equal to each other. If this is the entire array, then $$$k=10^9$$$ is sufficient.
  • Set $$$mx$$$ as the largest element of $$$b$$$.
  • Let $$$x$$$ be the smallest element of $$$b$$$. Subtract $$$x$$$ from all elements of $$$a$$$ and $$$b$$$.
  • Now we know that there is at least one element where $$$b[i]=0$$$, so we only need to test every $$$k$$$ where $$$k$$$ is a divisor of at least one element of $$$a$$$. So, make a set of divisors of all elements of $$$a$$$.
  • Make a counting array of all elements of $$$b$$$.
  • Now for every element of the set that is greater than $$$mx$$$ (because if $$$k \lt =mx$$$, then all elements of $$$a$$$ will be less than $$$mx$$$ when $$$\mod k$$$), make another counting array that counts $$$a[i] \mod k$$$. While making this array, if any counter exceeds the same element of $$$b$$$'s counting array, break the loop. If the counting arrays match, $$$k$$$ can be the answer. If none of them satisfies it, the answer is $$$-1$$$.

Without breaking the loop, the time complexity will be $$$\mathcal{O}((\text{distinct number of divisors of a)} \times n)$$$, which should have a far greater number of inner loop iterations than just $$$n^2$$$, but 311897146 this submission shows that it didn't even run $$$5$$$ million times on any of the tests due to the break.

The version that does not break the loop still passes in $$$531$$$ ms, but it's certainly because of the tests being weak, since I was able to make a test that makes the loop run $$$\sim 322$$$ million times, although it still wasn't enough to be hacked and it passed in $$$1671$$$ ms. Could anyone hack this version, at least?

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

I found problem C a lot harder than problem D. I ended up solving it with dynamic programming to find the minimal value of $$$k$$$.

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

Is top 2 of today div 2 abusing AI to cheat in this contest?

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

    Well, if you see the tutorial, you will see that there exists a much easier for F2 than just going for DS bash. I hope you will like the linear solution.

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

Enjoyed the contest mostly because it was more on thinking about the problem rather than just being some derivation of some standard problems.

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

I'm stupid. Can anyone point out the bug? It passes the first test and fails on the 88th of the 2nd pretests.

https://mirror.codeforces.com/contest/2085/submission/311931598

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

    my bad

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

      That's alright. I'm quite new to this. And this was my first contest. I couldn't figure out a counter example to my logic

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

        now it should be right

        1

        6 1

        bbabba

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

          ahh thanks man. solved it. DAMN I WAS THIS CLOSE! Will do better next time hopefully

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

            np and I recommend to check the editorial for simpler solution

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

              Yes i did check it. But i just wanted to make sure that my solution was valid or not. Thanks

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

                I gave you my While loop handling — ~~~~~ while (t--) { int n, k; cin >> n >> k; string s; cin >> s;

                // If the string has only one character, it's not universal
                    if (n == 1) {
                        cout << "NO\n";
                        continue;
                    }
                
                    // If all characters are the same, it cannot be universal
                    if (count(s.begin(), s.end(), s[0]) == n) {
                        cout << "NO\n";
                        continue;
                    }
                
                    // If already universal, print YES
                    if (isUniversal(s)) {
                        cout << "YES\n";
                        continue;
                    }
                
                    // If at least one swap is allowed, we can make it universal
                    cout << (k >= 1 ? "YES\n" : "NO\n");
                }

                ~~~~~

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

                  i managed to solve it after the person above gave me a counter example to my solution. Thank you for taking ur time to help me out

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

Just curious

For Div 2B the constraints were n <= 5000

was it becuase of implementing the checker or simply to confuse Serval

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

    The checker runs in $$$O(n^2)$$$ because of the array manipulations in each operation. An $$$O(n^{1+\varepsilon})$$$ checker needs some DS to optimize it. Leave it as homework. :)

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

Top 5 lets go!