Quantcast
Viewing all 40121 articles
Browse latest View live

MULTQ3 - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

MEDIUM

EXPLANATION

The problem can be solved using segment trees. Every node of the tree stores the following data :

1) tree0[k] : In the range [low..high] covered by this node, how many numbers are divisible by 3 considering just additions performed on numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2
2) tree1[k] : In the range [low..high] covered by this node, how many numbers leave a remainder of 1 when divided by 3 considering just additions performed on numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2
3) add[k] : What is the quantity which is added to all numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2


Is it necessary to add a reserve member to your team(ACM ICPC)?

Is it necessary to add a reserve member to your team or is that optional? Also how long does it take after you fill up the form about payment details on the Amritapuri Site to be reflected into the Baylor Site(Pending to Accepted)?

NO PARTICIPATION

My account always shows no participation. I did participated in LOCSEP17 and CNES2017 but it still shows no participation in any of the contest...Global and Country rank both are 0..HELP ME OUT..

How to Improve coding Proficiency?

Can Someone Guide how to improve coding proficiency and gain ability to solve hard or challenging problems in codechef.

string to number

You need to pass a secret key to your friend, which consists of all numbers but you don't trust the carrier. So, instead you pass a character string. You come up with a set of rules to map the string to the original key.

  1. Each character in the string should be replaced as the rule suggests.

  2. If the right hand side of the rule is a character, then this character should again be replaced till we find a number. The range of the numbers lies between 1 and 9.

  3. If no such number could be found but a cycle is detected, each such character should be replaced with 0. Note that this includes numbers which map to themselves (self loops).

  4. If no cycle is detected and no number replacement could be found, you should output -1.

  5. If a character appears in the test string which does not appear in the mapping, output -1. Input

First line of input contains a single integer T, the number of test cases. T test cases will follow. Each test case begins with a mapping. A mapping begins with a number N, the number of rules. Then N lines, each line in the form of A B will follow, where A is to be replaced by B. Then follows an integer K, the number of test strings. Then K lines follow, each line consisting of a test string. Output

For each test case, print on the first line # followed by the test case number, followed by the replacement string for every test string. Solution Templates

In the solution templates provided, complete the function whose signature is

C / C++ void decode (int n, char orig[26], char mapped[26], int k, char inputs[32][128], char outputs[32][128])

Java public static void decode(int n, char[] orig, char[] mapped, int k, String[] inputs, String[] outputs)

'n' is the number of mappings. 'orig' and 'mapped' store the original and mapped values respectively. 'k' is the number of queries. 'inputs' are the encoded strings. It is expected that you will store your answers in 'outputs', which is then printed by the template. Note that in JAVA, do not allocate outputs. It will be allocated, and hence put your answers in outputs.

Note: You are allowed to edit the code as you please. Add / delete headers. Add / delete methods. And so on.. So long as your final code solves the problem with Input and Output as described above. You may submit your own code, without using the template at all. Constraints

1<=T<=100 1<=N<=26 The left hand side of the rule consists of a single lowercase character The right hand side of the rule consists of a single lowercase character or a single non zero digit. No character will map to more than one character, i.e. you cannot have a situation where a maps to both b and c.

Sample Input

1 10 a b b c c a d e e f f 9 g h i j j 7 k p 3 abcdefij kabc aza

Sample Output

1

00099977 -1 -1

Explanation

String 1:a, b, and c form a cycle, and d maps to e, which maps to f, which maps to 9, and i maps to j, which maps to 7.

String 2: k maps to p, which maps to no nothing else. Hence -1.

String 3: The character z doesn't appear in the mapping. Hence -1.

FRUITS - Editorial

PROBLEM LINK:

Practice
Contest

Author:Sunny Aggarwal
Tester:Vasya Antoniuk
Editorialist:Pushkar Mishra

DIFFICULTY:

Cakewalk

PREREQUISITES:

Ad-hoc

PROBLEM:

Given are the number of apples ($N$) and oranges($M$) and $k$, i.e., the amount of money that chef has to buy apples/oranges. Each orange/apple costs 1 unit. What is the minimum difference that can be achieved.

