naivedyam_mishra's blog

By naivedyam_mishra, history, 13 months ago, In English

Problem Link — https://mirror.codeforces.com/contest/2085/problem/E

Code — https://mirror.codeforces.com/contest/2085/submission/312319353

Approach and Proof-

For the moment, consider that B isn't shuffled. In that case, a[i]%k = b[i].

So b[i] is just the remainder when a[i] is divided by k. From factor Theorem we know, dividend = divisor × quotient + remainder.

Say the quotient is q. Then rewriting this using factor Theorem-

a[i] = k*q + b[i]

So a[i] — b[i] = k*q.

Now let's do it for all elements ie,

a[1] — b[1] = k*q1 a[2] — b[2] = k*q2 ...... a[n] — b[n] = k*qn

Adding them all, we get

Sum of all of A — sum of all of B = k*(q1+q2+...qn)

Now in the start we assumed an unshuffled B. But this holds true for even shuffled B because no matter what the order the sum remains the sum.

Observation from this- No matter what the order of B, the difference of sums of both A and B must be a multiple of k. So, we can only have such a k which a divisor of (sum of A — sum of B). Let's call that difference of sums d.

Now we can consider 3 cases-

  1. If d = 0, then B must be a Permutation of A. Proof — notice that an element of B can never be greater than the corresponding element of A it got generated from because x%y must be less than x. So d = 0, every element of B must be equal to its generator. So B must be a permutation of A. So, we can always have max(A) + 1 as an answer because x%y for any x < y gives x.
  2. If d = 1, all elements of b must be 0. This is because the only divisor of 1 is 1 itself so we only have k = 1 as a valid answer and any number % 1 = 0. So if there is any non zero element in B and is -1 else it is 1.
  3. In every other case consider all the divisors of d as a valid answer and make a frequency map of a[i]%(divisor of d). If frequency map of b = this new freq map only then it's a valid k. This is literally brute force.

So what part of my proof is wrong which is causing the WA verdict?

Full text and comments »

  • Vote: I like it
  • -10
  • Vote: I do not like it

By naivedyam_mishra, history, 14 months ago, In English

Here is my idea-

First, I am counting the number of occurrence of AB, BA and overlap. Overlap are those indexes using which we can get both AB and BA. Like using A in BAB I can get both BA and AB. The ABs and BAs made from these indexes aren't counted to my count of ABs and BAs.

Next, I am getting rid of overlap by converting it to either AB or BA. If count of AB is less than the given limit for it, then I am converting as much overlaps into AB as I can such that AB doesn't exceed its limit. For all the remaining overlaps I am converting it to BA.

Next, for all the extra ABs and BAs I am left with now, I am converting them to an independent A and an independent B. If the final count of all independent As and Bs are less than or equal to the given limit, my answer is yes else no. I don't see anything wrong with it since I am redistributing as many ABs and BAs as I can to those respective things. Is there a logical flaw in my approach?

Here is my submission — 306805586

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it

By naivedyam_mishra, history, 16 months ago, In English

I have mostly tried following the lines of editorial for the problem 2042D - Recommendations but implemented on my own. Can someone help me with fixing the error?

here is my code — 294711824

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By naivedyam_mishra, history, 17 months ago, In English

I was recently trying out a CSES problem Coin Combinations 2 and THIS CODE GAVE ME MULTIPLE RUNTIME ERRORS while THIS ONE PASSED. If you look closely, both are exact same codes except that the one with runtime errors uses long long instead of int. Why using long long is giving runtime errors here?

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it

By naivedyam_mishra, history, 17 months ago, In English

My solution to 1207E - XOR Guessing which is 292757488 is giving incorrect query format and I am unable to figure out why. I have ensured that all the numbers I generate have no less than 14 digit binary representation. Can someone help me figure out?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By naivedyam_mishra, history, 17 months ago, In English

My submission 290383236 for the problem 1234D - Distinct Characters Queries is giving a WA at test case 8. However the numbers differ at case 303 so I cant view that particular test case. I don't get what am I doing wrong as the logic seems fine to me (Segment trees are some real pain while debugging). Can someone help me out here?

Full text and comments »

  • Vote: I like it
  • -19
  • Vote: I do not like it

By naivedyam_mishra, 17 months ago, In English

My solution to B — Cryptography gives a TLE on test case 13 even though (I feel) my solution meets the constraints. I am building the segment tree in O(n) and answering m queries in O(mlogn). So even in the worst case my solution should run in < 4e6 operations right? Then why a TLE?

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it

By naivedyam_mishra, 18 months ago, In English

THIS PROBLEM from Codeforces Edu section seems to be an exact replica of CSES problem DYNNAMIC RANGE QUERIES. I solved the CSES one and it passed but solving the Codeforces one was giving runtime error. Tried fixing it but didn't help much. Even the one that passed on CSES dosen't pass on CPH and gives Runtime error on my VS Code too. So I decided to copy the same code that passed on CSES and try it here on codeforces but for some reason, even the code that passed on CSES is giving me runtime error on Codeforces too! It is not even a difference in the version of C++ since on both the sites I used C++20.

THIS IS MY CSES CODE

While [submission:286148512] is my Codeforces submission (both are same since I tried pasting the same code after 2 runtime errors). Could someone explain why this weird behavior even while using the same C++ versions? And why is my CSES submission getting AC on CSES but giving run time error on both codeforces and vs code?

Full text and comments »

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