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

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


Is there any formula to calculate nth fibonacci number ?

$
0
0

Suppose we are given, a(0)=x ; a(1)=y

and the relation, a[i]=a[i-1]+a[i-2]

and , we are asked to calculate a(n) , how to calculate it if n is as big as 10^9 ?

Thanks ! :-)

EARTSEQ QUESTION

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

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 nor how to we implement pair class in java and how can we do pair sort with respect to first element and pair sort with respect to second element in java?

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

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

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"

GMEDIAN - Editorial (Unofficial)

$
0
0

PROBLEM LINK:
Div1
Div2

Setter:Teja Vardhan Reddy
Editorialist: Utkarsh Pandey

DIFFICULTY:
EASY

PRE-REQUISITES:
Observation, Binomial Coefficients.

PROBLEM:
Given a sequence A1,A2,…,AN. Find the number of subsequences in which the median of the subsequence is present in that subsequence, modulo 1000000007.

Explanation
Since we have to sort each subsequence to find its median, we will sort our original sequence (i.e. A1,A2,…,AN) at first itself. The ordering won't change.
For example, the good (desired) subsequences in the sequence [9,5,7,6,8,1] are same as that in the sequence [1,5,6,7,8,9].

The subsequences having odd length will definitely qualify to be one of our good subsequence (as in the subsequences with odd length, the element at the middle position is the median of the subsequence itself).

The subsequences with even length will qualify as good subsequence if and only if the middle two elements are same. It is so because the array is already sorted. View the content below in case you didn't understand this statement.

View Content

So our answer to this problem is : (Number of subsequences having odd length) + (Number of good subsequences having even length with both the middle elements equal)

First Subtask:
It is clearly written in this subtask: A is a permutation of integers 1 through N. Also, the number of elements in the sequence A is N which means each element from 1 to N is present once and only once. This tells us that there is no repetition of any number. So, no subsequence having even length will be counted.

So, answer to this subtask = Number of subsequences having odd length
= Number of ways of selecting 1 out of n elements + Number of ways of selecting 3 out of n elements + Number of ways of selecting 5 out of n elements + ............. + Number of ways of selecting n or (n-1) out of n elements

$=nC1 + nC3 + nC5 + ..... + nCn$ (if 'n' is odd) or $nC1 + nC3 + nC5 + ..... + nC(n-1)$ (if 'n' is even)
where nCx denotes the number of ways of choosing x elements out of n elements

= 2^(n-1) See the proof below if you didn't understand this completely Proof:

View Content

Second and Third Subtask:
The tricky part of this question is when the elements in the sequence starts repeating. In this case, we have to find the number of subsequences having even length. To find the subsequences of even length to be a good subsequence, we traverse through each element which is repeated at least once. For this element to be our median element in one of the subsequences of even length, we must have at least k elements at its index's left and we must have at least k elements at the other element index's right (Note that our array was sorted), where k is a non-negative integer.
An example is provided in the section below in case you didn't understand the lines written above:

View Content

Now, Calculating nCx in each iteration, we may have difficulties passing the time limit provided in the problem. To reduce the time complexity to pass the given time limit, we have to observe the given fact:

Let the repeating elements be found at index i and j Suppose, there are m elements at the left of the index i and n elements at the right of index j.

So, number of good subsequences: 1 (good subsequence of length 2) + $mC1 * nC1$ (good subsequences of length 4) + $mC2 * nC2$ (good subsequences of length 6) + ........... + $mCmin(m,n) * nC(min(m,n))$.

By Vandermonde's identity we can sum up this value as (m+n)C(min(m,n)), details of which can be found here :Vandermonde's Identity.

Bonus: Calculating queries of the type nCr % 1000000007 can be solved by precalculating $nCr % 1000000007$ upto n = whatever you need :p . Details of this can be found here: nCr % p in O(1)

Time Complexity = O($N^2$) (Enough to pass all the subtasks)

Editorialist's Solution:https://www.codechef.com/viewsolution/21611480

GetCode Codechef/Codeforces/SPOJ plugin for Sublime Text 3

$
0
0

GetCode

This is an ST3 plugin which:

  1. Take the URL of a problem such as https://www.codechef.com/problems/INVLIS.
  2. Parse the URL and get the problem code(In this case it is INVLIS).
  3. Create a new .cpp or .py file with a pre-determined template(cpp.snippets which is customized via settings).

Keyboard shortcuts

For all Operating Systems, ctrl+alt+x opens a new dialogue box which takes the problem url as user input

How to install

  1. Install Package Control from here
  2. In Sublime, Open Package Control

Open Package Control from the Preferences Menu

  1. Select Package Control: Install Packages

enter image description here

  1. Now you should be able to search for and install the GetCode Package.

How to use it

After installing, it is necessary to configure the settings(setting the default directory and snippets).

After configuring the settings, ctrl+alt+x opens a new dialogue box which takes the problem url as user input

Supported websites(for now)

  1. Codechef
  2. Codeforces
  3. SPOJ
  4. Virtual Judge

Invitation to RATED Contest(Div1+Div2) Enigma on Codechef, 10 January 2019

$
0
0

Hello, CodeChef community,

Tired of searching for the perfect teammates in every competition? Want to prove your worth as a solo coder? Looking for the perfect platform to display your skills?

This solo coding competition is designed for the masterminds who think they perform best alone.

Interested? Wanna find out more about it? No Problem! Plinth in association with Aavas Financiers Limited has a rated contest on CodeChef waiting just for you!

