hairband_dude's blog

By hairband_dude, history, 4 years ago, In English

The submission I've made here compiles fine on my local machine (OCaml 4.13.1), and I'm not using any language features incompatiable with v4.02 (the version CodeForces uses). However, the executable generated by ocamlopt runs in a few milliseconds on my machine, whereas it TLE's on the third testcase here.

The command I used to compile was ocamlopt -o test 1681D.ml. If anyone has any ideas why this is happening, please do share.

  • Vote: I like it
  • +21
  • Vote: I do not like it

»
4 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

1) You can use custom invocation to get a better gasp of the judge running time and behavior.

2) I don't know ocaml, so read your code with my little knowledge of lisp. Doesn't "push_all queue tbl (depth+1) vals;" put dupicate vals if n is, say, 22? To me, the code reads like an integer z exists in queue as many times as the ways z can be reached from x via min # of multiplications by digits. You can add something like visited[z] to prevent this. Since I don't know how to code ocaml, I can't really tset and confirm if this really works, sorry.

3) I don't know how Hashtbl is implemented in ocaml, but you must be sure that there is no severe hash collision for hash-based ds to run in O(1). I don't think this is really the case in this problem (hard to exploit the collision), but still, the following blog could be very useful: https://mirror.codeforces.com/blog/entry/62393?#comment-464775

»
4 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
4 years ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

OCaml is 32-bit on codeforces, and your code fails for numbers which doesn't fit in 31 bit.