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) » Stepford Houses

Stepford Houses

Problem code: INSOMA3

  • Submit
  • All Submissions

All submissions for this problem are available.

Stepford Street was a dead end street. The houses on Stepford Street were bought by wealthy millionaires. They had them extensively altered so that as one progressed along the street, the height of the buildings increased rapidly. However, not all millionaires were created equal. Some refused to follow this trend and kept their houses at their original heights. The resulting progression of heights was thus disturbed.

A contest to locate the most ordered street was announced by the Beverly Hills Municipal Corporation. The criteria for the most ordered street was set as follows:

If there exists a house with a lower height later in the street than the house under consideration, then the pair (current house, later house) counts as 1 point towards the disorderliness index of the street. It is not necessary that the later house be adjacent to the current house.

Note: No two houses on a street will be of the same height

For example, for the input:

1 2 4 5 3 6

The pairs (4,3), (5,3) form disordered pairs. Thus the disorderliness index of this array is 2.

As the criteria for determining the disorderliness is complex, the BHMC has requested your help to automate the process. You need to write an efficient program that calculates the disorderliness index of a street.

Input

Line 1: N – The size of the array. 1 <= N <= 10^5

Line 2: N integers denoting the heights of the various buildings in order of their locations on the street.

Output

Line 1: The disorderliness index of the street.

Example

Input:
6
1 2 4 5 3 6


Output:
2

Date: 2009-03-19
Time limit: 7s
Source limit: 50001
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.

Its so funny that the same

sppraveen @ 21 Oct 2009 07:31 PM

Its so funny that the same piece of code which was giving TLE some days back ran successfully today.

will the heights of houses be

Dalchand @ 26 Dec 2009 12:40 AM

will the heights of houses be in range 1 to N or it can be anything?

i didn't know this problem

Dalchand @ 26 Dec 2009 02:58 AM

i didn't know this problem can be solved so easily :P

i'm getteing time limit

rumi2752 @ 30 Dec 2009 10:49 AM

i'm getteing time limit exceeded.....for N=10000  >    0.24s

but for N=100000  >   14.93s   ..how!!!!!!!!

please help me...

i'm very much surprised that

gurpreet_09 @ 31 Dec 2009 03:55 PM

i'm very much surprised that for the problem TURBO SORT (easy)

in which no. of test cases were <10^6 and n<10^6,it took only 3.6sec to do by making and traversing

binary search tree.

but in this problem when no. of case =1 and n<10^5 and time limit is 7 sec ,then just making the binary search tree gives TLE................    :(

i am surprised that my

conceptsud @ 24 Jan 2010 09:03 PM

i am surprised that my solution works for N= 100,000 but get an run time error for N=30,000. I don't understand why? please help

@admin I don't understand

anurag_aggarwal @ 6 Mar 2010 03:12 PM

@admin

I don't understand that why is my code giving correct answer and in time for all cases except for N=10000 and N=30000 can you tell me why

How do u solve this in less

shanky89 @ 13 Mar 2010 02:05 PM

How do u solve this in less than O(n^2)

Can we assume that the

imperiumsage @ 25 Apr 2010 06:31 PM

Can we assume that the heights of the buildings are only numbers from 1 to N?

No it can be more than N

Dalchand @ 20 May 2010 09:55 AM

No it can be more than N also.

my code gets time limit

gunjanbansal @ 22 May 2010 04:06 PM

my code gets time limit exceeded for two test cases (100000,3000) , is this a problem with faster input/output??

yipee Got a correct answer ,

gunjanbansal @ 22 May 2010 04:08 PM

yipee Got a correct answer , was using memset extra :)

@Anurag Aggarwal Make sure

medium @ 24 Jun 2010 05:45 PM

@Anurag Aggarwal

Make sure your scaling works correctly.

@Admins- Sir why cant i

anurag11 @ 12 Aug 2010 10:44 PM

@Admins-

Sir why cant i submit my solution?

It says wrong pasword or login,while i have already logged in successfuly .. ?

@admin, i am facing same

thechamp @ 28 Aug 2010 07:37 PM

@admin, i am facing same problem as anurag.. the result says wrong answers only for 30000 and 10000, and correct for rest cases.

@max, scaling of what?

Just making the BST gives

vivek.cs.iitr @ 22 Sep 2010 04:45 AM
Just making the BST gives time of 14.85 seconds for 10^5 elements. How is it possible !!

