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 » May 2010 Contest » Summing Slopes

Summing Slopes

Problem code: SUMSLOPE

  • All Submissions

All submissions for this problem are available.

A digit in a number N is a minima if it is lesser than both the digits adjacent to it. Similarly, a digit is a maxima if it is greater than both the digits adjacent to it. The slope of N is the number of digits in N (leaving out the first and the last digit) which are either a minima or a maxima. Given A and B, count the sum of the slopes of all numbers between A and B.

Input :

The first line contains the number of test cases T. Each of the next T lines contains two integers A and B.

Output :

Output T lines one for each test case, containing the required sum for the corresponding test case.

Sample Input :
3
101 101
1 100
100 150

Sample Output :
1
0
19

Constraints :
1 <= T <= 50000
1 <= A <= B <= 1000000000000000 (10^15)

Author: syco
Date Added: 11-04-2010
Time Limit: 1 sec
Source Limit: 10000 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.

What does source limit

hi_i_am_amit @ 1 May 2010 08:05 PM

What does source limit indicate?

how many characters can be in

brien_premachandiran @ 2 May 2010 12:41 AM

how many characters can be in your code i assume

its the size of ur code in

justfor @ 2 May 2010 12:56 PM

its the size of ur code in terms of bytes..

ridiculous! my soln kept

white_king @ 2 May 2010 07:39 PM

ridiculous! my soln kept getting tle... later i submitted in C got ac. But my soln in c++ takes too little time and i think it should be given ac, i mean the time limit should be set to judge the soln order not to see how is the implementation, like if there is fast io or artihmatic optimization.

My code runs & gives desired

nssprogrammer @ 2 May 2010 08:06 PM

My code runs & gives desired output in DEV c++ ,but shows runtime error in the online judge

My code keeps getting TLE

shettynamit @ 4 May 2010 11:29 AM

My code keeps getting TLE even though it runs within 0.4 sec on my laptop for random 50000 cases. What maybe the problem. I'm using C++

A question, is the WA

a20012251 @ 6 May 2010 02:29 AM

A question, is the WA determined after the program finishes, or is determined during the execution of the program  (which could stop the program before is termination)?

The time limit of this

zhymaoiing @ 6 May 2010 11:13 AM

The time limit of this problem is too strict.......

Ya i agree .. the time limit

nutsnbolts @ 6 May 2010 07:36 PM

Ya i agree .. the time limit is too strict .. This what happens every time with me .. I am able to solve them but not within the time limit .. Please could anyone give point out to any site that gives tips to reduce execution time of C programs ..

i am getting "internal error

nemausus @ 9 May 2010 11:10 PM

i am getting "internal error occurred in the system" again and again??

Same to me, I can not submit

vdmedragon @ 10 May 2010 01:20 AM

Same to me, I can not submit the code.

it is easy to get TLE man.

vdmedragon @ 10 May 2010 02:43 AM

it is easy to get TLE man.

my ACed solution has not

vdmedragon @ 10 May 2010 02:44 AM

my ACed solution has not appeared since 1h , damn.

Uh, who isn't getting

Tool @ 10 May 2010 04:13 AM

Uh, who isn't getting internal server error?  I just submitted a simple junk spitting program, so i know it's not us contestants.

I too am gettting internal

sushilnath @ 10 May 2010 11:11 AM

I too am gettting internal system error!!!!

Admin or anyone please help......................

I think the internal server

madmaxwell @ 10 May 2010 11:30 AM

I think the internal server error is just a front end mistake for the TLE, i got email notifications for mine...

Im going nuts trying to figure out what the "Best" answer is to this one. Maybe someone can pm some knowledge when the contest is done?

thnks...............

sushilnath @ 10 May 2010 12:10 PM

thnks...............

i have optimized my

sushilnath @ 10 May 2010 12:58 PM

i have optimized my program.

It runs in around 0.6 seconds on my computer for t= 50000 and A and B of order 10^15

It is still showing internal system error.............

please help....

I have been trying for last 18 hrs for this program..........

@sushil: Try now, it seems

imrankane2005 @ 10 May 2010 02:06 PM

@sushil: Try now, it seems judge is fixed now.

This is hard on the output.

Tool @ 11 May 2010 12:58 PM

This is hard on the output. Outputstream printing 50000 lines takes an upwards of 1.5 seconds. Why so ridiculous?

@all Could you please

ankit1990 @ 12 May 2010 03:05 PM

@all

Could you please share your ideas as to how you solved/optimised the problem/solution ?

The way i attempted this

f03nix @ 14 May 2010 02:16 PM

The way i attempted this question was slightly different than the approach in editorial. For computing a range Slopes(A,B) i computed Slopes_Till(B) - Slopes_Till(A) + Slopes_In(B). Where Slopes_Till is the sum of slopes from 0 to that number(excluding the number itself).

Now , i just had to devise an algorithm for Slopes_Till .. the algorithm was as follows

-> Divide the x digit number into x different ranges as in the following example . If the number is 74356, the ranges would be { (0 - 69999) , (70000 - 73999) , (74000 - 74299) , (74300 - 74349) , (74350 - 74355) }.The result would be such that any range could be written in the following format {Constant Number}{0}{n zeros} - {Constant Number}{N}{n 9's}. The idea of doing this was to allow as many 0-9 digit permutations as possible (the last segment of the range), the slopes of which can be precomputed.

Now for every range , sum of slopes would be the sum of the following 5 kind of slopes

i) From the complete permutation of the last n digits alone.

ii) The slopes where first digit of slope is from the middle segment. ie, slopes from 000,N99*10^(n-2).

iii) The slopes where middle segment digit forms the middle digit of slope. it'll be c00,cN9*10^(n-1)

iv) The slopes where middle segment digit is the last digit of slope. It'll be cd0,cdN*10^n. (c and d are corresponding digits in the first segment of the range)

v) The slopes from the first segment alone. It'll be the slope of that constant number * (N+1)*10^n

 

As you can see , the above would be a O(1) time algorithms if you precompute the powers of 10 , slopes from 0-1000 and sum of slopes from complete permutation of n digits. (The calculation of perutation slopes requires a dynamic programming algo, which more or less is the same algo as above ... without requiring steps after step ii. You can see that in my program)

 

While following the above algorithm, you have to be careful about the steps where you might additionally include 010 as your slope when its not applicable. Such slopes should be added if you're computing the slopes from say 1000 - 1999 and not when you're computing it from 0 - 999 (the first range ...).

PS : the O(1) time would be

f03nix @ 14 May 2010 02:18 PM

PS : the O(1) time would be for an individual range , and since we're computing n ranges for an n digit number .. it'll take O(n) time.

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