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

ZCO 2019 Discussion

$
0
0

I've attached a spreadsheet for ZCO 2019 Scores. Please update this Spreadsheet after you finish the ZCO 2019 Contest. Solutions can be discussed here after the contest. :-)

Click the below link to access the spreadsheet.

ZCO 2019 Scores Spreadsheet Link

Important Notice: This is not an OFFICIAL Ranklist. It is for discussing and estimating cutoffs for ZCO 2019 amongst the participants before the Official Results are announced by the Organizers of ZCO 2019.


How to prevent our code from exceeding time limit in python 3.6?

$
0
0

Also 1 more question: I have only given 15 points out of 100 in contest. Why is it so?

Why is codechef copying questions from other websites for long challenge?

$
0
0

I found a exactly same to same question of codechef long in one of the site(sry cant tell the name). Why can't it bring new questions?

NZEC Error in python

$
0
0

My python(3.6) Code always gives NZEC error when i try to accept input for testcases. (i use input()) How do i resolve this error?

COMPILER - Editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Bruno Oliveira
Tester:Sergey Kulik
Editorialist:Lalit Kundu

DIFFICULTY:

EASY

PREREQUISITES:

AD-HOC

PROBLEM:

Given a bracket sequence, print the length of largest prefix that is a regular bracket sequence.

EXPLANATION:

A regular bracket sequence is defined as follows:
1. S="" is regular.
2. S="<" + S1 + ">" is regular, if S1 is regular.
3. S=S1 concat S2 is regular, if S1 and S2 are regular.

If S is regular bracket sequence, for any i, number of closing brackets in S[0,i] should not exceed number of opening brackets. Also, if number of opening brackets is equal to number of closing brackets in S[0,i], S[0,i] is a regular bracket sequence.

def check(s):    
     t=0,ans=0    
     for i=0 to N-1:    
          if s[i]=='<': t++;   
          else:    
               t--;    
               //Now, if t=0, means, the string s[0,i] is valid.    
               if t==0: ans=max(ans,i+1)   
               else if t<0: break   //string s whole is invalid.    
     print ans

Complexity: O(N).

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution
Setter's solution

Invitation to CodeChef February Long Challenge 2019 sponsored By ShareChat!

$
0
0

Greetings CodeChef community!

Come participate in CodeChef’s February Long challenge sponsored by ShareChat. This is a 10-day contest that invites participants to solve 7 problems and 1 tie-breaker style challenge problem. The contest is open to programmers of all skill levels. The contest problem statements will be available in English, Hindi, Bengali, Russian, Mandarin and Vietnamese.

Participants of Long Challenge also have an opportunity to apply for job openings at ShareChat - India’s fastest growing social network! Visit the contest link to know more.

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: 1st February 2019 (1500 hrs) to 11th February 2019 (1500 hrs). (Indian Standard Time — +5:30 GMT) — Check your timezone.

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

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 !!

CHFAR - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest

Setter:Misha Chorniy
Tester:Hasan Jaddouh
Editorialist:Taranpreet Singh

DIFFICULTY:

Simple

PREREQUISITES:

Basic Math.

PROBLEM:

Given a sequence $A$ of length $N$, by changing at most $K$ elements, can we make $A_1^2+A_2^2+A_3^2 \dots A_N^2 \leq A_1+A_2+A_3 \dots A_N$?

SUPER QUICK EXPLANATION

  • Count number of $A[i] > 1$, say $C$. If $C \leq K$, we can achieve inequality, otherwise no.

EXPLANATION

First of all, It can be seen that for every integer $X$, $X \leq X^2$. So, we can prove that we can never achieve $A_1^2+A_2^2+A_3^2 \dots A_N^2 < A_1+A_2+A_3 \dots A_N$.

Only option is, to achieve $A_1^2+A_2^2+A_3^2 \dots A_N^2 == A_1+A_2+A_3 \dots A_N$.

Now, Let's find all integers, for which $X^2 == X$. We can find, that This holds for only $X = 0$ and $X = 1$. But we can assign only positive values to elements. Hence, to achieve this inequality, we need all elements to be 1.

Hence, just count the number of elements greater than 1 and if this count is $\leq K$, we can achieve this inequality, otherwise, we cannot achieve.

Challenge

Find any real value for which $X^2 < X$. Enjoy solving. :P

Time Complexity

Time complexity is $O(N)$ 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. :)

