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

Ratings are just unfair..!!!

$
0
0

Ratings are just unfair..!!

  • My rating before(this and JAN Challenge) is 1484.
  • And after this challenge +83.So 1567.And it is reverted back to 1484.Due to running of JAN Long challenge.
  • And after long challenge it is inc.by +97 ,which is 1581.
  • And Now ratings are updated 1567(this External rating contest ).And +14 for Jan Long challenge.
  • This is so unfair because my rank was 2673.which is 1/4th of 13,000 participants.
  • And I get +14..Need to go through once.@admin@vijju123.

A big bug in Rating system..!!!

$
0
0

Here,

  • It is my rating graph for Jan Long Challenge 2019(Div.2),And see my rating inc. by 14.So which becomes 1581.
  • And my Rank was 2673.

My Graph

  • And this is Another graph of the person from same rank list,which is inc.by +26,which becomes 1590.
  • And his rank was 3990.

His graph

And,My rank was more than him,but his rating inc.by +26,but mine was +14...Give me reason @admin@vijju123 Thank you..!!!

A doubt in approach of MAXEP problem ( Shared by IOI Gold Medalist ) - December long contest 2018

$
0
0

I wrote an editorial regarding how to solve the MAXEP problem asked in december long contest 2018.

A lot of users shared wonderful approaches to take on the problem (besides my way of solving it), but I was not able to understand the approach of @utaha.

So any-one who understands how @utaha solved that particular problem - Please help...!!!

Especially I would be glad if @utaha himself helps me...!!!

That approach was ( as @utaha mentioned in the editorial ) from an IOI gold medalist and sounded very simple, just the fact was that I was not able to understand why was it working...

Link to that editorial can be found HERE

I asked my doubts there in the comments section ( Just under where @utaha shared his approach), but I guess no one is looking at that editorial now... So I decided to ask it seperately here.

But if you get @utaha's approach, Please share it in that editorial itself. ( It will be good for me to have all material of one question under one link itself)

Thanks in Advance...!!!

FANCY - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter:Shivam Gupta
Tester:Xiuhan Wang
Editorialist:Taranpreet Singh

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Given a string, check if it contains the word "not" as a complete word. (Not as a part of another word, like nothing)

SUPER QUICK EXPLANATION

  • The quote is Real Fancy, if the quote is "not", quote begin with "not", quote ends with "not" or quote contains "not" where "*" represents space character.

EXPLANATION

Consider the special case where quote itself is "not" separately.

After this, the word "not" can either appear as the prefix, as the suffix or in between the quote. So, check separately if the first word is "not", the last word is "not" or the quote contains the word "not". (Make sure to check that the word "not" is surrounded by space character on both sides.)

Trick

Those not interested in splitting the string into words can solve this by inputting the quote as a string, add space character at both ends of strings. Now, the quote will be "Real Fancy" if it contains "not" where "*" represents space character.

As a side fact, @vijju123 actually have a thing about fancy quotes. He has another fancy quote, shared during the contest, "You made my non-fancy quote a fancy one".

Time Complexity

Time complexity is $O(|S|)$ per test case where $|S|$ is the length of the quote.

AUTHOR'S AND TESTER'S SOLUTIONS:

Setter's solution
Tester's solution
Editorialist's solution

Feel free to Share your approach, If it differs. Suggestions are always welcomed. :)

A very big plagiarism this long challenge JAN19.

$
0
0

Codechef did not do his job this long challenge yet it was obvious that the plagiarism had to be very big. Out of 10 solutions in python3.6 I count 4plagiarisms on XYPIZQ.

And what disgusts me is that the scores of all these cheats have been calculated. Some of them were just copying and others using other techniques that I prefer not to say here so that others do not use it.

This attitude was common in India and I find it very sad to behave when I see all the work done by codechef, geeksforgeeks and ... This is not the way that India will stand out as a respected power. Please stop the plagiarism because I know people who prefer not to participate because of it. Even his ranking backward gradually because of the people who cheat is frustrating.

Look at these solutions:https://www.codechef.com/viewsolution/22482771https://www.codechef.com/viewsolution/22482425https://www.codechef.com/viewsolution/22483248https://www.codechef.com/viewsolution/22482660

Just in one page.

And this is about all the problems of competition

Pizza Slice (XYPIZQ) mini editorial

$
0
0

Consider this diagram. Half of the line segments are drawn in red. The line segments $a_0b_1,b_1a_2,a_2b_3,b_3a_4$ also exist, but are ommited here for clarity.

alt text

