Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all 39796 articles
Browse latest View live

Editorial request for sereja and brackets from codeforces.

$
0
0

I was solving the problem C. Sereja and Brackets from codeforces, but editorial provided by them is very fast paced, can anyone please explain in detail how this problem will be solved.


Apparent Bug Codechef Profile

$
0
0

@admin On my profile I am to select on point which I marked on given screenshot.alt text

RUNDIR - Editorial

$
0
0

Problem Link:

Practice

Contest

Setter: Alei Reyes

Tester: Triveni Mahatha

Editorialist: Triveni Mahatha


Difficulty:

EASY MEDIUM

Prerequisites:

Binary Search, Greedy

Problem:

N students are standing at distinct points in the X-axis. Every students will start running at t = 0. assign direction (left/right) to each of them such that the first time when any two students cross each other is as large as possible. Speed of every students is given.

Quick Explanation:

Do binary search on the time. Suppose at any step in the binary search, we are are trying to find whether it is possible to assign direction such that no students will cross before some time say t.

To check, whether it is possible to assign direction. We fix the direction of leftmost students towards left (without loss of generality). For every other student from left to right, we try to fix the direction to left itself if it crosses non of the students before time t. And move to next student.

If it is not possible, we try to fix the direction as right. If it is possible then move to next student.

If we are able to assign direction to each students in that manner then the answer is yes, otherwise it is not possible.

SOLUTION:

Setter

Tester

Time Complexity:

For required precision, iterating 100 steps in the binary search is enough. Let's say the number of steps be S.

$O(S N)$ per test case.

Space Complexity:

$O(N)$

help needed in a DP question.

$
0
0

given two arrays, of which one is increasing (not necessary strictly) and other is decreasing(strictly actually it is the index of that element from back)and we have to answer q queries [x, y] in which we have to find the maximum value of the product of the value at same indices in array excluding the given range [x, y].

Example :

a1 : 1 2 2 3 4 (fixed increasing array)

a2 : 4 0 3 2 1 (for range [1, 1]) : answer is 6 (32 or 23)

a2 : 2 0 0 0 1 (for range [1, 3]) : answer is 4 (4*1)

I thought of applying binary search but as the first array is not strictly increasing it fails!

infinite series sum

$
0
0

hello guys I want to just ask a mathematical problem here. how can i find the sum of this infinity series.

1+a+a1/2+a1/4+...
where 0<a<1 thnxs in advance.

Google Code Jam Round 1-B 2018 Rounding Error Problem WA

Possible bug in rating change

Things to do in summer vacation

$
0
0

What should i do in summer vacation of 2 months? what are the best thing to learn in summer to improve my coding skill? i'm a begineer:-


Two vs Ten (TWOVSTEN) Video Solution

[Script] Filter submissions status based on score

$
0
0

Hello fellow coders,

As you all know, looking at the status (Time and Memory) of successful submissions gives a good hint about the expected Time/Memory complexity. But often there's a lot of submissions of varying points and it gets annoying to manually filter through them and get an approximate. So, I wrote a script that filters the results according to the score that is needed.

INSTALLATION STEPS

  • Install Tampermonkey for Chrome/ Greasemonkey for Firefox.
  • Install the script from here:

USAGE

Go to submission status page of any problem such as:

https://www.codechef.com/LTIME59A/status/GCDDIV

There should be an added option of score, add the partial score you want to view and click go.

Screenshot

The Github Repository can be found here .

Editorial request for solving kquery problem from SPOj

$
0
0

Can anyone provide detailed editorial to solve KQUERY - K-query problem from SPOJ.

This problem has one editorial on codeforces I have already looked into it but found it very fast paced and didn't understand that.

thanks in advance

Codechef Contests regular reminders

$
0
0

Right now, I need to place reminders for every contest I wish to participate. I miss many contests at times, because I don't check codechef that regularly.

Won't it be better that codechef sends reminders for all upcoming contests to its subscribers? If there is something like that already, please let me know how to access it.

If isn't, My strong suggestion to codechef team to incorporate the same. It'll be really helpful for developing the platform to an even better version of itself!

Few Suggestions maybe ?

$
0
0

I was thinking that maybe the setter and testers can comment their code so that we can understand what the particular implementation is doing. Its frustrating to read the editorial and not understanding it and then looking the implementation and seeing just short hands and single character variable without explanation on what are they doing or what they signify.