plagiarism in Quark-Codejam


Can anyone provide editorials for QCJ03 and QCJ04 ?

$
0
0

Can anyone provide editorials for QCJ03 and QCJ04 ?

DUNDRG - Editorial

$
0
0

#PROBLEM LINK:

Practice : Click
Contest : Click

Author:Soham Chakrabarti
Tester:Arkapravo Ghosh
Editorialist:Soham Chakrabarti

#DIFFICULTY:

Cakewalk

#PREREQUISITES:

Primes, Time to think

#PROBLEM:

Again a problem!

Agniva is trapped inside the Dungeon and is about to be executed by the king of NumberLand.
Dotionmo, zoindrek and Pavo has travelled across 2 cities to help Agniva get out of this trouble. They have almost reached Agniva, when suddenly, the king of NumberLand surprises them with another trap.
"Hahahah! You Fools.", he says.

"You have only 5 minutes to solve my puzzle, and it will be very very HARD.
Once you solve the hardest problem of NumberLand, we will release Agniva."

The problem statement:

  1. Agniva will be provided N cards in a bag.
  2. Every Card will have a number from 1 to N (inclusive).
  3. Agniva will pick a card at random from the bag, without looking at it (lets call it 'x'). Note :: He has to read all the cards from the bag.
  4. You will decide if the number 'x' has exactly 3 divisors. If true, shout 'YES'.
    and "Remember!", says Mr. Soham.
    "The number x is divisible by '1' and the number 'x' ."
    "I will keep a count of the number of times, you say the words 'YES'", says Mr. Soham.

The friends don't want dragons after them. Help them :P

#EXPLANATION:

We can solve this problem by finding the primes using a seive. Square all primes till the squared value is less than N.
Keep the count. Print it.

#AUTHOR'S AND EDITORIALIST'S SOLUTIONS:

Author's and editorialist’s solution can be found (here).

adakng Problem

$
0
0

// Can some one please look into my code snippet for the ADAKNG Problem // and point out why my code is not accepted . The code is in C++ //Thank you.

`#include <iostream> using namespace std;

int main() { int t,r,c,k; int y; int dr,ur,fc,bc; / dr = lower_most_row ur = upper_most_row fc = right_most_column bc = left_most_column / int no_of_squares;

dr = 0;
fc = 0;
ur = 8;
bc = 8;

cin>>t;

while(t--)
{
    cin>>r>>c>>k;

    for(y=k;y>=0;y--)
    {
        if( (1 <= (r+y)) && ((r+y) <= 8) )//if the row exists
            if((r+y) > dr)// if the new value is lower than current row
                dr = (r+y);

        if( (1 <= (r-y)) && ((r-y) <= 8) )// if the row exists
            if((r-y) < ur)// if the new value is higher than current row
                ur = (r-y);

        if( (1 <= (c+y)) && ((c+y) <= 8) )//if the column exists
            if((c+y) > fc)// if the new value is more right than current column
                fc = (c+y);

        if((1 <= (c-y)) && ((c-y) <= 8))//if the column exists
            if((c-y) < bc)// if the new value is more left than current column
                bc = (c-y);

    }

    no_of_squares = (dr - ur + 1) * (fc - bc + 1);
    cout<<no_of_squares<<"\n";
}
return 0;

} `

WA in Maximise the Sum(NOMATCH)

Taking Query And Flushing in C++

$
0
0

Can anyone tell me how to make query and flush the output in C++.

I haven't done this before.

So , please kindly answer my question.

Thank's

:)

Different Ranks for Same Marks in Long Challange

$
0
0

Hi,

I am very disappointed today
I am a division 2(Rating) coder.
I was at third rank and when I saw ranklist I got disappointed.
I saw the name of the users with same marks and different rank by which my rank has gone to fifth (India , School) in division B.

Note : Long challenge do not consider the WA submission (The best submisions are only considered)

Ranklist of division B