We do not yet know what angle $x$ is, but we can work out the other angles in terms of $x$. We will be working in radians here. $\pi\ radians = 180\ degrees$

Because the slice is an isosceles triangle, we can calculate:

$c = \frac{\pi-x}{2} = 0.5\pi - 0.5x$

Knowing that all the inner triangles are also isosceles trangles, we can also calculate:

$d = \pi - 2c = x$

$e = c - d = 0.5\pi - 1.5x$

$f = \pi - 2e = 3x$

$g = \pi - c - f = 0.5\pi -2.5x$

$h = \pi - 2g = 5x$

$i = \pi - e - h = 0.5\pi - 3.5x$

$j = \pi - 2i = 7x$

Also because of the isosceles triangle, $x = i$, so we can now derive the value of $x$:

$x = 0.5\pi - 3.5x$

$4.5x = 0.5\pi$

$9x = \pi$

Now we can go back and substitute $\frac{\pi}{9}$ for $x$ and work out all the angles exactly.

We can also see a pattern in the angles. The angles of the tops of the triangles go:

$x,3x,5x,7x..$

while the angles of the sides go

$0.5\pi-0.5x$

$0.5\pi-1.5x$

$0.5\pi-2.5x$

$0.5\pi-3.5x$

$..$

So we can work out the angles of specific triangles with closed form formula, instead of having to calculate them all.

this code runs successfully but at the time of sumbit it gives me NZEC error . can you help me to rid off from this

$
0
0

cook your code here

x, y = int(input()), int(input()) if(x % 5==0): print(y) y=y-x- 0.50 print("%.2f" %(y) ) else: print(y)

EARTSEQ - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter:Evgeniy Artemov
Tester:Xiuhan Wang
Editorialist:Taranpreet Singh

DIFFICULTY:

Easy-Medium

PREREQUISITES:

Sieve of Eratosthenes, Number-Theory and Constructive Algorithms.

PROBLEM:

Given an integer $N \geq 3$, find $N$ distinct numbers such that every pair of consecutive numbers have a common factor $ > 1$ and all possible consecutive three elements have no common factor $ > 1$. Also, all numbers found should be between $1$ and $10^9$. First and Last elements are also considered adjacent here.

SUPER QUICK EXPLANATION

  • A simple way to generate $N$ such distinct numbers is to take a prime and multiply two consecutive elements by this number. This way, the condition of co-primes is handled, but the numbers generated go beyond $10^9$.
  • A better way would be to reuse smaller primes while ensuring all the generated numbers are distinct.

EXPLANATION

This is a constructive problem, and hence, have multiple solutions. Feel free to share your solution in comments.

Note: If we represent a number as the product of prime numbers, Prime factorization of a common factor of the pair of numbers is the common part of prime factorization. If we consider prime values or product of few primes, they have relatively lesser factors as compared to composite numbers. So, for most of the problems involving prime factors/factorization/divisibility, prime numbers bear special importance.

Let us try similar problems first.

Try solving the same problem assuming there's no upper bound on maximum values. Now, we can just multiply a distinct prime number to every pair of consecutive numbers. This way, every two consecutive numbers are not co-prime while every three consecutive numbers are coprime.

The above solution is sufficient to solve the first subtask, but in the second subtask, the values exceed $10^9$, so we need something better.

Try solving the same problem, assuming we are allowed repeated values. Here, we can choose prime numbers and multiplying each position by exactly two primes such that every two consecutive positions share prime factor while every three consecutive numbers do not share any prime factor, taking special care to choose a different prime number when reaching the end of the array.

Now, let us solve the original problem.

Think up and try to mix the above solutions so as to reduce the magnitude of generated numbers while keeping each number distinct.

The construction used in my solution is to reserve the first few primes and then multiply the first two positions by a non-reserved prime, next two positions by another prime and so on. Now, We can multiply Last and first position by a reserved prime, second and third position by different reserved prime, and so on. This way, we are guaranteed to have every pair of consecutive positions divisible by that particular prime number, and every three consecutive positions are coprime since no prime is multiplied to three consecutive positions.

Implementation

For this problem, we can preprocess and calculate a list of primes beforehand using the sieve of Eratosthenes and then for every test case, use primes from the list instead of recomputing.

Interesting Fact

This problem can also be approached as a challenge problem where we need to minimize the maximum value generated in sequence. Can you minimize? Say for $N = 50000$

Time Complexity

Time complexity is $O(MX*log(log(MX)) + \sum N)$ per test case where $MX$ is the upper limit till primes are found. Finding primes up to $10^6$ suffices for this problem.

