Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3752034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:09:31+00:00 2026-05-19T09:09:31+00:00

I’m new to CodeChef and thought of trying a few problems, so I solved

  • 0

I’m new to CodeChef and thought of trying a few problems, so I solved the “Bytelandian gold coins” problem. (http://www.codechef.com/problems/COINS/) I’m getting instant results on my computer, CodeChef sets a 9 second time limit, but i’m still getting TimeOuts from CodeChef. I don’t have any clue anymore what causes this. Any hints would be helpfull.

My code:

module Main where

import qualified Data.Map as M
import Data.Map (Map)
import Data.Maybe

main = do
    catch (main' M.empty 1) (const $ return ()) 

main' _ 11 = return ()
main' m c = do
    x <- readLn
    let (k,m2) = sol m x
    print k
    main' m2 (c+1)


sol :: Map Integer Integer -> Integer -> (Integer, Map Integer Integer)
sol m x     |M.member x m = (fromJust $ M.lookup x m,m)
            |x > x2+x3+x4 = (x,M.insert x x m)
            |otherwise = (fullSoll, M.insert x fullSoll m4)
    where
        x2 = div x 2
        x3 = div x 3
        x4 = div x 4
        (sx2, m2) = sol m x2
        (sx3, m3) = sol m2 x3
        (sx4, m4) = sol m3 x4
        fullSoll = sx2+sx3+sx4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:09:32+00:00Added an answer on May 19, 2026 at 9:09 am

    Your sol doesn’t terminate when the x == 0. When x is 1 it is fine because all of x2, x3, x4 are 0, and their sum is less than x, meaning the second guard is true, and no recursion. However, when the input is 0, then the recursive case kicks in, and it never terminates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.