EXPLANATION:

The problem is a very direct one. We have to minimize the difference. We can only increase the number of apples or oranges that we have. The logical step is to increase that commodity which is less because increasing the which is already more will only increase the the difference. Let $minC$ denote the quantity which is less. Let $maxC$ be the quantity which is more. The answer is given by:

$ans = maxC - min(minC+k, maxC)$

We have a min operation in the second term because the optimal case is to make both the quantities equal. If we have enough money to increase the lesser one to more than the other one, then we would rather make them equal so as to have a difference of zero, which is optimal.

COMPLEXITY:

$\mathcal{O}(1)$ per test case.

SAMPLE SOLUTIONS:

Author
Tester
Editorialist

THERE SHOULD BE AN OPTION TO REFER OR ASK QUESTION TO SOMEONE SPECIFIC

Since from my past days experience on discuss forum many time there comes some questions which are either out of their coding bounds of present time actives or they don't care to give time as they can answer multiple questions in the same time to cultivate karmas just as an example , I was asking a solution or hint of a problem (CDMN17C) I asked it twice and it been more than a week but till now nobody answered or not being able to answer. I also find many questions which were out of my present scope so I just pass over them but if there is any referring system at least I can refer problems to some better coders than me. Also take it as a request don't drop shitty comments about my first line Bro you are generalising your thought you shouldn't as I already mentined it as a thought . Problem link link text

What's wrong with this CODE (TTENIS)

Here is my code: Solution
The expected output is also produced and the limits of the variables is also satisfied. The output format is also correct. Is it that we don't have to print leading zeros? Please help me with the code.
Thanks a lot!


First Google Your Doubt Then Codechef Discuss

I have seen many person who are just posting questions which have a direct link on one google search.

1) If there is a direct link for that question then asking that question is not very helpful.

2) If there has already been a discussion for that topic in codechef discuss then don't make a new question for that ,instead comment in the previous post only.

3) Also don't ask any question related to an ongoing contest.

solution to question, that how to reverse the string from any point, in java

To print any type of string in this order example " My Name Is" output should be in this format " yM emaN sI" every word in the string has to be reversed individually.

Invitation to ICO practice contest 1

Hello, everyone. I would like to invite you to the first contest of the ICO prep series.

Problem Setters: Udit Sanghi, Shashwat Goel, Istasis Mishra
Problem Tester: Udit Sanghi
Editorialist: Shashwat Goel

It will be held on 13th October from 8:00 pm to 11:00 pm IST. Link - Contest

The contest will be unrated. Hope you like the problems. There would be 4 problems and 3 hours to them. The problems difficulty would be around CF Div2 B-C-C-D.

Also, the editorials will be published soon.

Please ask your doubts below.

CHMOD - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

PREREQUISITES

Simple Math, Repeated Squaring

PROBLEM

You are given a list of N integers.

Each value in the list is between 1 and 100.

You have to respond to T queries of the following type

  • Given L and R
  • Find the product of all integers in the given list between L and R, inclusive
  • Find the above product modulo some M, which is also given

EXPLANATION

For each query, iterating through the list between L and R to maintain the modular products is too slow.

Of course, we use the fact that each value is between 1 and 100 to our advantage.

  • There are 25 prime numbers between 1 and 100

Each number has a unique prime factorization. The product of a set of numbers can also be simulated by adding up the frequencies of each prime in all numbers in the set.

For example, suppose we have to multiply 36 and 45.

36 = 2232
45 = 325

36 * 45 = 22345

Thus, we can maintain a table of cumulative frequencies for each of the 25 primes between 1 to 100 for the given list of numbers.

When processing a query

  • consider each of the 25 primes
  • find the frquency of the prime between L and R. This can be done in O(1) using pre-calculation of cumulative frequencies
  • calculate primefrquency for each prime and multiply these values
  • maintain the result modulo M

These ideas are best presented in the pseudo code below.

PSEUDO CODE

