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 » Compete » Manthan 2010 » Edit Distance

Edit Distance

Problem code: CF02

  • All Submissions

All submissions for this problem are available.

Run-length encoding(RLE) is a very simple and easy form of data compression in which consecutive occurrences of the same characters are replaced by a single character followed by its frequency. As an example, the string S aabbbbdaa would be encoded to a2b4d1a2.

Thus encoded string is described as an ordered sequence of pairs (a, i), each consisting of an alphabet symbol a and an integer i. Each pair corresponds to a run in S consisting of i consecutive occurrences of a.

In this problem, we are interested in finding the minimum number of mutation(s) needed to transform first string given in encoded form into second string i.e. edit distance when only two operation are allowed

  1. Add any character at any position(insertion)
  2. Remove any character from any position(deletion)

The cost of inserting a character is 1 and cost of deleting a character is 2.

Input

The input file contains several test cases. The first line of the input denotes the number of test cases, T (1 T 100) to follow. Each test case begins on a new line and consists of an integer L1, a blankspace and a run length encoded string S1 and then on a new line, an integer L2, a blankspace and a run length encoded string S2.

L1 and L2 denote the number of runs in strings S1 and S2 respectively. 1<=L1,L2<=100.
S1 and S2 consists of alphabets [a-z] followed by number of consecutive occurrences of that character.

You can safely assume that the total length of any of the strings will not exceed 3000 characters.

Output

For each test case, output the edit distance from S1 to S2 in a new line.

Example

Input:
2
2 a3b2
1 b3
3 a1b1a1
1 a2
Output:
7
2


Date: 2010-03-26
Time limit: 2s
Source limit: 50000
Languages: C C++ 4.0.0-8 C++ 4.3.2


  • Submit

Comments

  • Login or Register to post a comment.

"You can safely assume that

cro1 @ 28 Mar 2010 06:22 PM

"You can safely assume that the total length of any of the strings will not exceed 3000 characters."

Is this sentence about the original string, or the encoded string?

Will there be input like c6c6

screw_it @ 28 Mar 2010 06:26 PM

Will there be input like c6c6 ?

The length constraint is

manthan @ 28 Mar 2010 06:27 PM
The length constraint is corresponding to original string. For e.g. if the encoded string is a3b2, the string length is 5 characters.

No. There is no such input in

manthan @ 28 Mar 2010 06:29 PM
No. There is no such input in the judge test cases. c6c6 will be c12.

What is the maximum length of

screw_it @ 28 Mar 2010 07:00 PM

What is the maximum length of a run, for e.g. if input is of form aX
what is maximum value of integer X?

@screw_it: As the original

manthan @ 28 Mar 2010 07:05 PM

@screw_it: As the original string (not the encoded string) can be of maximum 3000 characters, X can maximum be 3000, if number of run is 1

Is the second test case right

Villain @ 28 Mar 2010 07:08 PM

Is the second test case right ???

Yes, by deleting the 'b'

Thelhoers @ 28 Mar 2010 07:12 PM

Yes, by deleting the 'b'

is the run length positive?

cro1 @ 28 Mar 2010 07:42 PM

is the run length positive?

@Musketiri: Yes run lengths

manthan @ 28 Mar 2010 07:45 PM

@Musketiri: Yes run lengths are always positive (>0).

Is it possible to submit

Coodle @ 28 Mar 2010 08:03 PM

Is it possible to submit solution in JAVA

Current ranking is available

manthan @ 28 Mar 2010 08:08 PM

Current ranking is available at http://www.codechef.com/teams/list/MANTH10/

@sam6230i: No only C/CPP

manthan @ 28 Mar 2010 08:12 PM

@sam6230i: No only C/CPP codes are allowed for the contest.

Hi, can we know why our team

team_khan @ 28 Mar 2010 09:00 PM

Hi, can we know why our team is not elligible, I have registered our team at the CodeFest website before the start of contest and also my current team ID is our team name at your website.

 

Thanks

@ThreeKhan : Eligible team

manthan @ 28 Mar 2010 09:24 PM

@ThreeKhan : Eligible team section shows invalid data. All teams registered on Codechef wenbsite and listed at http://www.codechef.com/teams/list/MANTH10/ are eligible for prizes if they form a team for Manthan at Codefest website with same team members. The team names can be different.

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