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
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » March 2010 Contest » K-important Strings

K-important Strings

Problem code: N3

  • All Submissions

All submissions for this problem are available.

You are given a set of N strings S0, S1, …, SN-1. These strings consist of only lower case characters a..z and have the same length L.

A string H is said to be K-important if there are at least K strings in the given set of N strings appearing at K different positions in H. These K strings need not to be distinct.

Your task is to find the shortest K-important string. If there are more than one possible solution, your program can output any of them.

Input

The first line contains a number t (about 10) which is the number of test cases.

Each test case has the following form.

The first line contains three integers N, L and K. The next N lines contain the strings in the given set.

Each test case's input is separated by a blank line.

Constraints

  • 1 ≤ N ≤ 150
  • 1 ≤ L ≤ 300
  • 1 ≤ K ≤ 500

Output

For each test case, output the following information.

The first line contains the length of the shortest K-important strings.

The second line contains H, one of the K-important strings.

Each line in the next K lines contains the index of one string in the given set that appears in H and the corresponding position (0-based) in H.

Print a blank line after each test case's output.

Example

Input
3

3 3 1
abc
cde
bcf

3 3 2
abc
cde
bcf

3 3 3
abc
cde
bcf

Output
3
abc
0 0

4
abcf
0 0
2 1

7
abcfabc
0 0
2 1
0 4


Author:
Date Added: 5-02-2010
Time Limit: 4 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Isn,t the output of 3rd test

mcsharma1990 @ 1 Mar 2010 04:59 PM

Isn,t the output of 3rd test case is given wrong?

@Mahesh The test cases look

Brian Drake @ 1 Mar 2010 05:12 PM

@Mahesh The test cases look correct to me.

hi frnds i'm new in ths

janak.rajyaguru @ 2 Mar 2010 05:39 PM

hi frnds i'm new in ths competition...r we going to check the input given by the user is correct or not? or we hv to keep in mind tht the input supplied by the user will always be correct i.e. in above problem instead of chars a-z if user enters digits wt shd be done? pls clarify for all the problems. Thnks.

@janak If you're new, you

Brian Drake @ 2 Mar 2010 06:54 PM

@janak If you're new, you should probably read all of the FAQ. The input is guaranteed to be correct.

Are the given n strings

ankush108 @ 2 Mar 2010 11:20 PM

Are the given n strings distinct??

Please read the problem

admin @ 3 Mar 2010 03:32 PM

Please read the problem statement again.

can anybody explain the

dabbcomputers @ 3 Mar 2010 06:45 PM

can anybody explain the problem...plssss

@Ankush By definition, a set

Brian Drake @ 4 Mar 2010 05:46 PM

@Ankush By definition, a set of N items contains N distinct items.

@AMRITPAL A string H is

Brian Drake @ 4 Mar 2010 05:55 PM

@AMRITPAL A string H is K-important if, and only if, we can find at least K different positions i in H satisfying the criterion below. The criterion is that the substring of H consisting of the characters i to [i + (L − 1)] matches one of the strings in {S0, …, SN − 1}.

@brain pls elloborate with an

dabbcomputers @ 4 Mar 2010 06:10 PM

@brain

pls elloborate with an example. i didn't get it. pls...

thanx for your response...

explain the H and L term in your comment...

my submission is showing

jitendra_theta @ 7 Mar 2010 01:39 AM

my submission is showing runtime error(other)...

what can be the probable reasons???

got the error, K and N were

jitendra_theta @ 7 Mar 2010 02:13 AM

got the error, K and N were swapped in one of the declared variable (segmentation fault),now accepted :)

I changed the input of the

thealgorist @ 7 Mar 2010 09:06 AM

I changed the input of the string from

 

for(int i=1; i<=N; i++) {

for(int j=1; j<=L; j++) do scanf("%c", &s[i][j]) while(s[i][j]==' ' || s[i][j]=='n');

}

 

to

 

for(int i=1; i<=N; i++) scanf("%s", &(ss[i][1]));

 

and got AC from WA.

Does that mean, the input does not follow the specifications in the problem statement?

This WA had been bugging me for a LONG time !

No, the first code you wrote

triplem @ 7 Mar 2010 09:22 AM

No, the first code you wrote is wrong. You probably haven't read the FAQ.

Can anybody explain that what

charango @ 7 Mar 2010 10:34 AM

Can anybody explain that what will be the output if input is

Input

4

 

4 4 1

abcd

bcde

cdef

defg

 

4 4 2

abcd

bcde

cdef

defg

 

4 4 3

abcd

bcde

cdef

defg

 

4 4 4

abcd

bcde

cdef

defg


hey admin...i am bit 

ashukasama @ 7 Mar 2010 11:58 AM

hey admin...i am bit  confused abt output...

Each line in the next K lines contains the index of one string in the given set that appears in H and the corresponding position (0-based) in H.

as in input is

3 3 1
abc
cde
bcf

and

output H is abc bcoz k is 1 and

3
abc
0 0


i didnt understand the 0 0 output. it should not be only 0 ? bcoz only single string present in given set

@Ashish it means 0th string

neel @ 7 Mar 2010 12:12 PM

@Ashish

it means 0th string starts from 0th index of "abc"

I had a overview of the FAQ

thealgorist @ 7 Mar 2010 06:49 PM

I had a overview of the FAQ but could not get the soln.

Please do explain...

I got the solution accepted

nadeemoidu @ 9 Mar 2010 08:48 PM

I got the solution accepted by changing gets to scanf("%s"). I think there is something wrong with the input format. It won't matter for people who use scanf, but the input format should be exactly as mentioned in the question.

Nothing is wrong with the

triplem @ 10 Mar 2010 02:07 AM

Nothing is wrong with the input format.

@charango, I think the

smilitude @ 10 Mar 2010 10:01 PM

@charango, I think the output would be

4
abcd
0 0

5
abcde
0 0
1 1

6
abcdef
0 0
1 1
2 2

7
abcdefg
0 0
1 1
2 2
3 3

During a running contest,

gsbhatia @ 11 Mar 2010 10:01 AM

During a running contest, discussing input values beyond those given can (and should) result in disqualification. Contestants are supposed to work out any extraneous inputs themselves, without any help. Discussing them in public is unfair to those who have already made submissions. It is not hard to fathom that a good part of the challenge in such contests lies in coming up with your own test cases without anyone else being privy to them. Discussing them in public ruins it for everyone.

@ADMINS - This is a serious concern and compromises the integrity of these competitions. I hope you take care of such episodes.

@admin: Is the contest over.

sam6230i @ 11 Mar 2010 06:08 PM

@admin: Is the contest over. I am not able to submit solution for this contest any more. Kindly help.

how DP is to be used in this

shivmitra @ 24 Mar 2010 04:56 PM

how DP is to be used in this problem???

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

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