Skip to main content

Posts

AtCoder Post Contest Solutions and Code C++

  Solutions with explanation and C++ code of these contests are available here. All these solutions and editorials are published after the actual contest gets over and are only aimed for editorial purposes.   Regular Contests- Beginner Contests- 1. AtCoder Beginner Contest 233  ( Solutions ) ( Contest Link )

AtCoder Beginner Contest 233 (ABC233) Post Contest Solutions A,B,C,D,E (C++)

 Problems and Solutions-  A- 10yen Stamp  https://contestsolver.blogspot.com/2021/12/abc233a.html B- A Reverse https://contestsolver.blogspot.com/2021/12/abc233b.html C- Product  https://contestsolver.blogspot.com/2021/12/abc233c.html D- Count Interval   https://contestsolver.blogspot.com/2021/12/abc233d.html E- - Σ[k=0..10^100]floor(X/10^k) https://contestsolver.blogspot.com/2021/12/abc233e.html

E_ Σ[k=0..10^100]floor(X/10^k) - AtCoder Beginner Contest 233 (C++ Code and Explanation)

   E- Σ[k=0..10^100]floor(X/10^k) AtCoder Beginner Contest 233  Problem-   https://atcoder.jp/contests/abc233/tasks/abc233_e Approach- As we see the pattern, each time the number gets divided by 10 and then summed up to give the final answer.  Observation-1 As we notice that for a number if it has n digits then the most significant digit contributes n times to the final sum, the second most significant contributes n-1 time and so on.  Observation-2 This final sum can be represented as sum of the prefix sums of the digits of the number. For example  1225 has to be written as 1, 3, 5, 10 as prefix sum array.  Now we just have to add these numbers starting from the backside of the array using the carry ahead method of addition. The sum is 1360 for the above example. All the operations should be done by taking the number as string input since the constraints are very high. Below is the code matching with the exact explanation above. Code - string s; c...

D_ Count Interval-AtCoder Beginner Contest 233 (C++ Code and Explanation)

  D-Count Interval AtCoder Beginner Contest 233  Problem-   https://atcoder.jp/contests/abc233/tasks/abc233_d Approach- Since, negative numbers are also allowed, we cannot use the traditional method of sliding window here. So, we will use unordered_map to store the subarray sum we have encountered till now and if the difference of current sum is already present in our map then this means that the subarray after the previous one also has sum equals k. For example k is 7 and array is {3, 4, 7}, then for index 0 and 1 map stores 7 as a subarray sum and then as we encounter index 2, current sum is 14. Now current sum-k is 7 and it is already present, this signifies that the current subarray sum is also k. Below is the code matching with the exact explanation above. Code - long long s=0, ans=0; unordered_map<long long, long long>m; for(long long i=0;i<n;i++) {     s+=a[i];     if(s==k)         ans++;     else if(m.fin...

C_ Product-AtCoder Beginner Contest 233 (C++ Code and Explanation)

  C-Product AtCoder Beginner Contest 233  Problem-   https://atcoder.jp/contests/abc233/tasks/abc233_c Approach- Since, it is given that product of L1*L2*L3....LN is less than 100000 so we can use the brute force method for solving this question. That is by generating all possible combinations and incrementing the final answer. But the question is how to generate all possible combinations? So, this can be done using Depth-First-Search or DFS. Starting from first row ( rownumber=1 ), take elements row wise and for each element, move to the next row with current product ( currpro ) multiplied by this element ( currele ). As soon as we reach the row after the last one  ( rownumber=n ) , or current product ( currpro ) exceeds k, return the function. And now our current product  ( currpro )  should be divided by the element  ( currele ) to continue the process for remaining elements of the same row  ( rownumber ) . This step of dividing can also be ca...

Leetcode Post Contest Solutions and Code C++

  Solutions with explanation and C++ code of these contests are available here. All these solutions and editorials are published after the actual contest gets over and are only aimed for editorial purposes.   Weekly Contests- Biweekly Contests- 1. Leetcode Biweekly Contest 68  (Solutions) ( Contest Link )

Codeforces Post Contest Solutions and Code C++

Solutions with explanation and C++ code of these contests are available here. All these solutions and editorials are published after the actual contest gets over and are only aimed for editorial purposes.   Codeforces Rounds- Global Rounds- 1. Codeforces Global Round 18       (Solutions) ( Contest Link ) Educational Rounds 1. Codeforces Educational Round 120  ( Solutions ) ( Contest Link ) Other Rounds-

B_A Reverse AtCoder Beginner Contest 233 (C++ Code and Explanation)

B-A Reverse AtCoder Beginner Contest 233  Problem-   https://atcoder.jp/contests/abc233/tasks/abc233_b Approach- Do l-- and r-- for 0 based indexing, then firstly print character at index less than l. After this make a new string of characters from l index to r index inclusive. Print the reverse of this string. Then print remaining characters from r+1 to n-1, where n is length of original string. Code - long long l , r ; cin>>l>>r; l--; r--; string s; cin>>s; long long n=s.length(); for( long long i=0;i<l;i++) cout<<s[i]; string temp=""; for( long long i=l;i<=r;i++) temp+=s[i]; reverse(temp.begin(), temp.end()); cout<<temp; for( long long i=r+1;i<n;i++) cout<< s [i]; Other Problems from this Contest- https://contestsolver.blogspot.com/2021/12/abc233.html Disclaimer- Everything is published after the actual contest gets over.

A_10yen Stamp AtCoder Beginner Contest 233 (C++ Code and Explanation)

A-10yen Stamp AtCoder Beginner Contest 233  Problem-   https://atcoder.jp/contests/abc233/tasks/abc233_a Approach- If y-x is divisible by 10 answer is simply(y-x)/10 and if it is not divisible by 10, the answer is ((y-x)/10) plus 1. Both of these can be handled by using (ceil) of (y-x)(10.0). Code - long long x, y; cin>>x>>y; if(x>=y) cout<<0<<endl; else cout<<(ceil)((y-x)/(10.0)); Disclaimer- Everything is published after the actual contest gets over. Other Problems from this Contest- https://contestsolver.blogspot.com/2021/12/abc233.html