Maybe this can be accommodated. what are your opinions ?

Not a simple sum!!!!

How do I win a CodeChef Goodie?

$
0
0

I want to know how can I get a CodeChef goodie? In which monthly contests, how many goodies are given? Does CodeChef also give certificates to the winners?


AVGPR - Editorial

$
0
0

PROBLEM LINK:

Div2
Practice

Setter-Anuj Maheshwari
Tester-Misha Chorniy
Editorialist-Abhishek Pandey

DIFFICULTY:

Simple

PRE-REQUISITES:

Array, Looping, Basic Math and Principles of Counting, Frequency Array.

PROBLEM:

Given an array of length $N$, find number of unordered pairs $(i,j)$ such that their average exists in the array (real division), or in other words, find number of unordered pairs of $(i,j)$ for which we can find an element in array $A_k$ which satisfies-

$2*A_k=A_i+A_j$ where $A_i$ and $A_j$ are $i$ $'th$ and $j$ $'th$ element of the array.

Unordered pair means that order of listing elements in pair doesnt matter. It means $(2,1)$ is treated same as $(1,2)$. In ordered pairs, we treat both of them as different.

QUICK EXPLANATION:

We immediately see the low constraints for value of $A_i$. We can make a frequency array to record frequency of each array element. The only problem is, $A_i$ can be negative as well. This is easily solved by adding a constant $K$ (preferably $1000$) to all array elements. With all elements positive, we iterate over all possible pair of values of array elements, i.e. we check all pairs of $(a,b)$ where $0\le a,b \le 2000$. We check if $a$, $b$ and their average exists in array and update answer accordingly.

EXPLANATION:

This editorial will discuss 2 approaches. First is mine (Editorialist), and second one is Misha's (@mgch), i.e. the tester's. My approach is a bit more difficult than tester's because I use some formulas and observations, while tester's solution is simply basic.

We noticed a lot of Div2 users getting stuck in lots of useless and unnecessary things, hence we will answer how to overcome such things in Chef Vijju's Corner at the end of editorial. :)

1. Editorialist's Approach-

The first thing I did was to add $1000$ to each element so that all elements of array are non-negative and between $[0,2000]$. We can show that if we add any constant to all values of array, then although the average of numbers increases, it has no effect on "existence of average (of 2 array elements) inside array." Try to prove it if you can. (Answer is in tab below).

View Content

For now, forget about duplicates. My approach counts even duplicates in the process, and removes them later at the end.

Once we have the frequencies of elements inside array, I iterate from all possible "pairs of values" allowed, i.e. , we know that now values of array elements are in range $[0,2000]$, so we will iterate over all pairs of $(a,b)$ where $0 \le a,b \le 2000$ and do the following-

1.If $(a,b)$ exist, and if their average (by real division) exists in the array as well, goto 2, else check next pair.
2.Is $a==b$ $?$ If yes, then add $(freq[a]-1)*freq[b]$ to answer, else add $freq[a]*freq[b]$

To remove duplicates, simply divide the answer by $2$ - because each pair is counted twice. The proof for the 2 formulas I used, along with fact that dividing by $2$ removes duplicates is left to reader as an exercise. (Answer/Hints are discussed in Chef Vijju's corner.)

$Time$ $Complexity-O({2000}^{2}+N)=O(N+K)=O(N)$ (where $K$ is a constant).

Tester's Approach (Easy)-

The first step is the same, he also made all elements non-negative by adding 1000. He deals with duplicates immediately.

1.For each possible value in $[0,2000]$, check if it exists in array. If it does, goto 2, else check the next value.
2.Count all pairs formed by this value and its duplicates by adding $ cnt[mid] * (cnt[mid] - 1) / 2$ to the answer. $mid$ here is the value being investigated.
3.If $mid$ is average of 2 numbers, this means both the numbers are equidistant from $mid$. Hence, count all pairs possible due to presence of equidistant numbers present at a distant $x$ , where $x$ is in range $[0,mid]$ and $mid+x$ and $mid-x$ are in valid range of $[0,2000]$. For each such pair, add $cnt[mid - x] * cnt[mid + x]$ to the final answer.

Time complexity is same as my solution in worst case :).

SOLUTION:

Setter
Tester
Editorialist