Please let me know what is this going on.
:(

TestCaseForRunningContest

$
0
0

Hello,

can I get few test cases for running contest?

regards, Ankit


ATM: need help with "Wrong answer"

$
0
0

I am getting "Wrong answer" after submission. But I can't find any combination of X and Y..all the combinations I tried locally returned the same error that passed the submit test. Please help.

def atm(withDraw, balance):
    fee = 0.50
    if withDraw % 5 != 0 or balance < (withDraw + fee):
        return balance
    else:
        return balance - (withDraw + fee)

def main():
    try:
        w,b = input().split(" ")
        w = int(w)
        b = float(b)
        balance = atm(w,b)
        print(balance)
    except:
        pass

if __name__ == "__main__":
    main()

What Does Negative TLE Means?

$
0
0

I am doing codechef Manhattan Rectangle problem and after submitting my solution I got TLE of (-1.0000 sec ??).I have seen this time limit first time.

Can anyone tell me what does that mean?
:(

Python, Error while taking input

$
0
0

I have been working with Python 3 for quite a while, however, I am new to CodeChef. I have tried to solve quite a few practice problems using CodeChef IDE. However, every time I try to run it, I get the following error.

Traceback (most recent call last):
File "./prog.py", line 1, in <module>
EOFError: EOF when reading a line

I try running the same code with custom input and it works perfectly. The first line of my code, where the error occurs is the following:

t = int(input())

  1. I have checked the version, and it is Python 3 only. Hence, there is no problem with input()
  2. The first line of input is a single integer, hence, converting the string into int should not be an issue. For more details, i am sharing the link to the problem as well which I am trying to solve. Link: here

I also tried the following:

import sys
inp=sys.stdin.read()
print(inp)

In this case, the output was nothing. Can someone help me out with what the problem is actually?

HP18 - EDITORIAL

$
0
0

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter:Hruday Pabbisetty
Tester:Xiuhan Wang
Editorialist:Taranpreet Singh

DIFFICULTY:

Simple

PREREQUISITES:

Game-Theory and Basic Math would do.

PROBLEM:

Given an array $A$ containing $N$ elements, on which Bob and Alice are playing a game with Bob playing first, both of them having lucky numbers $a$ and $b$ respectively. In one move, a player can remove any number of elements from the array $A$ which are divisible by their lucky number. The player unable to remove any element loses the game. Find winner of the game if both players play optimally.

SUPER QUICK EXPLANATION

  • If $A$ contains elements which are divisible by both $a$ and $b$, It is optimal for Bob to delete all such elements in the very first move. Turn goes to Alice.
  • Now, it is optimal for both players to remove exactly one number they can remove, until one of the players is unable to make a move, thus losing the game. The number of moves Bob can make is Number of elements divisible by $a$ after deleting numbers divisible by both $a$ and $b$. Same way for Alice.

EXPLANATION

First of all, let us classify the numbers present in the array into four categories.

  • Numbers divisible by both $a$ and $b$.
  • Numbers divisible by $a$ but not $b$.
  • Numbers divisible by $b$ but not $a$.
  • Numbers not divisible by $a$ or $b$.

Let Number of elements of the second type be the number of reserve moves of Bob and Number of numbers of the third type be Number of reserve moves of Alice.

Since Bob is having the first move, it is ideal for Bob to remove all elements of the first type in the first move itself to force Alice to use reserve move in next move, if the array contains any number of the first type. This is because if after Bob's move, if there are any number of the first type present in the array, Alice can remove all of them, forcing Bob to use his reserve move in next move.

Now, the player having lesser reserve move loses since that player shall run out of moves. In case both players had the same number of reserve moves, the player first to move shall lose (After removing numbers of the first type).

It can be easily implemented by making two counter variables counting reserve moves of each player, and a flag determining whether there are any numbers of the first type in the array.

Time Complexity

Time complexity is $O(N)$ 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. :)

Regarding Submission(NZEC)

$
0
0

import java.util.; import java.lang.; import java.math.BigInteger; import java.io.*; class Codechef{ public static void main (String[] args) throws java.lang.Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); for(int i=0;i<t;i++){ String s = br.readLine(); String[] st = s.split(" "); BigInteger r=new BigInteger(st[0]); BigInteger m=new BigInteger(st[1]); BigInteger n=new BigInteger(st[2]); BigInteger k=new BigInteger(st[3]); BigInteger p=r.divide(m); BigInteger q=r.divide(n); BigInteger e=n.multiply(m); BigInteger f=r.divide(e); BigInteger y=p.subtract(f); BigInteger z=q.subtract(f); BigInteger x=y.add(z); if(x.compareTo(k)<0) System.out.println("Lose"); else System.out.println("Win"); } } } This code runs on my ide but it throws an exception(NumberFormatException)on the codechef ide.Please help me solving this problem.

Viewing all 39796 articles
Browse latest View live


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