What is Competitive Programming?
Discover the world's most exciting brain sport — where coding meets competition!
Open interactive version (quiz + challenge)Real-world analogy
What is it?
Competitive Programming (CP) is a mind sport where participants solve well-defined programming problems within a time limit. You read a problem, think of a solution, write code, and submit it to an automated judge that instantly tells you if you are right or wrong. It combines logical thinking, math, and coding into one thrilling activity.
Real-world relevance
CP skills are used everywhere in the real world. Search engines like Google use algorithms to find the best results in milliseconds. GPS apps use shortest-path algorithms (a classic CP topic) to find the fastest route to your destination. Video games use optimization to render millions of pixels smoothly. Even social media feeds use sorting and filtering — all things you learn in CP!
Key points
- CP is a Brain Sport — Competitive Programming (CP) is like chess, but instead of moving pieces, you solve puzzles by writing code. Thousands of people around the world compete to solve problems the fastest. It is a real sport — with contests, rankings, and even world championships!
- How a CP Contest Works — In a contest, you get a set of problems (usually 4 to 8). Each problem describes something you need to calculate or figure out. You write code to solve it, submit your code to an online system, and it tells you if your answer is correct. The person who solves the most problems in the least time wins!
- Where People Compete — There are awesome websites where you can practice and compete. Codeforces is the most popular — it hosts contests almost every week. AtCoder is great for beginners with clean problems. LeetCode helps you prepare for job interviews. USACO is for high school students in the USA. All of them are free!
- What Are Verdicts? — When you submit your code, the system (called an online judge) checks it and gives you a verdict — like a grade. AC (Accepted) means your code is correct — hooray! WA (Wrong Answer) means your output is wrong. TLE (Time Limit Exceeded) means your code is too slow. RE (Runtime Error) means your code crashed. MLE (Memory Limit Exceeded) means your code used too much memory.
- Why CP is Amazing for Your Brain — CP trains your brain to think logically and break big problems into small steps. It is like going to the gym, but for your mind! Every problem you solve makes you a stronger thinker. Scientists have shown that problem-solving practice improves your ability to learn anything else too.
- CP Helps You Get Great Jobs — Top tech companies like Google, Meta, Amazon, and Microsoft love CP coders. Why? Because CP proves you can think clearly under pressure and solve hard problems. Many job interviews ask the exact same type of problems you practice in CP. It is like training for a race — when race day comes, you are already prepared.
- Anyone Can Start — Yes, Even You! — You do not need to be a math genius or a coding expert. Many world-champion competitive programmers started when they were 10 or 12 years old with zero coding experience. The secret is simple: start easy, practice a little every day, and never give up. If you can follow a recipe, you can learn CP!
- Famous CP Contests Around the World — The biggest CP contest is the International Olympiad in Informatics (IOI) for high school students. For university students, there is ICPC (International Collegiate Programming Contest). Google hosts Code Jam, and Facebook hosts Hacker Cup. These contests have prizes, trips, and bragging rights!
- Your CP Journey Starts Now — In this course, we will go step by step — from writing your very first line of code all the way to solving real contest problems. No rushing, no skipping. Think of it like learning to ride a bicycle: first we use training wheels, then one day you will be doing wheelies!
Code example
#include <bits/stdc++.h> // Include all standard libraries at once
using namespace std; // So we can write cout instead of std::cout
int main() {
// Your very first CP-style program!
// It reads a number and prints a greeting.
int age; // Create a box to hold a whole number
cout << "How old are you? "; // Print a question to the screen
cin >> age; // Read the user's answer into our box
if (age < 13) { // Check: is the number less than 13?
cout << "Wow, a young CP champion in the making!" << endl;
} else { // Otherwise (13 or older)
cout << "Welcome to Competitive Programming!" << endl;
}
cout << "Let the adventure begin!" << endl; // One last message
return 0; // Tell the computer we are done
}Line-by-line walkthrough
- 1. We start with #include — this is a magic line that gives us access to ALL the tools C++ has. Think of it as opening a giant toolbox.
- 2. using namespace std; — this lets us use shortcuts like cout and cin without writing std:: in front every time. It saves us typing!
- 3. int main() { — this is where every C++ program starts running. It is like the starting line of a race. The computer begins here.
- 4. int age; — we create a memory box called 'age' that can hold a whole number. Right now the box is empty.
- 5. cout << "How old are you? "; — cout (see-out) prints text to the screen. The << arrows point toward cout, meaning 'send this text to the screen.'
- 6. cin >> age; — cin (see-in) waits for you to type something. The >> arrows point toward age, meaning 'put what the user typed into the age box.'
- 7. if (age < 13) { ... } — this checks a condition. If the age is less than 13, it runs the code inside the curly braces. Otherwise it skips to the else part.
- 8. else { ... } — if the condition above was false (age is 13 or more), the computer runs this code instead.
- 9. cout << "Let the adventure begin!" << endl; — prints one more message. endl means 'go to a new line' (like pressing Enter).
- 10. return 0; — this tells the computer 'I am done, everything went well.' The 0 means 'no errors.' It is like saying 'The End' in a story.
Spot the bug
#include <bits/stdc++.h>
using namespace std;
int main() {
int score;
cin >> score;
if (score = 100) {
cout << "Perfect score!" << endl;
}
return 0;
}Need a hint?
Show answer
Explain like I'm 5
Fun fact
Hands-on challenge
More resources
- Codeforces — The Most Popular CP Platform (Codeforces)
- USACO Guide — Structured CP Learning Path (USACO)
- What is Competitive Programming? (Beginner Intro) (YouTube)