CHEF VIJJU'S CORNER:

1.Lets first discuss the mistakes. Most of the participants got the formulas right...but they did a tremendous blunder. Suffered from Overflow!!. If you are declaring your frequency array as int, then for larger test cases where $N$ is as large as ${10}^{5}$, the frequency of elements can be as large. Hence, when we do $freq[a]*freq[b]$, we must make sure to use proper type casting, else the answer will overflow!! Many contestants stored answer in an int variable, and that code is doomed to be wrong even before submission!!

One thing I will tell, if you are getting AC for smaller sub tasks, and WA for larger ones, do check for overflow!!. There is a good $60\%$ chance that it is overflow issue giving you WA. We were going through the wrong solutions in detail, and our heart sank a little bit each time we saw a solution killed because of overflow :(

2.Some of them mistook $|A_i| \le 1000$ as $0 \le A_i\le 1000$. The difference between the two is that, the first condition allows negative integers in the input. Whenever in such confusion, assume value of $A_i$ to be negative - and ask yourself - Does it satisfy this constraint? If yes, its in the input, else its not.

3.Derivation of $freq[a]*freq[b]$ in tab below.

View Content

4.Whenever you see that the max value of array elements is comparable to size of the array, frequency array approach can be used. Its usually asked as a part of question rather than an individual question, like here it was Math (principle of counting) +Frequency array. With some modification, you can also count number of each character in a string using this approach.

5. Frequency Array approach to count number of each element is one of the steps involved in Counting Sort , an $O(N)$ sorting technique.

6. What would we do if this question had constraints on $A_i$ upto $|A_i| \le {10}^{5}?$ It would be a difficult question, but still possible to solve. That problem then, can be solved using $FFT$. We create a polynomial $P(x)$ such that $P(x)=\sum_{0}^{2*{10}^{5}}(freq[i]*{x}^{i})$. On squaring $P(x)$, we will have $freq[i]*freq[j]$ for all $(i,j)$ between $1 \le i,j \le N$, but we need to check the case when $i=j$. The next step to do is, if $i+j$ is even, and $freq[(i+j)/2]>0$ , it has to be added to the final answer. This outline is just meant to introduce beginners that there is something like $FFT$ existing in this universe (xD) and to offer an interesting insight to the solution. Time Complexity is $O(|A|Log|A|)$

7. Questions to practice frequency array-

(More will be added if I find more, or if the community helps :) )

Separate section for editorials only.

$
0
0

Shouldn't there be a separate section for the editorials? The "questions" tab should list only the questions, and not the editorials.

As for now, the "Recent Questions" section in the CodeChef homepage often features editorials with large number of views and upvotes, while the real questions get neglected.

[suggession] Sort by points

$
0
0

@admin, Please add sort by no of points on All submissions page of a question.

This feature is really helpful when we want to see highest scorer points for challenge problem. When we have a question for which partial AC submission are much more than fully AC.

In those cases AC(100 pts) soln is lost somewhere in between partially AC soln.

WA in GALACTIK Please Help!

$
0
0

Checked all previous links in the forum for this question... but unable to debug... I'm doing dfs to find min tax val node in each component(val>=0) and then using it to construct optimum edges. WA Code

Not Able to Answer any Question on codechef discuss forum ? why? plz help

$
0
0

I am asking this Question on Behalf of my friend anju98 because she have only 1 karma point(due to strict rules of codechef she is not able to ask her doubts)..
other than that, Main problem is-->

She is not able to answer any Question on codechef discuss..

alt text

she is getting "reCapcha V1 is shutDown" .. thats why and not able to answer any question

but then why i m not getting such issues ? Any solution to this problem.. help

Due to only 1 reputation points(1 point is given to every new user in gift by codechef ), she is not able to ask any of her doubt of codechef problems.. So plz tell me How can she Earn enough karma point to ask AnyQuestion..

due to her low karma points,

  1. she can not ask question(doubts)
  2. she can not upvote
  3. she can not downvote
  4. now she thought she will help others begginers by writing on answer and may earn karma points to become elligible for asking her own doubts, but due to this reCaptcha error, she is not able to ask any question

i know, a seperate thread is availble to ask question. who dont have enought karma points, but beginner is unfamiliar initially that a seperate thread is going on to ask doubts..
Thanks In Advance

Viewing all 39796 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>