Introduction to Competitive Programming

Authors: Nathan Wang, Benjamin Qi, Darren Yao

Programming competitions, including the USA Computing Olympiad.

Edit This Page

Programming Competitions

A programming competition generally lasts for several hours and consists of a set of problems. These problems are not open problems; they have already been solved by the problem writers and testers and are designed to be solved in the short timeframe of a contest. In general, each problem in competitive programming is solved with a two-step process:

  1. coming up with the algorithm, which involves problem solving skills and intuition
  2. implementing the algorithm, which requires programming skills to translate the algorithm into working code.

For each problem, you submit the completed code to a grader, which checks the answers calculated by your program against a set of predetermined test cases. For each problem, you are given a time limit (usually 2 seconds) and a memory limit (usually 256 megabytes) that your program must satisfy.

For those of you with experience in software development, note that competitive programming is quite different, as the goal is to write programs that compute the correct answer, run quickly, and can be implemented quickly. Note that nowhere was maintainability of code mentioned. You don't need to bother documenting your code because it only needs to be readable to you during the contest. That being said, you probably want to maintain a bare minimum level of readability so you can keep track of what's going on.

William Lin

video shown above

Kamil Debowski

algorithms & programming contests


competitive programming, contests


examples of algorithms

Here is a task similar to the one that was solved in Kamil's video:

Focus Problem – try your best to solve this problem before continuing!


If you have prior programming experience we encourage you to register a Kattis account and submit a solution. If not, feel free to skip ahead to the solution.

Solution - Basketball One-on-One

Just print the second-to-last character of the input.


#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << s[s.size() - 2];




import java.util.Scanner;
public class basketballoneonone {
public static void main(String[] args) {
Scanner in = new Scanner(;
String s =;
System.out.println(s.charAt(s.length() - 2));


The USA Computing Olympiad is a national programming competition that occurs four times a year, with December, January, February, and US Open (March) contests. The regular contests are four hours long, and the US Open is five hours long. Each contest contains three problems. Solutions are evaluated and scored against a set of predetermined test cases. Scoring is out of 1000 points, with each problem being weighted equally (~333 points). There are four divisions of contests: Bronze, Silver, Gold, and Platinum. After each contest, students who meet the contest-dependent cutoff for promotion will compete in the next division for future contests.

See the USACO FAQ for more information.

Module Progress:

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!