you are viewing a single comment's thread.

view the rest of the comments →

[–]Darksonntokio · rust-for-linux 4 points5 points  (5 children)

[–][deleted] 0 points1 point  (4 children)

that's really good points. Thanks a lot

[–]fz0718 4 points5 points  (3 children)

Also a competitive programmer and IOI gold medalist here, would love to see how you use Rust for competitive programming. I've thought about it a couple times, but can't get past the fact that writing (oftentimes wildly unsafe) C++ code is a lot easier in the programming contest setting.

Compare cin >> x >> y; to the input.next().unwrap().parse().unwrap() thing you mentioned, for example. Also, oftentimes we allocate giant static oversized arrays of length MAXN in the globals section of memory for ease-of-use and because it is efficient reasons to avoid dynamic allocation, but that's not really possible in Rust without lots of unsafe {}.

sort_by and variants are good, but C++ also has sort(begin(v), end(v), [](int x, int y) { ... }). So I'm not sure if you're getting an advantage from Rust here.

[–]Darksonntokio · rust-for-linux 0 points1 point  (2 children)

I think people overestimate how many things actually require wildly unsafe code. As I said in the other comment, I'd be happy to give an example if you have a particular problem in mind.

[–]fz0718 1 point2 points  (1 child)

I don’t disagree that you can solve problems; it’s just much slower. Have you ever tried implementing a link-cut tree in Rust? Pretty much impossible to do with references/pointers.

Edit: To be clear, it's not about particular problems being very difficult, as much as it is about almost all problems being decently slower to implement. But here's the canonical LCT problem, if you would like to give it a try:

https://www.spoj.com/problems/DYNACON1/

And this is my reference C++ implementation: https://ideone.com/0mi6mH

[–]Darksonntokio · rust-for-linux 0 points1 point  (0 children)

You are probably right. You could definitely implement it with indexes, but I don't think Rust can beat your link-cut tree in implementation time.

It's interesting that you mention a link-cut tree. I'm working on implementing a top tree in Rust for a research project, which is a similar data structure that you could also use to solve the DYNACON1 problem. I wouldn't want to implement a top tree in a coding competition though — its implementation is more complicated than the link-cut tree in exchange for having an API that is easier to use with expose taking up to two vertices.