reirugan's blog

By reirugan, 11 months ago, In English

I hope you all enjoyed the contest!

Rating Predictions
Rate the contest!

A — Blackboard Game

Solution
Rate the problem!

B — Tournament

Solution
Rate the problem!

C — Prefix Min and Suffix Max

Solution
Rate the problem!

D — Binary String Battle

Solution
Rate the problem!

E — MEX Count

Solution
Rate the problem!

F — Minimize Fixed Points

Solution
Rate the problem!

G — Modular Sorting

Solution
Rate the problem!
  • Vote: I like it
  • +292
  • Vote: I do not like it

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

Pen,Paperforces round

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

Bro dropped the editorial at the speed of light. Very refreshing contest btw!!

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

Fun fact: As a tester, testing for this contest was stopped once due to me.

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

    Context for those who are curious: it turned out one of my problems was, up to a cosmetic rewording, a duplicate of a past ARC problem. beaten_by_ai luckily remembered the problem and it was removed.

    https://atcoder.jp/contests/arc147/tasks/arc147_e

    Initially, MEX Count was D (with a subtask to solve for one $$$k$$$) and Minimize Fixed Points was E, with the AtCoder problem placed at F. After it was removed, DE were moved to EF and Binary String Battle was added.

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

      ahaa, thats why F is a bit easy i believe??

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

      Note that the original problem is rated approx. $$$\color{orange}{2476}$$$, which roughly corresponds to $$$\color{red}{2585}$$$ in CodeForces. Therefore, we could have witnessed the hardest div3F in the history.

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

Thank you for the contest and the fast editorial!!!

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

assert(number_theory == magic);

»
11 months ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

editorial drops faster than brainrot memes hitting my youtube page

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

It was a weird contest for me. Took me 30+ minutes to solve A but about 15 total for both C and D :)

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

Am I the only one who got stuck on D and solved E? Very nice contest by the way, kudos

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

so fast tutorial. great work

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

problems were really interesting thank you for the great round!

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

This is the best div3 E i've ever seen

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

What could be the expected rating of the problems? ig A-B-C seems like a standard 900,1100, and 1200 rated. D was tricky but code is short so it can't be thought of more than 1400. E probably felt like 1500-1600. I don't know about F and G tho. What do you guys think?

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

    A: 800 B: 800 C: 800 D: 1200 E: 1400 F: 1600 G: 2000

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

    For A and B, I think they are ~800. C should be ~1000 (I think I got WA before AC because I had no idea what I was doing). D is really wonky and is not obvious, so I think it should be ~1300. E is not bad but requires a bit of work, so 1500~1600. F is straight-up divisor checking, so ~1600. G I didn't solve, so I just assume it's ~2000.

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

In D : Step 3 -> Take the example given after Bob gets s=00101111 Alice could convert this to s=00000010 and eventually win. I don't see how Bob wins this.

The strategy I see is Alice tries to make the array of the for 10001000/01000100 etc , and wherever Bob tries to reverse digits she flips back the ones Bob flips additionally being able to take care of extra ones. Hence, even if n>2k she can win.

What's wrong?

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

    nevermind Bob would pick the newly found full 0 string , nice contest :)

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

So close yet so far for F. great contest btw

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

good

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

Contest without graphs and dp after long time. Kudos to authors.

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

Clean editorial, easy to understand.

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

Although i was not able to solve F, it was a beautiful problem and worth spending my time on. Thank you for the contest

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

    I solved F by calculating smallest prime factor of every number and then performing a greedy algorithm for prime numbers.

    For me, E was way harder lmao (any hint for E?)

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

editorial out so fast ! wow !!

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

Great Contest, except D was horrible.

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

https://t.me/placementsoftware reirugan this is a telegram channel where answers were getting released during the contest, please check this and use it during the plagiarism check to ban the contestants who have used the exact same code in their submission.

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

As always, please report cheaters on https://cf-cheater-database.vercel.app/.

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

did anyone faced connection issues while submitting? I was stuck approximately 20mins...might be my internet but i am curious if anyone faced the same? :'

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

can anyone please tell me how alice will win if n=5 k=3 and s = 11111

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

This is the closest I have ever been to AK'ing a contest.

And yet, 2 problems was left. Still a long way to go ig

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

can someone pls help me understand where I am going wrong in G? I am at a loss[submission:326909800]

