MSV - Editorial

Explanation of alternate solution in a very easy to understand language :slight_smile:

Lets say that the element under consideration is

A[i]

Using factorization we will find all the distinct factors of all the elements before A[i] namely A[0], A[1], … ,A[i-1]

Lets keep an array named count[100005] that will keep count of number of times a factor has appeared.

Now we have all the factors of all the elements before A[i] and if A[i] would have been a factor of elements before A[i] then it would have been reflected in the count array that we are maintaining to count how many times a factor occurs.

Now we simply need to find the maximum value in the array count.

Please comment if I am missing something.

1 Like

Exactly, but this should not work for a testcase with 10e5 elements with each one being 10e6. It should be a timeout based on the constraints right?

https://www.codechef.com/viewsolution/27391997
Mine got an AC somehow

@r_64 / @admin / @harrykp / @all : Why @harrykp 's solution(CodeChef: Practical coding for everyone) got 100pts on AC why not the following different types of my solution :frowning:

  1. CodeChef: Practical coding for everyone
  2. CodeChef: Practical coding for everyone
  3. CodeChef: Practical coding for everyone
  4. CodeChef: Practical coding for everyone

@admin will you please help on this is there anything wrong with compiler or is my solution wrong if my solution wrong what about the editorial?

Please help on this, solution can be appreciated :slight_smile:

The following is my 10 lines of code C++14 dynamic-programming solution.

https://www.codechef.com/viewsolution/26989154

The array int dp[10^{6}+1] is used to store the count of divisors 1 \le d \le 10^{6} for all previous subsequene items A_{j}, 1 \le j <i, in the i-th iteration. Initially, dp[d] = 0 for all d. The maximum star value can be computed iteratively as \max \limits_{i=1}^{n} dp[A_{i}]

2 Likes

Brother…you get TLE hence your approach is OK…you just need to optimise it.
I review your code https://www.codechef.com/viewsolution/27403611
You are calling max function in loop 2 everytime even it is not needed…Max should be called after execution of loop 2.
I think for test cases in which loop 2 runs frequently it generates TLE…
you can re submit your code again …Of course it will not give you point…
But you can check.
If the condition remains same…Update me and then @admin will take care of it.

Hope your code runs

CodeChef: Practical coding for everyone Same TLE :frowning_face:

Try 2 loop inside if h[i]==0…
i knew it is a hit and trial.
Honestly, i couldn’t get the main reason …why your code isn’t running successfully.
Hope,expertise will look into this matter.

Three more test cases has been added and this solution is giving TLE for those 3 test cases.

1 Like

Yes…, My bad :sweat_smile:

Why is it happening? I think the constraints are still the same.

All are prime numbers maybe. So, sieve thing isn’t beneficial

https://www.codechef.com/viewsolution/27369369

how this solution got accepted??

1 Like

Weak testcases, I suppose: it fails on:

1 
7
240 440 112 132 571 556 139 

Edit:

I think Codechef really needs to adopt a policy of always allowing tons of testcases in a testfile (at least 100 - possibly more like 1000) and always controlling the total size by having constraints of the form “blah less than or equal to bloo over all testcases” (in addition to per-testcase constraints) - you can’t think of every way a contestant can “game the system”, and randomised testcases often flush out these kind of things after ~100 or so testcases.

This would have been useful in ZOMCAV where a ton of people used an approach that was so obviously wrong that the Setter and Tester (understandably!) didn’t think of it, but which can be usually revealed as false only after ~150 random testcases. As far as I can tell, they still haven’t added testcases to guard against this wrong approach :frowning:

Edit2:

Hehe - the same user also exploited this flaw in the testcases for ZOMCAV XD Edit3: Wait, no - I think he’s found an even deeper weakness in the testcase data - this one is exposed almost immediately by randomised tests. How is he doing this?? XD

3 Likes

It fails on anything above 100 value being as MSV for example
1
7
1000 1000 1000 1000 1000 1000 1000
he is simply reducing N(actual MSV number) to 100

3 Likes

Astonishing XD

@vijju123 - can we get some better testcases for MSV? :slight_smile:

1 Like

Yes, we just found the test cases for this problem too weak after the contest started. :sob:

I also agree that codechef needs to allow problems to have many test cases. The reason that we minimize the number of tests is “to reduce server loads”…

But even if you can make a lot of tests, it’s still hard for some problems to make very perfect test data. MSV is an example IMO.

4 Likes

tl for python is very strict.I had to use sieve to get comlexity<nlog(n) then only it passed

I tried implementing similar solution like @aditya_kandi6 But getting 2 TLE don’t know why this is happening ,Someone please help .

my solution link : https://www.codechef.com/submit/complete/27537109

adityas solution link : CodeChef: Practical coding for everyone

I’m getting “Access Denied” for this link.

Edit:

Assuming you meant CodeChef: Practical coding for everyone - there are two extra testcases that have been added in Practice mode that were not in the original OCT19B where adityas’s solution is taken from:

https://www.codechef.com/OCT19B/

Presumably, if adityas re-submitted his solution in Practice mode, it would also now TLE, like yours does.

1 Like

“Sum of N over all test cases does not exceed 100,000”. What is the meaning and use of this line given in constraints ?