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 Long Contest
    • January CookOff
    • January Long Contest
  • 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) » An interesting subsequence

An interesting subsequence

Problem code: C5

  • Submit
  • All Submissions

All submissions for this problem are available.

For two given sequences of integers, find the longest possible integer sequence which is a subsequence of both these sequences, and whose elements are integers in a (strictly) increasing order.

Input

The first number is n (1 ≤ n ≤ 5000), the length of the first sequence.

The next n integers are elements of the first sequence.

The next is m (1 ≤ m ≤ 5000), the length of the second sequence.

The next m integers are elements of the second sequence.

Output

One number k, the length of the longest possible common subsequence that is increasing, followed by exactly k space-separated integers containing any exemplary sequence of this length.

Example

For the input:

5
2 3 1 4 0
6
10 3 4 1 0 0
the unique correct answer is:
2
3 4


Date: 2009-04-20
Time limit: 3s
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 TEXT


  • Submit

Comments

  • Login or Register to post a comment.

niyasim @ 25 May 2009 04:40 PM

the output of this prblm is not clear. i cant understand.

admin 2 @ 25 May 2009 04:43 PM

There is a discussion of the problem here: http://blog.codechef.com/2009/05/19/211/

praveen_agrawa @ 25 Jul 2009 04:08 AM

My solution is giving correct results for seqs i give, but throwing 'wrong answers' here. I didn't go with the algo given on the discussion page.
Admin: is it possible to put some of your test cases/sequences here?

praveen_agrawa @ 25 Jul 2009 04:18 AM

I'm reading input from four lines:
line-1: count of seq1 numbers,
line-2: integers for seq1, separated by one space
line-3: count of seq2 numbers,
line-4: integers for seq2, separated by one space

Output is:
line-1: count of result seq
line-2: integers of seq, in increasing order, with no duplicates

Please let me me know if anything is not correct. Thanks.

admin 2 @ 26 Jul 2009 07:49 AM

@praveen. The solutions for this problem are available. You can take any of the accepted solutions and test them yourself.

praveen_agrawa @ 27 Jul 2009 03:36 AM

Thanks Admin.
But i dont see any successful solution here!!
Also, i'm more interested in having seqs for which my solution is throwing wrong results. Seeing other solutions is good, but having own solution working is better :). When the solutions are public, i'm sure the problem seqs can also be public. Thanks.

admin 2 @ 27 Jul 2009 08:35 AM

http://blog.codechef.com/2009/05/11/winners-of-may-challenge-test-cases/ :) Hope this helps.

praveen_agrawa @ 27 Jul 2009 06:29 PM

Thanks a lot admin, for sharing seqs. My solution is passing 8 out of 12 seqs, and failing for other 4. However, few things to note:
1:- the C5_xx.out files contain only the result seq length, and not the actual seq numbers after that, whereas the problem example given above asks to print seq number also, which will result in "wrong answer" always, if you match solution output and the .out file.. 2:- I analyzed one failed scenario: C5_3.in. I found that the max common seq itself is of length 64 (set aside the "strict increasing" condition) then how can the final seq length be 84? Any hint or final seq numbers will be of great help, while i'm analyzing other 3 failed ones :). Thanks again.

admin 2 @ 27 Jul 2009 06:58 PM

The problem statement has been edited. Please check it out again.

praveen_agrawa @ 27 Jul 2009 07:20 PM

Thanks for modifying problem statement.
Are you looking into testcase#3 (C5_3.in)?

admin 2 @ 27 Jul 2009 07:22 PM

As of now, it has been removed. We will look into it and if it is correct, will replace it and rejudge the submissions.

rockinneal @ 30 Jul 2009 12:50 AM

Do we hav 2 check the sequence,so that we realize the general trend of it's growth n compare all the possible valuse in the sequence??
Pls Lemme know!!

i0exception @ 30 Jul 2009 12:53 AM

Your question is rather vague.

Hi, I am new here. Just a

Amit Mittal @ 26 Aug 2009 07:11 PM
Hi, I am new here. Just a thought... The required task takes 4 lines of input 1. The first number is n (1 ≤ n ≤ 5000), the length of the first sequence. 2. The next n integers are elements of the first sequence. 3. The next is m (1 ≤ m ≤ 5000), the length of the second sequence. 4. The next m integers are elements of the second sequence. For 2nd and 4th line, it is not mentioned that the integers will be 'space' separated, though the given example suggests that. If this is indeed the case, this is not fair for many programming languages, esp C#. C# supports limited console input/output functionality. Straight forward input methods available in c# read strings or characters from the console unlike cin or scanf where we can specifically ask for reading integers. If you want to read integer from command line, you need to read a string and parse it to integer. Now the problem is that a 'space' is considered a part of the string rather than a delimiting character like new line. So if you want to read a stream of integers that are 'space' delimited rather than 'new line' delimited, you need to do considerable tweaking which considerably takes away the focus from actual algorithm at hand. It would be better if the input is one integer per line and better still if the input can come from command line parameters. One more thing that I am confused about right now is about the handling of 'foul' input. I read your guidelines which ask the programmer not to prompt for input, since yours is an automatic judgment system. Majority of the bugs arise due to wrong input and hence it is always better to validate the input. The confusion is, given that yours is an automatic judgment system, do we still need to worry about invalid input (or just assume that correct input will be given). If yes, should we just exit with a return code or ask for re-input (without any prompt of course :))?

A huge number of problems

triplem @ 27 Aug 2009 08:15 AM

A huge number of problems throughout all contests worldwide have space separated inputs on various lines, you're not going to get them to change that :P All languages can do some things and not others; Java has BigIntegers which makes programs involve them easier for example. You should be able to easily split a line on whitespace with split functions that come with whatever language you use.

As for input, the problem statement tells you what input you will receive. If it tells you something, you shouldn't assume what it tells you is wrong! You'll never receive any input that doesn't match what it says the input will be like.

Thanks for reply Stephen. So

Amit Mittal @ 27 Aug 2009 05:37 PM
Thanks for reply Stephen. So now I fully understand that the test cases of the automated judgment system will never be negative at least from input perspective.

Dear Admin, 'all

Amit Mittal @ 27 Aug 2009 05:42 PM
Dear Admin, 'all submissions' section is giving out following php error. warning: Missing argument 5 for get_recent_activity_practice_problem(), called in /var/www/html/codechefbeta/codechef/sites/all/modules/problem_status/problem_status.module on line 78 and defined in /var/www/html/codechefbeta/codechef/apicalls.php on line 152.

Hey Everyone! I coded the n^2

matrixk1 @ 30 Dec 2010 02:12 PM

Hey Everyone!

I coded the n^2 solution and it gives the right answer for all official cases used in the contest but when submitting it gives WA.

So any help is appreciated :)

Thanks in advance!

@ALL: My solution gives

paarth @ 17 Mar 2011 10:22 PM

@ALL:

My solution gives correct answer...but codechef judge gives out WA...plz do check  and help......Hmm can anyone one pointout the mistake.....

http://www.codechef.com/viewsolution/490595

thnx in advace...

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