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
    • Wiki
    • Forums
    • Blog
    • Facebook
    • 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
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » August 2010 Challenge » Genetics

Genetics

Problem code: GENETICS

  • All Submissions

All submissions for this problem are available.

Genetic engineering is fun. The scientists have gathered several DNAs and want to create something new out of those. Each DNAs can be represented as a sequence of bases A, G, T, C. Let DNA[a..b] be the subsequence of DNA starting from index a finishing in b inclusive, and DNA[a..] be the subsequence of DNA starting from index a to the end. Scientist can perform the following operations on the DNAs:

  • cross operation they take DNA1 and DNA2 and numbers k1 and k2. Then two new DNAs are created: DNA3 = DNA1[1..k1]+DNA2[k2+1..] and DNA4 = DNA2[1..k2]+DNA1[k1+1..].
  • mutate operation they take a DNA, number k and one of the bases. Then they replace the base in position k in DNA with that base.
  • also they need to know certain characteristics of those DNAs. So they can perform count operation they take DNA and numbers k1 and k2 (k1 <= k2). This operation should return the number of A, G, T, C bases in DNA[k1..k2].

 

The initial DNAs are numbered from 1 to n, where n is the amount of those DNAs. The new DNAs created in the cross operations are numbered with consecutive integers. You are to write a program to help scientists perform those operations.

Input

The first line of input file contains number n the amount of initial DNAs. Each of the following n lines contains the description of each DNA. The next line contains number q the amount of operations to perform. The next q lines contain the description of each operation in the following form:

  • CROSS id1 id2 k1 k2
  • MUTATE id k m
  • COUNT id k1 k2

Constraints

1 <= n <= 20
1 <= q <= 30000
The length of each initial DNA does not exceed 30000. The length of any DNA formed in cross operation won t exceed 2000000000. Total amount of different DNAs won t exceed 10000. It is guaranteed that all operations are correct.

Output

For each count operation print four integers: the number of each of the bases in the given subsequence of the given DNA.

Example

Input:
2
CTCGC
TGCGG
5
MUTATE 1 2 A
COUNT 2 2 4
MUTATE 2 1 G
CROSS 2 1 1 5
COUNT 4 3 6

Output:
0 2 0 1
0 2 0 2


Author: spooky
Date Added: 9-04-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, PERL6, 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.

do the index of the sequences

chaitanyaanand @ 3 Aug 2010 12:04 AM

do the index of the sequences start from 0 or 1

the description of the cross operation suggest 1 but if so then the line "COUNT 4 3 6" in the sample input be invalid

is there a mistake or am i missing something....

In cross operation id1 and

Oleg @ 3 Aug 2010 12:31 AM

In cross operation id1 and id2 can be same ?

@chaitanya Thindex in

spooky @ 3 Aug 2010 12:50 PM

@chaitanya

Thindex in operations starts with 1. DNA with id=4 will be CACGCGCGG. So COUNT 4 3 6 gives us 2 G and 2 C.

@Oleg

yes

i don't know whats the

shk0drani @ 3 Aug 2010 11:53 PM

i don't know whats the problem when i try the example it works fine in my pc, but here it sayas runtime error could someone tell me what could  i have done wrong

Please provide atleast two or

Gaurav Rai @ 4 Aug 2010 08:55 AM

Please provide atleast two or three test cases for eash problem statement.

i have coded this with java.

rocker.da @ 5 Aug 2010 09:44 AM

i have coded this with java. working fine on my pc but here i am geeting run time error...someone plzz tell me d reason.

doubt in problem

muke @ 8 Aug 2010 01:36 PM

doubt in problem statement

cross operation they take DNA1 and DNA2 and numbers k1 and k2. Then two new DNAs are created: DNA3 = DNA1[1..k1]+DNA2[k2+1..] and DNA4 = DNA2[1..k2]+DNA1[k1+1..].

 

if n=4 i.e. there are 4 DNA in input

and cross operation

cross 2 1 1 5

what will b no. 2 new created DNAs is it DNA5 and DNA6

or DNA3 and DNA4 get modified

Each DNA is given the next

triplem @ 8 Aug 2010 02:23 PM

Each DNA is given the next available number. 5 and 6 in that case.

I have coded my solution in C

shruti25 @ 9 Aug 2010 08:57 PM

I have coded my solution in C and it works absolutely fine in my PC. However, it shows runtime error when I try submitting it. Another strange thing is than it shows the runtime error as "OTHER" when I hover the mouse over the icon in "My Submissions" and when I try doioing the same in "Recent Activity", it shows "SIGSEGV". What does it imply? Somebody plz help.

The problem description

bhetrick @ 10 Aug 2010 01:32 AM

The problem description implies (but does not state) that "mutation" modifies an existing DNA rather than creating a new one. Is this correct?

Thanks.

@Brian Yes. MUTATE doesn't

spooky @ 10 Aug 2010 01:58 AM

@Brian

Yes. MUTATE doesn't create new DNA.

i am printing count whenever

rahul8iitkgp @ 10 Aug 2010 09:39 AM

i am printing count whenever that operation is encountered  and i m getting TLE ...

does it mean that i m getting correct answer for test cases tested within time?

No, it just means you

triplem @ 10 Aug 2010 10:52 AM

No, it just means you exceeded the time limit. FAQ

Is it necessary that during

rjdthegreat @ 11 Aug 2010 08:04 AM

Is it necessary that during cross: 1< k1 and k2 <length of either DNA?

No, the sample input has an

triplem @ 11 Aug 2010 10:31 AM

No, the sample input has an example with k1=1.

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.

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