AUTHOR'S AND TESTER'S SOLUTIONS:

Setter's solution
Tester's solution
Editorialist's solution

Feel free to Share your approach, If it differs. Suggestions are always welcomed. :)


EARTSEQ QUESTION

Invitation to CodeChef January Long Challenge 2019 sponsored By ShareChat

$
0
0

Happy New Year to the CodeChef community!

Celebrate the new year with CodeChef’s January Long Challenge 2019 sponsored by ShareChat. This programming contest lets you tackle 8 problems over 10 days and it’s open to programmers in every country and at every skill level. The contest problem statements will also be available in English, Hindi, Bengali, Russian, Mandarin and Vietnamese.

Participants will also have the opportunity to apply for jobs at ShareChat - India’s fastest growing social network. Visit the contest link for more details.

I hope you will join your fellow programmers and enjoy the contest problems. Joining me on the problem setting panel are:

I hope you will enjoy solving them. Please give your feedback on the problem set in the comments below, after the contest.

Contest Details:

Time: 4th January 2019 (1500 hrs) to 14th January 2019 (1500 hrs). (Indian Standard Time — +5:30 GMT) — Check your [timezone](https://www.timeanddate.com/worldclock/fixedtime.html?msg=CodeChef+January+Challenge+2019&iso=20190104T15&p1=44.

Contest link:https://www.codechef.com/JAN19

Registration: You just need to have a CodeChef handle to participate. For all those, who are interested and do not have a CodeChef handle, are requested to register in order to participate.

Prizes:

Top 10 performers in Global and Indian category will get CodeChef laddus, with which the winners can claim cool CodeChef goodies. First to solve each problem except challenge - 100 laddus. Know more here: https://www.codechef.com/laddu. (For those who have not yet got their previous winning, please send an email to winners@codechef.com)

Good Luck!
Hope to see you participating!!
Happy Programming !!

MGAME - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter:Smit mandavia
Tester:Xiuhan Wang
Editorialist:Taranpreet Singh

DIFFICULTY:

Easy

PREREQUISITES:

Modulo operator and Basic Combinatorics.

PROBLEM:

Given two integers $N$ and $P$, suppose the maximum value of $(((N \bmod i) \bmod j) \bmod k ) \bmod N$ be $M$ where $i, j, k \in [1, P]$, Find the number of ways to select $i, j, k \in [1, P]$ such that $(((N \bmod i) \bmod j) \bmod k ) \bmod N$ equals $M$.

SUPER QUICK EXPLANATION

  • The maximum value of $N \bmod x$ where $x \in [1,N]$, if $N$ is odd, is $(N-1)/2$ when $x = (N+1)/2$, and if $N$ is even, is $N/2-1$ when $x = N/2+1$.
  • We can achieve $(((N \bmod i) \bmod j) \bmod k ) \bmod N = M$ in three ways. Let $x = \lceil (N+1)/2 \rceil$
  • $i = x$ and $j,k > M$.
  • $i > N$, $j = x$ and $k > M$.
  • $i, j > N$ and $k = x$. Each of this case can be easily computed.

EXPLANATION

First of all, Let is find this value $M$. It has to be less than $min(i,j,k,N)$ which implies, $M < N$. Hence, if we want $M > 0$, we need $(((N \bmod i) \bmod j) \bmod k) < N$. So, We know for sure, that to maximize $M$, $min(i, j, k) \leq N$. Hence, we need maximum $(((N \bmod i) \bmod j) \bmod k) < N $ and now we can ignore the last $\bmod N$.

So, The maximum $N \bmod x$ can attain is $\lfloor (N-1)/2 \rfloor$. This happens when $x = \lceil (N+1)/2 \rceil$. It can be easily verified either by checking by hand, or writing a simple program ;)

Now, try finding out number of ways $(((N \bmod i) \bmod j) \bmod k)$ equals $M$. It can be approached in Simple case base analysis.

We can try all possible triplets of $(i,j,k)$ and generalize them into three cases.

  • When $i = \lceil (N+1)/2 \rceil$ and $j,k > M$
  • When $i > N$, $j = \lceil (N+1)/2 \rceil$ and $k > M$
  • When $i,j > N$ and $k = \lceil (N+1)/2 \rceil$

In all three cases, we can simply count the number of triplets $(i, j, k)$ satisfying any condition and print the answer.

Corner Case

When $N \leq 2$, $M = \lfloor (N-1)/2 \rfloor = 0$. This is because we cannot achieve $(((N \bmod i) \bmod j) \bmod k ) \bmod N > 0$. So, all triplets $(i, j, k)$ are valid.

