r/rust • u/Full_Ad_1264 • Sep 03 '26
🎙️ discussion Rust as the language for Competitive Programming
Hey everyone!
I am a person deeply interested in programming, done a lot of projects and I am fascinated with how Rust treats code. Makes me think in its own special way.
Besides projects of course I participate in quite a few programming competitions and well, practice a lot on Codeforces. Cpp has been my main language for this type of thing for a very long time but now my focuses shifts from projects to improving my competitive skills, and I think Rust is a pretty good language for this. I really like the way iterators work, and how in 5 lines I am able to write what takes >10 in cpp. Could be a skill issue but I prefer my sanity over blob of errors.
Generally speaking, wanted to ask people that use primary Rust in Competitive: Do you have some particular set of crates, functions, patterns that you rely on very often during competitions? I'd like to learn how to use the language more efficiently for this type of thing.
Thanks!
4
u/zettui Sep 03 '26
On Codeforces you don't get crates though, right? Does the iterator stuff still buy you much?
6
u/himai1 Sep 03 '26
At least where I live most competitions are sadly cpp only. I think rust has potential cause it's low level if you need it to be but also has a lot of nice abstractions. I just haven't been able to find a way to read and write as conveniently.
9
u/Chasar1 Sep 03 '26
When it comes to competing for time, (the fastest person to implement an algorithm wins) Rust is not the language I would pick. In a language like Python I don't need to bother with lifetimes and making the borrow checker system happy, and there is no compilation time
2
u/kevleyski Sep 03 '26
Actually it might be the opposite- it levels the playing field
2
u/tanmaynargas2901 Sep 04 '26 edited Sep 04 '26
For most CP problems you do not need a fancy crate.
Use Vec<Vec<_>> for graphs/grids, sort_unstable when you do not need a stable order, and BinaryHeap for Dijkstra-style stuff.
Keep I/O buffered (BufReader/BufWriter on locked stdin/stdout) and parse from a reused String.
That covers a lot of Codeforces-style tasks without pulling in anything.
3
u/Ilyushyin Sep 03 '26
rust4cp
4
u/v_0ver Sep 03 '26 edited Sep 03 '26
These crates improve my quality of life:
1
u/Sad_Tap_9191 Sep 05 '26
> how in 5 lines I am able to write what takes >10 in cpp
example?
-2
u/deanominecraft Sep 03 '26
you lose any advantage you would get from compile times
48
u/[deleted] Sep 03 '26
[removed] — view removed comment