Test N Result

vivek.cs.iitr @ 22 Sep 2010 06:44 AM
Test N Result (time) 1 1000 accepted (0.00s) 2 10000 accepted (0.01s) 3 1 accepted (0.00s) 4 100000 accepted (0.11s) 5 30000 wrong answer (1.78s) 6 10000 wrong answer (0.21s) can anyone explain why i may be getting wrong answer for last two cases ?

@ Admin: Please care to

vivek.cs.iitr @ 22 Sep 2010 06:45 AM
@ Admin: Please care to explain any possible reason for getting wrong answer in the last two cases.

I got the right answer :) A

vivek.cs.iitr @ 22 Sep 2010 07:03 PM
I got the right answer :) A bug had just managed to live long enough !!

I got the right answer :) A

vivek.cs.iitr @ 22 Sep 2010 07:04 PM
I got the right answer :) A bug had just managed to live long enough !!

i got time limit exceeded,

malpani @ 22 Sep 2010 09:55 PM
i got time limit exceeded, for(30,000 ,t=6.07 s) rest all are <1 s. since time is 7s for one test case. how can i get the time limit?? It means 7s is combined for all the cases.It should be mentioned there.

why i m getting wrong answer

algoritmus @ 28 Oct 2010 06:10 PM

why i m getting wrong answer for last two cases???

@Admin: I am amazed why the

prakharprakhar @ 12 Nov 2010 08:25 PM

@Admin: I am amazed why the solutions (successfully submitted) are producing different results. I am providing the same 10k input file.

I feel that providing the test cases might be a good idea than showing the submitted solutions.

Most likely you are not

triplem @ 13 Nov 2010 01:46 AM

Most likely you are not testing them correctly. Input cases can never be revealed or it would ruin the problem.

1000    0.1sec          

prakharprakhar @ 15 Nov 2010 07:52 PM

1000    0.1sec           accepted

10000  0.96sec         accepted

1           0.0sec           accepted

1L         14.93sec       TLE

30000   0.06sec        accepted

10000   0.02sec        accepted

 

On my machine 1L gives in 0.93 sec :(

Its a simple BST, any suggestions.


Lets say if my input is 74 12

dhiman_nikhil @ 18 Nov 2010 06:48 PM

Lets say if my input is

7
4 12 7 5 20 16 21

Will the answer be 4 or 5

 

12-5  12-7  7-5  20-16  12-21

12-21 is not in the wrong

triplem @ 19 Nov 2010 02:29 AM

12-21 is not in the wrong order. There are only 4 pairs in the wrong order.

  I see comments like.. "1000

sharad_banka @ 19 Feb 2011 04:42 PM

 

I see comments like..

"1000    0.1sec           accepted

10000  0.96sec         accepted

1           0.0sec           accepted

1L         14.93sec       TLE

30000   0.06sec        accepted

10000   0.02sec        accepted"

 

Does code chef provide such detailed failure reports ? In all the submissions I have made I never get such details. Or do we need to download some explicit test cases from somewhere to get such analysis ?

Don't know how but my (nlogn)

vijay_kansal @ 11 Jun 2011 02:00 PM
Don't know how but my (nlogn) soln. got TLE and n^2 soln. got accepted

may be bcoz, ur nlogn soln

mkagenius @ 12 Jun 2011 01:58 PM
may be bcoz, ur nlogn soln got stuck somewhere (ex:- infinite loop)

i don't really understand the

pc1ang @ 28 Aug 2011 11:32 AM
i don't really understand the problem

I got the following: Test

digs2digi @ 19 Oct 2011 03:44 PM
I got the following: Test N Result 1 1000 Accepted 2 10000 Accepted 3 1 Accepted 4 100000 Accepted 5 30000 TLA 6 10000 Accepted Howcome test case 4 is accepted and 5 is not?

i got it correct for 1L but

kaushalv27 @ 23 Oct 2011 10:17 AM
i got it correct for 1L but it is giving TLE for 30k please help

Is BST good for this

swaprocks123 @ 4 Dec 2011 12:46 AM
Is BST good for this problem....

@admin I don't understand

yash.prince @ 21 Jan 2012 03:56 PM
@admin I don't understand that why is my code giving correct answer and in time for all cases i had also read the above all comment and many ppl ask d sm doubt ,so please clr it asap

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