Codeforces Round #833 (Div. 2) // problem B — Diverse Substrings

Правка en1, от shine_rocks, 2022-11-14 11:13:26

I'm almost a new coder, solved only a few problems . No wonder that it takes me more time than regular participants to solve a problem. so did i in the #### Codeforces Round #833 (Div. 2) contest. I messed up with the problem #### (B — Diverse Substrings ) and after a hardship of long two days, I got my desired solution and the best thing is that I made my code so nourished in the meantime that is runs faster than most other accepted codes. I thought about the problem all day and night and finally got a point that I never thought off before.

the problem I'm talking about is — #### Codeforces Round #833 (Div. 2) ,B — Diverse Substrings ;
Your text to link here...

where I had to find out the total number of diverse substrings from a given string of given length that comprises total 10 numeric digits 0 through 9 in random arrangements. A substring is diverse under the condition that the frequency of any digit used in the substring can not be greater than the total number of distinct digits present in the substring.

so to solve the problem I made brute force approaches firstly but to no avail, I got TLE on few consecutive submissions. Then I started to amend my code to bring the running time and complexity to the lowest and reached my best, yet to no avail. then I started to think about the string that would be given as input. according to problem statements, the string can be of 10^5 in length. Suddenly I remembered the pigeon hole technique studied few months ago. pigeon hole technique states that, if (n+1) balls are kept in n boxes then it is sure that any of the boxes containing 2 balls.

similarly , when (n*m)+1 ------- balls are placed in n boxes then it is to be sure that any of the boxes containing (m+1) ----- balls. so I applied this technique.

As 10 distinct numbers can be present in a string and the highest acceptable frequency of each of them is 10 is case of being a diverse substring, so any substring beyond the length 10*10 = 100 is sure to contain a digit that has more frequency than 10, to surely any substring greater than length 100 can never be diverse. so I didn't bring them in count as they will not be able to update the total number of diverse substrings. this made my code more simpler than ever. after implementing this way , I was totally astonished that my code executed in 202 milli second and got accepted!!! . I can't explain how much happy I am right now. this is mu submission history if anyone wants to see the code 180935482 .

Finally I got to realize that to do better in coding, I need to learn more about number theory and techniques. I started loving coding and would highly appreciate if anyone suggests me a better way to learn mathematical techniques and theories.

Thank you for reading this and for any suggestion you might give .... #### Shine (me)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский shine_rocks 2022-11-14 11:13:26 3018 Initial revision (published)