CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » Name Chopping

Name Chopping

Problem code: INSOMA4

  • Submit
  • All Submissions

All submissions for this problem are available.

In the hidden country of Lapatrecta, an age old custom was followed to ensure that no outsider ever entered their country undetected. The security measure, though simple, was an effective one. Every person born in Lapatrecta had the initials of all his forefathers included in front of his name. Every once in a while, certain families became very famous and the initials of their ancestors were dropped from the names of all their descendants. Thus, there existed a nice homogeneity in the names of the people of Lapatrecta.

Now, a royal ball was organized at the behest of the Queen of Lapatrecta and all citizens were cordially invited to the event. The ball was being held to chop off the initials of the ancestors of the most distinguished family of the country. The Queen set the following 2 criteria for determining the most distinguished family from amongst the invitees:

1. The family must have more than 1 member living.
2. The length of the ancestor list of the family must be as long as possible.

For example:

For 3 people:

APJQ Ravi

APJRS Rahul

PJQ Bharat




The following observations hold:

APJQ Ravi was of the same family as APJ Rahul but PJQ Bharat was not of the same family.

The length of the ancestor list for Ravi and Rahul was 3 whereas Bharat has an ancestor length of 0 as there is no other member of his family living. However, if there existed a person named PJ Varun, Bharat and Varun would both have an ancestor list length of 2.

As a member of the Royal Court of Lapatrecta, you have been entrusted the task of determining the length of the ancestor list that will be chopped off by the Queen. You will be provided data in the following format:

Input

Line 1: N – The number of people coming to the ball

Line 2-N+1: The initials list of all the people coming to the ball. No initials list is longer than 100 characters.

Output

Line 1: The length of the longest ancestor list.

Example

Input:
3
APJQ
APJRS
PJQ

Output:
3 

Date: 2009-03-19
Time limit: 7s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK


  • Submit

Comments

  • Login or Register to post a comment.

sagar_jhobalia @ 22 Jun 2009 08:47 PM

the question isn't clear...pls giv an example with an explanation

is there any limit on the no

kshivi @ 1 Sep 2009 06:21 PM

is there any limit on the no of people that attend the ball?

 

Is the input restricted to

tuxcanfly @ 6 Sep 2009 08:57 PM

Is the input restricted to CAPS or can it be small and miXeD case??

Can be mixed.

admin @ 7 Sep 2009 02:22 PM

Can be mixed.

what is the maximum value of

vivek.cs.iitr @ 21 Nov 2009 01:30 AM

what is the maximum value of N ?

For N=10000, my code has

vivek.cs.iitr @ 21 Nov 2009 03:48 AM

For N=10000, my code has runtime well below 7 s.

so is it that N can be even higher than this, given it is being displayed as time limit exceeded.

Admin, I have solved this

sppraveen @ 23 Nov 2009 12:08 PM

Admin,

I have solved this problem. I could not see the submissions of others. This problem exists for many other problems also. Please fix this

Admin, Is there a way I can

sijuv @ 24 Feb 2010 02:15 PM

Admin,

Is there a way I can know for what particular input it is a WA?

No. FAQ

triplem @ 24 Feb 2010 02:34 PM

No. FAQ

Hi My solution is giving

shwetanka_19 @ 11 Jul 2010 10:16 PM

Hi

My solution is giving runtime error. Can I find out what type of error is it showing?

Hi My solution is giving

shwetanka_19 @ 11 Jul 2010 10:16 PM

Hi

My solution is giving runtime error. Can I find out what type of error is it showing?

Are 'A' and 'a' same in mixed

shwetanka_19 @ 11 Jul 2010 10:36 PM

Are 'A' and 'a' same in mixed case or different?

@Shwetanka: Consider them

vikeshkhanna @ 27 Nov 2010 03:55 PM

@Shwetanka: Consider them different.

@Vivek: I believe N<=10^5. My program would give TLE outside that range but it got accepted. Therefore, I am sure N<=10^5

what is

u4cse10152 @ 29 Mar 2011 05:17 PM
what is this????????????????please explain the question......!!!!!!!!!!!!!!!!!

My prog works fine on my

maverickcoder @ 22 Jul 2011 01:29 AM
My prog works fine on my manual input. How does it give wrong there??

Can the characters in the

a1_3 @ 30 Jan 2012 12:39 PM
Can the characters in the initial list be between a-z or are they strictly uppercase?

What is the output for APJQ,

a1_3 @ 30 Jan 2012 10:31 PM
What is the output for APJQ, APJRS, APJRT? Is it APJR or is it APJ?

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com