Alternate solution - read at your own risk, you have been warned :D

For those curious enough not to be satisfied with such solutions, there also exists a pattern based solution too, using basic math. Just use brute solution to find the first terms of series and solve using the pattern formed. Number 6 is important. Enjoy :D

Time Complexity

Time complexity is $O(1)$ per test case.

AUTHOR'S AND TESTER'S SOLUTIONS:

Setter's solution
Tester's solution
Editorialist's solution

Feel free to Share your approach, If it differs. Suggestions are always welcomed. :)

Implementation of Dijkstra's Algorithm using set data structure in C++

$
0
0

I was trying to implement Dijkstra using set data structure in C++. I was coding in C++14 and there seems to be something out of order in the code for it is not giving me the right answer in Codechef IDE and on DevCpp it is not even compiling!

I believe the code is logically sound and there are only semantic errors in it.

Implementing Dijkstra using set in C++

RECTSQ, am I unable to understand?

$
0
0

https://www.codechef.com/problems/RECTSQ

My Code:

#include <stdio.h>

int ans;
int finder (int a, int b)
{
    if(b > a)
        {
            a += b;
            b = a-b;
            a = a-b;
        }

    int k = a/b;
    ans += k;
    if(a-(k*b))
        finder((a-(k*b)),b);
    else
        return 0;
}   
int main()
{
    int t;
    scanf(" %d",&t);
    while(t--)
        {
            int a, b;
            scanf(" %d%d",&a,&b);
            ans = 0;
            finder(a,b);
            printf("%d\n",ans);
        }
}

I know it is giving output as 3 even for the sample testcases given in the question, while the desired ones are 6 and 6. But I want to ask that if we have to return the minimum number of square plots then why is this incorrect? Take the first case 10, 15 for example, Square 1: 10x10 (5x10 remains from original 10x15) Square 2: 5x5 (5x5 remains from original 5x10) Square 3: 5x5 (Return to main)

So Minimum is 3 squares, why is 6 the answer? I think maybe I understood the question wrong, please help.

Thank You

KINGCON - Editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Jay Pandya
Tester:Hiroto Sekido
Editorialist:Anton Lunyov

DIFFICULTY:

EASY

PREREQUISITES:

Biconnected components

PROBLEM:

Getting rid of the story line the problem simply asks to find the number of articulation points in the undirected graph and multiply it by K.

EXPLANATION:

Naive approach would be for each vertex delete it from the graph and check the connectivity. Such approach has complexity O(N * M) and should get TLE. So something clever should be invented.

The problem could be solved using simple DFS in O(N + M) time. For this, some magic value low(v) is calculated for each vertex v and this allows to check whether v is articulation point in O(1) time inside DFS. The root of the DFS traversal tree should be analyzed in another way. Namely it will be an articulation point if and only if it has at least two sons in this tree.

But sincerely speaking biconnected components, articulation points and bridges is one of my unfavorite topics :)
So I prefer to forward you to some existing tutorials for further details of the mentioned approach:

  • Exercise 23-2 in famous book "Introduction to Algorithms" by Cormen and others.
  • The article on e-maxx.ru. It seems to be very well written but unfortunately it is only in Russian. But code there is working - I've checked and get AC here :) But be careful with IS_CUTPOINT(v); it could say this several times for the same vertex.
  • The article at Wikipedia. Unfortunately it contains no code snippets so it could be hard to learn this topic efficiently from there.
  • Yet another tutorial. It seems to be really good introduction to DFS and its applications with code snippets.
  • Several other tutorials: click, click, click.

Also I provide a lot of related problems on biconnected components, so don't blame me much for not writing yet another tutorial on this topic :)

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution will be provided soon.
Tester's solution can be found here.

RELATED PROBLEMS:

UVA - 796 - Critical Links
TJU - 2840 - Apple Tree
UVA - 610 - Street Directions
UVA - 10972 - RevolC FaeLoN
PKU - 3177 - Redundant Paths
Live Archive - 4186 - Lucky cities

Previous CCDSAP exam questions

$
0
0

Where can I find all the previously conducted CCDSAP exam questions?


How to implement Pair Class in Java?

$
0
0

Is there any inbuilt library for pair class in java like in c++? If not how to we implement pair class in java and how can we do pair sort with respect to the first element and pair sort with respect to the second element in java?

DPAIRS - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter:Noszály Áron
Tester:Xiuhan Wang
Editorialist:Taranpreet Singh

DIFFICULTY:

Easy