https://mirror.codeforces.com/contest/2123/submission/326909800

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

I like this contest, the problems are fun to think about. Even if I don't solve E and F, I had fun with them :)

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

Strange how all Problem A solutions match. Is this collective intelligence or something else?

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

the contest went from being one of my worst to one of my best, altho i have a rank of 8.6k, stayed idle for 2 hours, clutched at the very last. Hare Krishna!

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

Thanks for great contest and lightning quick editorial!

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

Can someone please explain D to me, especially step 3 in the editorial. I was able to come to the point where I observed that 1. If n is odd and the middle element is already 1 and rest count of 1 is at max k then its always possible for Alice to Win. 2. If n is even and middle 2 elements are 1 and rest count of 1 is at max k then again Alice can win. Basically I understood the reverse of step 2 that if I can force Bob to only be able to make a sequence of length exactly 'k' then Alice can win. Also k == half the length of string in above 2 cases.

But this condition, n < 2*k seems like magic to me.

Basically how to logically go from Step 2 -> Step 3 My Submission: https://mirror.codeforces.com/contest/2123/submission/326981142

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

    you can think of it like this : in order for Alice to win , she needs at some point to make all the remaining ones included in all the substrings , so that whatever Bob does he can not get the full +k ones at his turn .And when we say included in all the substrings they must also be included in the first substring of length k . So we must ensure that when we divide the string into first (k) and last (n-k) elements , we should be sure that the ones in the first substring can be included in all other substrings , so (k) should be greater than (n-k) , reformulating : k>n-k --> 2*k>n is a necessary condition for Alice to win . hope it helps:)

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

      Thanks, this idea that "all remaining ones must be present in all substrings" was the key idea I believe. I re-interpreted it in my own way. Basically, I need to ensure that in the worst case (odd length with 1 in the middle) too I am having a 'k' such that the first substring and last substring can cover it. This is only possible if they overlap, which means: length of first substring + length of last substring > n 2*k > n (since both are equal to 'k')

      If my 'k' fulfills this condition then and count of 1`s > k then Alice always has a chance to win if she plays optimally.

      Thanks a lot!! I am new and my maths is weak. How can I perform better on such problems?

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

      Ohh hell!! You just made me realize how beautiful this problem was! Got stuck in this particular condition for a long time! Although I'd solved it but this line needs at some point to make all the remaining ones included in all the substrings clarifies everything and conversion of this line to the condition 2*k>n shows implementation skills! Thank you buddy!

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

      In problem D, Do bob want the alice to win ? then only, 2*k>n will be valid for alice win. pls reply.

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

    I want to explain it to you with examples in an intuitive way.

    Take an example with n = 7, s=1111111, k = 4 (2k > n holds, so Alice wins even though s is fully 1's). now, Alice can keep doing this: flip leftmost 1 bit and rightmost (k-1) 1's, so after the first move, s = 0001110. Now Bob makes it 1111110, Alice can keep doing the same strategy, s becomes 1111100 (after Alice's and Bob's second moves). This way, after (k-1) moves, here (k-1) = 3, s will be 1111000 after Bob's turn. Now Alice can simply flip the 4 ones and win. It's easy to see that this strategy is optimal for Alice, and any other strategy is not better.

    Now, take n = 8, k = 4, and we have k+1 one's this is the most forgiving case that we can have (from Alice's perspective) where 2k > n does not hold. Specifically, take s = 00011111 (5 one's), now Alice will flip 4, Bob will flip the same 4 back to 1, so this is a trivial case. Take s = 10101011. Alice -> 00000001, Bob -> 11110001. (And now it's the same case like the one above where Alice flips 4 bits and Bob flips back the same 4 bits).

    So if count of 1's > k and 2k <= n, Bob will always win, otherwise Alice wins.

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

I absolutely love the G problem. After reading the editorial, it just seems so obvious

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

Am I only one who is thinking that my code are more complex than this lol

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

Thanks for the fast editorial. The questions were really good. I was able to solve A,B and C.

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

it was my first codeforces contest it took me 50min to solve A ,and got stuck on B,it's really interesting

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

super good contest, very interesting problems and super quick editorial !! :)

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

Gratitudes for the lightening fast editorials.

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

the sol $$$O(tn^2)$$$ for prob A, 326827179

(What tf was I thinking?)

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

My stupid ass was thinking of implementing two heaps in C but I got cold feet and didn't do shit

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

I was looking awoo 's Solution. for Problem E . I dont have any idea how this simple logic work, some. kind soul please help me. :

vector<int> cnt(n + 1);
for (int x : a) ++cnt[x];
vector<int> ans(n + 2);
forn(i, n + 1){
	int l = cnt[i];
	int r = n - i;
	if (l <= r){
		++ans[l];
		--ans[r + 1];
	}
	if (cnt[i] == 0){
		break;
	}
}
forn(i, n + 1) ans[i + 1] += ans[i];
forn(i, n + 1) cout << ans[i] << " ";
  • »
    »
    11 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Think of it like marking the start and end of the increment, and the prefix sum “spreads” the value across the entire range. https://mirror.codeforces.com/blog/entry/78762

    Btw, if you're asking about the full solution, try thinking about the problem in reverse: for each i, check whether it's possible to make the mex = i, and determine the minimum and maximum number of elements to remove to achieve that. (step 4 in this editorial)

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

    ohh look what he is calulating for each possible mex he is calculating 2 values one is what is min number of element we need to remove to get ans as i and what is max number of value we ca remove get ans as i now for getting some value as min value is just its frequency and max value you can calculate first remove everyhting that is >= element . now when a mex is not possible we break now for each i we know we can get value as i for some k belongs to l to r then we just to linear sweeping between l to r incraesing value at l by +1 and value at r by +1 and doing prefix array sum

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

    its difference array ; Imagine a you have been given an array where you are told to make increment over a range (l,r) , you can just increment the lth element by x and (r+1)th element by -x , and then take a prefix_sum at the end of it . So basically he has calculated the min number of removals and max number of removals needed to make any number from (0,n) , a possible MEX , then for each range min[i] to max[i] , he is using a difference array to make range updates and finally took a prefix sum . I had a similar approach as well.

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

    it can also be called as sweep line

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

D could also be a sliding window isn't it, If a every window is like 011 and k=3 let's say then if Alice selects one of it then, Bob wins the next.

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

D was quite tricky, E,F were much easier

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

Great contest and balanced questions! Had that nostalgic codeforces feel many contests these days don't

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

can anyone please explain why does my code exceed time limit in testcase 30 (326998284)

I'm using an array for count which should be better than a map as provided in the solution

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

Alternative solution to F:

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

Anybody body know what is wrong with this? https://mirror.codeforces.com/contest/2123/submission/326994630, stops on test 13?

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

I had a very small bug in question E yesterday that I didn't find out for an hour, that is, I didn't consider the situation of no zero, and I looked at F this morning and wrote it in 10 minutes

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

Alternative for E ( i think ). Solution uses transformation from i to i + 1 step

https://mirror.codeforces.com/contest/2123/submission/326935560

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

I dont really understand my solution of DEF completely, but I guess them and get passed

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

nice contest, i will learn solving problem by going through these editorials!

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

Am i the only one who could not solve C and ruined the contest?

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

My approach to E uses a greedy approach different from the editorial's solution but it's much more complicated, although I think it's still worth noting.

First, we need to find the original MEX, denoted MEX from now on. Now, for k = 0, the answer is always 1.

I have a variable called extra initialized to 0, extra will be the count of elements that when removed, the original MEX will stay the same. Now, of course, we need to keep 1 instance for elements < MEX, the others are extra, and for elements >= MEX, all instances of these elements are extra. For every element >= MEX, I will add the frequency of that element to extra. I also have a vector v for the frequencies of the elements < MEX, sorted in decreasing order.

I don't actually know how to explain the rest of it, but the idea is that I use binary search on this vector of frequencies to find how many values in v are <= k, and this is almost the number of different MEX's I can achieve for this particular k, we also add 1 if extra >= k because in this case we can achieve the original MEX as well.

There is also a special case where K >= extra, that is, if we removed all extra numbers that do not change the original MEX, we still need to remove more. let x = k — extra denote the amount of elements we still have to remove, the answer in this case will be (MEX — x + 1), MEX is the original MEX.

submission: 327022593

UPD: updated submission (removed unused variables).

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

Can someone help me find why my greedy approach is wrong for d . Basically i am greedily converting the outermost k 1's of the string to 0 , and then checking if i can get a substring of length k+1 . Here's my submission — 326923441

my idea was that if bob can make k+1 consecutive 1 then he always win

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

    Your approach is incorrect. Consider the following example:

    n = 5, k = 3 s = "11111"

    After Alice's first move—if she plays optimally—the string will become "01010". Now, Bob is left with a maximum substring of consecutive zeroes of length 1, so he can turn at most 3 characters into '1'. On her next move, Alice can easily turn all the characters back to '0'.

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

i had pretty simple approach on F!!....

https://mirror.codeforces.com/contest/2123/submission/326973038

I just swap x with its largest divisor!

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

I only came up with C with 1 minute left xD Don't know when am I finally touching Ds

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

Am I the only one, who solved problem E using Merge Sort Tree? Because when you realise, that 0 <= i <= min(n-k, mex) and freq(i) <= k it turns out to be a straightforward Merge Sort Tree task (and I couldn't figure out a different solution)

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

For question F , I just iterated from n to 1

and swapped it with the max divisor

int largest_divisor(int n) {
    if (n <= 1) return n;
    for (int i = sqrt(n); i >= 2; --i) {
        if (n % i == 0) {
            return n / i;
        }
    }return 1;
}
int solve(){
    ci(n)vector<int> a(n+1);
    for( int i= 1;i<=n;i++){
        a[i]=i;
    }
    for(int i=n; i>=0;i--){
        int largest = largest_divisor(i);
        if(largest == 1) continue;  
        swap(a[i],a[largest]);
    }
    for(int i=1;i<=n;i++){
        cout << a[i] << " ";
    }
    cout << endl;  
    return 0;
}

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

couldnt solve A, but barely managed to solve B & C lol

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

Thanks for the fast editorial guys, great contest!

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

Writing Solutions step wise is even more confusing . BEA!

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

Great contest! Thanks for the fast editorial!!!

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

there is no changing in my ratings or is not even showing any updates of this contest

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

Editorial of G seems too much complicated to understand ? Is anyone able to make it more simpler ?

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

    I tried chat GPT.

    It helped.

    Any way, I am getting WA but can't tell whats wrong in my code

    327149170

    Can some one lend some brain power?

    Thanks

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

      Found one silly mistake

      Now on TLE on test 23 327273197

      After removing all binary data structures, and using global data stores

      Now i achieved TLE on test 29 327276612

      reirugan is there any special reason why input constrain are so tight?

      My way to calculate divisors was innefficient, still normal code with STL's binary structure based data type like map, vector::push_back() gave TLE :)

      I had to re write code to optimize time with so many unconventional ways. this seem so unnecessary it also waist lot of compute resources of codeforces engines.

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

        I think five seconds is pretty lenient? Some solutions ran as fast as 312ms.

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

          My fully optimized code ran in 1200ms

          beyond this I can only think about rewriting input reader myself. and precomputing gcd? (not sure if that is possible)

          Thanks for lovely problem though, enjoyed every bit brain fuck, and connecting dots to understand solution.

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

          saw one of those solution they optimized by scaling down possible divisors , by only focusing on divisors based on query input.

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

            True, but even the solution codes in the editorial both run in around 2.5 seconds, and they are rather unoptimized (using map, for example). I think it's fair to set the time limit to double that.

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

    Key observation is

    1. $$$(a + (k.n))\mod{m}$$$ where $$$n\in{N}$$$, can be written as $$$a\mod{gcd(k,m)}$$$

    2. possible values you can transform $$$a_i$$$ for given any $$$k$$$ is congruent to $$$a_i\mod{gcd(k,m)}$$$

    3. for any value of $$$k$$$, $$$gcd(k,m)$$$ will be a divisor of $$$m$$$ which means there are only less than $$$800$$$ values possible for divisors (given $$$m \lt 5\times{1e5}$$$)

    4. For each divisor you can keep array $$$a$$$ transformed into $$$a_i\mod{d|m}$$$

    5. you can keep precomputed sum of all arrays (arrays based on divisor of m). and determine answer.

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

Thanks for the contest! Great problems

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

Did anyone notice that there is an account llm-test currently solve all div3 using AI? I'm scared now :(

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

Does the"random"in Problem B mean that peopel are pairred up in twos, and after the match,the winners can be brought together to compete again?

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

Question G — Could someone please explain why ai(mod(gcd(k, m)) is the invariant across the operations? Where did gcd(k, m) come from?

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

    Let x=gcd(k,m). Since x divides k, adding k keeps ai invariant mod x because k is congruent to 0 mod x. Similarly, taking ai modulo m keeps ai invariant modulo x because x divides m.

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

    Where did gcd(k, m) come from?

    I like to imagine in term of grid, picture m=10, k-5, ai=3

    ___#______
    

    keep doing ai + k for few times and you get

    ___#____#____#____#____#____#____#____#____#____#_
    

    now see how would (ai + k) mod m would look, by wrapping this list every 10 chars

    ___#____#_
    ___#____#_
    ___#____#_
    ___#____#_
    ___#____#_
    

    You can see ai + k only ever return in 2 possible values, if you look at these values mod gcd(10,5), i.e. mod 5

    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    

    you can see ai mod (gcd(k,m)) is invariant. that means you can only set ai to ai mod (gcd(k,m)) being smallest possible value and take gcd(k,m) steps at a time.

    if gcd(k, m) is 1 you can make ai any value, try to picture same with k = 7.

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

can anyone explain me "we can first choose one instance of every element less than i . Now, the MEX of our chosen elements is i , so we just need to choose the rest of the elements without affecting the MEX . We can just choose elements arbitrarily, as long as we don't choose i . Since freq(i)≤k , we have enough spare elements to reach our n−k quota without needing to choose i .

" in problem E editorial

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

    lets say that mex(a) = 5

    this means that we have 0 ,1,2,3,4 present in our original array a

    now we want to keep only k elements out of n

    we want to check if we can have i as a MEX for these k elements (0<= i <=5)

    for each i we have to take all the elements that are less than i and we need to not take i

    so if we can pick K elements such that we have all elements less than i and we don't have i
    then we have made an array with k elements and it's MEX is i

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

problem G is A great educational problem can someone provide problems where the idea of this diff array can be applied also

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

why gcd(k, m) in problem G?

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

This should be the gold standard for editorial quality. Feedback for problem quality and difficulty and the solutions explained in collapsible steps. I also really liked the tester rating predictions. I don't expect all editorials to be of this quality, but I certainly appreciate it!

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

I know my doubt would be silly because i would be messing somewhere but : in problem D ,if n = 9 and k = 5 and string = 011111110 the answer according to tutorial solution should be Alice but i think Bob should win Plz tell me where i am messing up

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

    I make the turn from given string to alternate each Alice and Bob -

    Given — 011111110

    Alice — 000101000

    Bob — 111111000

    Alice — 000010000

    Bob — 111110000

    Alice — 000000000

    Alice wins.

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

I don't really understand A.

Here it says that a+b≡3(mod4) which means that b = 3 (mod4) — a; Say Alice picks 4, then b = (3 % 4) -4 = -1. Am I just not understanding the question? @reirugan

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

    Look into modular arithmetic. This would be a+b≡3(mod4) => a≡3-b(mod4) (you are subtracting b mod4) For b=3, => a≡0(mod4), then Alice should pick a multiple of four

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

I am not able to see the reason that why does the test case n=5, j=4, k=1 and the array being [5,4,5,3,2] return YES. While according to me and the solution it should be returning NO.

It's been already mentioned in the step 2 of the solution to the problem that given number can only survive when k=1 if and only if j is largest number among them all.

Please Clarify

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

div 3 C Prefix min and suffix max

#include<iostream> 
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<climits>

using ll=long long;

using namespace std;

void solve();

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T=1;
    cin>>T;

    while(T--) solve();
    return 0;
}

void solve(){
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    // main

    int mn=INT_MAX,mx=INT_MIN;
    for(auto x:arr){
        if(mn > x) mn=x;
        if(mx < x) mx=x;
    }

    string bs="";
    for(int i=0;i<n;i++){
        if(i==0 || i==n-1) bs += '1';
        else if(arr[i]==mx || arr[i]==mn) bs += '1';
        else bs += '0';
    }
    cout<<bs<<endl;
}

Why my code is Wrong

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

the first time i actually used difference array !1!!1

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

We can optimize the solution for problem E using a difference array. Let cnt[x] be the frequency of value x. For x < mex, it contributes to answer k iff cnt[x] ≤ k ≤ n − x − 1.

Each x defines a valid interval on k. We add +1 on [cnt[x], n − x − 1] using a difference array, then take prefix sums.

This avoids sets/maps and runs in O(n) time with O(n) memory instead of O(nlogn) time complexity.