Given:
    N, the number of numbers
    L[N], the list of numbers
    P[25], primes between [1, 100]
    CF[N,25], cumulative frquency for each prime

for each query Given Query: left, right, M answer = 1 for i = 1 to 25 r = CF[right,i] - CF[left-1,i] v = P[i]r % M, use repeated squaring answer = (answer * v) % M

The complexity of answering each query would be O(25 log N).

Cumulative Frequencies can be calculated in O(25 * N).

CODING COMMENTARY

You can either calculate the primes in thr porgram or hard code the array of primes by calculating it offline.

The repeated squaring should take care of the fact that the exponent can be 0. a0 should return 1 for any a.

Calculating the cumulative frequencies table should be done carefully. The frequencies of the primes for each number between 1 and 100 can be pre-calculated. Use these frequencies to build the cumulative frequencies table.

SETTER'S SOLUTION

Can be found here.

TESTER'S SOLUTION

Can be found here.

Is there any option to check for exactly which testcase our programs is giving wrong answer.?

I am new to programming on CODECHEF. I am experiencing this problem in which my program runs perfectly for the given test cases in questions but says wrong answer while submitting. I want to know is there any way to find out for exactly which test case my program is failing?

Ratings for Institutes In Competetive Programming (CpCtrl.com)

Hello Everyone,

Codechef has been a great platform for motivating and guiding potential competitive programmers on the individual basis. Ratings for all the contests: Long, Short and Lunchtime keep the sense of competition ongoing.

To provide and promote competition on the institution level, I designed a rating list provides unofficial ratings for all institutes ln the basis of Long contests of Codechef. Check it here.

The rating system works on the basis of ELO rating system. For more information about the entire rating system, please check this.

This rating system is entirely unofficial but does motivate the performance on institute level.

Future Additions to the Website:

  • Rating System for Short and Lunchtime challenges.
  • Full Event description regarding total participants and submissions grouped into colleges.

Any more inputs would be most welcomed from all programmers to improve this platform.I hope you all like it.

Edit- Now you can check ratings for cook-off events also.

Doubt regarding ACM ICPC Regionals

Is it possible to change site for ACM ICPC regionals? My team has been registered by the coach but still we have not paid onsite fees.


submission info not found while submitting problems in practise session

I have submitted the same solution given herein on of the editorial(https://discuss.codechef.com/questions/110979/unofficial-editorial-seaco-and-fill-matrix-briefly), but it doesn't show submission info when I submit it?

Here is the link to the same where I submitted (https://www.codechef.com/viewsolution/15470300 ) This is because if I don't get submission info, how can I get to know whether I got partial marks or not? Here is another submission I found where the submission got partial marks (https://www.codechef.com/viewsolution/15418126 ).

Your Best Rank In Codechef ..!!

Just as codechef shows our highest rating on codechef ,similarly our best rank sholud also be displayed there.

Invitation to KJSCE CodeSpree 2017

KJSCE Codecell presents CodeSpree, with CodeChef as Programming Partner.

Contest will last for 3 hours. It will be an ACM-ICPC style contest. It will start on 1st October 2017 at 21:00 hours IST.

Anyone can participate in this contest. This is a part of Abhiyantriki, technical fest of KJSCE.

Prizes worth 2000/- and laddus are up for grabs.

Contest link is https://www.codechef.com/KJCS17

You can register here.

Join the Facebook page here.

P.S:-Only Indian participants are eligible for cash prizes or to get selected for the onsite round.

Update

The contest is over the winner will get a mail soon. If you haven't registered and were among the top participants please fill the google form above so that we can contact you. Thank you all for participating.

swapping two characters in python string ?

what is the easiest way to swap two characters in a python string ?

A few questions about ZCO 2017

This year I am participating in ZCO 2017 so I have a few questions related to it, it would be a really big help if anyone could help me out. My questions are:

  • How many question come in ZCO?
  • What is the requirement to qualify for the next level?
  • What is the time limit for ZCO?

Once again thank you.

Viewing all 40121 articles
Browse latest View live