PREREQUISITES:

Sorting and maps and a nice Observation.

PROBLEM:

Given two sets of distinct integers $A$ and $B$. Choose $|A|+|B|-1$ pairs $(x,y)$ such that values $A_x+B_y$ for all pairs is pairwise distinct where $|X|$ means size of set $X$.

SUPER QUICK EXPLANATION

  • Simple way to find distinct $|A|+|B|-1$ values is to sort both $|A|$ and $|B|$ in ascending order, pair smallest element of one set with all element from the second set and largest element of the second set with all but first element of the first set. This way, we get $|B|+(|A|-1) = |A|+|B|-1$ distinct values which is what we want.
  • The reason these values are distinct is that $x+y < x+z$ if $y < z$. This is happening for all consecutive pairs generated in this manner. Indices can be taken care of using maps or arrays itself.

EXPLANATION

Subtask 1: $|A|, |B| \leq 10^3$.

Here, constraints are small enough to try each pair of elements in both sets, finding pairs having distinct values and printing $|A|+|B|-1$ pairs with distinct sums.

Subtask 2: $|A|, |B| \leq 2*10^5$

Now, we cannot iterate over every pair of values. We need to be smart.

Let us sort both sets in ascending order, and pair first element of $A$ with all elements of $B$, getting $|B|$ pairs. If the first element of $A$ is $x$, Sum of these $|B|$ pairs is pairwise distinct as the set of sums of these pairs is nothing but all values of $B$ increased by $x$.

Now, suppose $y$ is the largest value present in $B$ and $z$ be second value in $A$. Since $z > x$, we have $y+z > y+x$. So, we can now pair the second element of $A$ with the last element of $B$ to get a distinct sum value.

This way, we can continue to pair all values in $A$ with the largest element of $B$ (except first, as it is already paired), getting $|A|-1$ more pairs.

Hence, we have got our required $|A|+|B|-1$ pairs. Indices can be preserved using maps, or arrays itself.

Want to solve it faster? See the box below.

View Content

Exercise:

Prove that the minimum number of pairs that can be generated having distinct sums is $|A|+|B|-1$ irrespective of the value present in set $A$ and $B$ have distinct values.

Also, Generate a large test case where this minimum value is achieved. (Hint in box)

View Content

Time Complexity

The time complexity is $(|A|*log(|A|)+|B|*log(|B|))$ due to sorting.

AUTHOR'S AND TESTER'S SOLUTIONS:

Setter's solution
Tester's solution
Editorialist's solution

Feel free to Share your approach, If it differs. Suggestions are always welcomed. :)

Invitation to CodeChef January Cook-Off 2019 sponsored By ShareChat

$
0
0

Greetings CodeChef community!

I invite you to participate in CodeChef’s January Cook-Off 2019 sponsored by ShareChat*. This short contest lets you solve 5 problems in 2.5 hours. The contest problem statements will also be available in English, Hindi, Bengali, Russian, Mandarin and Vietnamese. This contest is open to programmers of all ages and skill levels across the world.

All participants of the Cook-Off will be eligible to apply for jobs at ShareChat - India’s fastest growing social network. Visit the contest link for more details.

I hope you will join your fellow programmers and enjoy the contest problems. Joining me on the problem setting panel are:

I hope you will enjoy solving them. Please give your feedback on the problem set in the comments below, after the contest.

Contest Details:

Time: 20th January 2019 (2130 hrs) to 21st January 2019 (0000 hrs). (Indian Standard Time — +5:30 GMT) — Check your timezone.

Contest link:https://www.codechef.com/COOK102

Registration: You just need to have a CodeChef handle to participate. For all those, who are interested and do not have a CodeChef handle, are requested to register in order to participate.

Prizes:

Top 10 performers in Global and Indian category will get CodeChef laddus, with which the winners can claim cool CodeChef goodies. Know more here: https://www.codechef.com/laddu. (For those who have not yet got their previous winning, please send an email to winners@codechef.com)

Good Luck!
Hope to see you participating!!
Happy Programming !!

Regarding JavaFX Library error.

$
0
0

when we import JavaFX library in codechef IDE.

it was showing a syntax error.

How can we rectify this one??

Need your help! YVMUN

$
0
0

I cant understand why i am getting wrong answer in YVNUM. I matched all testcases and corner cases that i can think of ..with the testers solution and my solution ..all are hiving same answer..therefore i request u to guide me where i am getting wrong .given below is the ideone link of my code please do check https://ideone.com/e.js/GrO14s"

Viewing all 39796 articles
Browse latest View live


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