The contest shall be a great opportunity for students to test their programming aptitude. This national level programming contest shall assess the intelligence of participants through various rounds. It is an Online Qualifier Round for the Onsite Round to be held during Plinth'19.

There will be 2 rounds to decide the winner:

First Round: Online Qualifier for onsite will be held on 10th January 2019 on Codechef which is a rated round(Div1+Div2).

Second Round: Onsite round will be held at The LNM Institute of Information Technology, Jaipur on 20th January. More details will be announced later.

The Contest details of Enigma'19 are as follows:
- Contest duration will be 3 hours.
- Solo Coding Event
- Start time: 10th January 2019, 21:00 hrs IST
- End time: 11th January 2019, 00:00 hrs IST

Contest Link: Click Here

Problem Setters: panikxodiacaditya10_tds115

alt text

Good Luck and have Fun!

Getting java NZEC error on codechef compiler

$
0
0

Guys i am trying to solve the DAG Delete problem of December contest. My code runs perfectly fine on my computer and i have tested it for multiple cases. I have also made sure that everything is properly initialized and checked for corner cases too. Earlier i was using too much memory and even that is not the case now. Please tell me what are the not so common reasons where you people got Run Time Error or how should i proceed with debugging my code.

Best Regards

Why doesn't Codechef put editorials of all problems !

$
0
0

Is there nobody answerable to providing editorials of contest problems. Let go other open and unrated contests, we are talking about monthly rated contests. Several times the editorials don't appear not even the unofficial ones, particularly to tough problems. Besides, not to ignore the fact that for even the other problems it takes a minimum of 3 days to put the editorials.

https://www.codechef.com/LTIME67A/problems/NOSS

Come on Codechef, this hasn't happened the first time.


MySql database creation

$
0
0

Need help how to create database in mysql via chef .Iam able to install mysql and now i need to create database i don't know the syntax how to create database.Thanks .

DIFNEIGH - 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:

Pigeonhole principle, Constructive algorithms and Case-based Analysis.

PROBLEM:

Given two integers $N$ and $M$, find out any matrix with $N$ rows and $M$ columns using as less distinct numbers as possible, such that for all cell, all values of neighbors of that cell are pairwise distinct.

SUPER QUICK EXPLANATION

  • In all cases, it can be seen that if $K$ is the maximum number of neighbors for any cell, It is not possible to have any valid table using less than $K$ distinct numbers due to Pigeonhole principle.
  • Turns out, it is always possible to make a valid table using $K$ numbers. One possible construction is noticing that ith position in the row should have values different than (i-2)th position and (i+2)th position in the same row. Same goes for columns. Constructions exist based on this condition only.

EXPLANATION

Considering a $N*M$ table, we can see that if the maximum number of neighbors any cell has in a table is $K$, there cannot exist any valid table using less than $K$ distinct values. The reason is, that if we take $K$ values out of distinct $ < K$ values, It is guaranteed to have at least one value occurring more than once, which means that the values of neighbors of that particular cell are not pairwise distinct. Hence, the table is invalid. Refer Pigeonhole principle for proof.

Thus, we need to find a way to fill the table using $K$ values.

General case

In general case where we have $K = 4$, occurs when both $N, M \geq 3$.

Here, in every row or column, we need the first element to differ from the third element in the row, the second element should differ from the fourth element, the third element should differ from the fifth element and so on. If we choose the fifth element to be the same as the first element, it shall make no difference.

It is recommended to try a few ways to fill a $4*4$ table and then trying to extend it either way.

Here, it is possible to have different constructions than the one mentioned here, so feel free to share yours.

One possible way to fill a $4*4$ table is

1 1 2 2 3 4 4 3 2 2 1 1 4 3 3 4

Now, it can be easily seen, that we can just keep appending rows and columns without causing any conflict for any cell, thus efficiently generating our table.

View Content

Special cases

Assuming $N \leq M$. Values $N$ and $M$ can be swapped if otherwise.

  • If $N$ equals one. Here, if $M \leq 2$ each cell has at most one neighbor, and thus, we can just assign 1 to both cells. If $M > 2$, we need the first element to differ from third, second from fourth and so on. So, we can just assign the first four values as 1 1 2 2 and from the fifth element, ith value is assigned same value as (i-4)th element.

  • If $N$ equals two. Here too, if $M == 2$, valid table exist with $K = 2$. Otherwise, we need at least three distinct values. A simple construction being ith element in both rows being assigned as (i-3)th element, first three elements being 1 2 3.

This covers all cases where $K < 4$. All other case have $N, M \geq 3$ which implies $K == 4$ as seen above.

Time Complexity

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

Help for SEACO

$
0
0

hi , i am not able to find out whats wrong in my solution for the problem "Sereja and Commands"(https://www.codechef.com/problems/SEACO ) . I am implementing a fenwick tree approach , in which i am applying all the commands of type "1" in my array a all commands of type "2"are pushed in a vector, then i am traversing the vector from back and implementing all the commands of type "2" on another BIT one by one .The second BIT is used for storing the count of all the commands with particular index , then finally implementing all the commands of type "1" on my array a . map 'c' and 'd'are used for the storing the type and range of the a particular command respectively. I checked in the editorial discusions that my approach is correct but not able to find the error in my code. my submission link (https://www.codechef.com/viewsolution/22518842 )

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

Viewing all 39796 articles
Browse latest View live


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