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

  • SEARCH
  • Home
  • 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 3623468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:23:14+00:00 2026-05-18T23:23:14+00:00

Hmmm… its kinda challenging to find a method for reading/writing data faster enough to

  • 0

Hmmm… its kinda challenging to find a method for reading/writing data faster enough to get ACCEPTED in this problem ( https://www.spoj.pl/problems/INTEST/ ) using F#.

My code ( http://paste.ubuntu.com/548748/ ) gets TLE…

Any ideas how to speed up data reading?

  • 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-18T23:23:14+00:00Added an answer on May 18, 2026 at 11:23 pm

    This version of mine passes the time limit (but is still terribly slow ~14 seconds):

    open System
    open System.IO
    
    // need to change standard buffer, not to add an additional one
    let stream = new StreamReader(Console.OpenStandardInput(4096))
    
    let stdin = Seq.unfold (fun s -> if s = null then None else Some (s,stream.ReadLine())) <| stream.ReadLine()
    
    let inline s2i (s : string) = Array.fold (fun a d -> a*10u + (uint32 d - uint32 '0') ) 0u <| s.ToCharArray()
    
    let calc = 
        let fl = Seq.head stdin
        let [|_;ks|] = fl.Split(' ')
        let k = uint32 ks
        Seq.fold (fun a s -> if (s2i s) % k = 0u then a+1 else a) 0 <| Seq.skip 1 stdin
    
    printf "%A" calc
    

    Though the bottle-neck of this version is actually string -> uint32 conversion (standard uint32 cast from string is even slower) the reading itself takes around 2 sec (vs 6 sec of total time) on my sample input (~100M file) – still not a great result. Once s2i is rewritten in imperative style, the total run-time can be reduced to 10 sec on spoj:

    let inline s2i (s : string) =
        let mutable a = 0u
        for i in 0..s.Length-1 do a <- a*10u + uint32 (s.Chars(i)) - uint32 '0'
        a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hmmm. Consider this program, whose goal is to figure out the best way to
I have a multi-paged forms and I need to get all the data from
Hmmm... the Java Iterator<T> has a remove() method but not a replace(T replacement) method.
I have searched and searched and I just can't get this code to work.I
Hmmm this seems silly, so I feel silly. I have a custom operation on
Hmmm, so how is this done? I have a class class Themes extends Access
Hmmm...crappy question, but I didn't know how to phrase this: I have a sweet
Hmmm... I have read about this issue on various other threads here on stackoverflow
Hmmm. Okay after revisiting PInvoke, I'm sure that I don't quite get it :-/
Hmmm...strange problems... I'm making a form to upload syllabi. Basically, someone go search for

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.