Skip to content
/ uva Public

UVa, CodeForces, and all things competitive programming.

Notifications You must be signed in to change notification settings

cbarnson/uva

Repository files navigation

Competitive Programming

UVa, CodeForces, and more

This repository was originally for UVa Online Judge solutions, but has expanded to encompass all things competitive programming. There's a healthy supply of CodeForces solutions, primarily in C++, but also some Python, and even Java. I've also used this repository as a space to collect useful code snippets, algorithms, and tricks that are worth having around.

Getting started

Most C++ programs you'll find in this repository are standalone, single-file. Most competitive programming contests and sites offer GNU GCC, so that's generally what we want to build with. But you always want to use the same compiler as the judging system you'll be submitting against, so don't just fire up your Visual Studio IDE without a second thought. Problems are meant to be solved in a contest-setting, which means (ideally) your code is relatively short, and certainly a single source file. Most people opt for a lighter editor like Emacs, Vim, or VS Code.

Compile / debugging

Compilation is almost always the same (see below), and you run your executable with input being piped in from a file, e.g. ./solution.exe < input.txt, and output to standard out (redirect to file with ./solution.exe < input.txt > output.txt).

I use several helper scripts to make this process of setup, testing, comparing, and (finally) submitting a little bit easier. These scripts constitute a variety of bash, sh, batch, and python files. The ones I use often are probably scattered about in the root of this workspace, and others have been archived to /archives/scripts. Have a look, hopefully you'll find something that works.

On Windows, I've recently enjoyed using MSYS2 since you get pacman. But you can also try Cygwin, or you can download MinGW-64 and use a MinTTY emulator like Git-bash. On Linux, just use whatever you have, as GCC is pretty universally accessible (on new setups of say, Ubuntu for example, you may need to run sudo apt-get install build-essential).

Once you're all setup, with your solution contained in a single C++ source file like main.cc file ready to go, compile with:

g++ -std=c++17 -Wall main.cc -o main.exe

Submission (CodeForces)

Lets say you are solving problem 1102E on CodeForces (here). You want to submit. From the problem page, on the side bar select the language and compiler:

Submission (UVa Online Judge)

Lets say you are solving problem 137 on UVa (here). You want to submit. From the main site: https://uva.onlinejudge.org/, login, and navigate to "Quick Submissions" on the side bar. From here, choose your compiler and either paste in your code or upload the source file.

Links

Online judging systems and problem databases

Online judges

Past contests

Learning

Licensing

The code in this project is licensed under MIT license.

The MIT License (MIT)

Copyright (c) 2019 C. Barnson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.