Skip to main content

Codeforces Survival Guide

From LeetCode to Codeforces

You’ve grinded LeetCode. You understand algorithms. But Codeforces? It’s a different beast. This guide will help you survive and thrive.

Understanding the Rating System

Rating Colors & Titles

RatingTitleColorWhat It Means
0-1199NewbieGrayJust starting out
1200-1399PupilGreenUnderstand basics
1400-1599SpecialistCyanSolid fundamentals
1600-1899ExpertBlueStrong problem solver
1900-2099Candidate MasterVioletVery strong
2100-2299MasterOrangeTop competitor
2300-2399International MasterOrangeElite
2400-2599GrandmasterRedWorld class
2600-2999International GrandmasterRedLegend
3000+Legendary GrandmasterBlack/RedMythical

Rating Changes

Rating Change = K × (Actual Score - Expected Score)

Where:
- K depends on your rating and contest participation
- New accounts have higher K (faster rating changes)
- Expected score based on your current rating vs opponents
Pro Tip: Your first 6 contests have inflated K values. Focus on performing well early!

Contest Types

Division 4 (Div 4)

  • Who: Rated < 1400
  • Difficulty: A (800) to G (1400)
  • Duration: 2 hours, 7-8 problems
  • Strategy: Solve A-E quickly, attempt F-G
  • Best for: Complete beginners, first-time CF users, building confidence
  • Frequency: Every 4-6 months (less frequent than Div 2/3)

Division 3 (Div 3)

  • Who: Rated < 1600
  • Difficulty: A (800) to F (1600)
  • Duration: 2 hours, 6-7 problems
  • Strategy: Solve A-D quickly, attempt E-F
  • Best for: Beginners who are comfortable with basics

Division 2 (Div 2)

  • Who: Rated < 2100
  • Difficulty: A (800-1000) to E/F (2000+)
  • Duration: 2 hours, 5-6 problems
  • Strategy: Solve A-C, attempt D
  • Best for: Reaching Specialist/Expert

Division 1+2 (Combined)

  • Who: Everyone is rated (no rating cutoff)
  • Difficulty: A (1000-1200) to F/G (2400+)
  • Duration: 2-2.5 hours, 6-7 problems
  • Strategy: Same problems for all participants
  • Best for: Intermediate difficulty between Div 2 and Div 1
  • Note: A-B problems are harder than typical Div 2 A-B

Division 1 (Div 1)

  • Who: Rated ≥ 1900
  • Difficulty: Starts at ~1700
  • Best for: Expert+ grinders

Educational Rounds

  • Rated: For all < 2100
  • Special: 12-hour hacking phase after
  • Format: Similar to Div 2

Global Rounds

  • Who: Everyone rated
  • Difficulty: Wide range
  • Duration: Usually 2.5-3 hours

The Contest Interface

Before Contest

┌─────────────────────────────────────────────┐
│  1. Register for the contest                │
│  2. Check your template compiles            │
│  3. Have input.txt ready                    │
│  4. Close distracting tabs                  │
│  5. Get water/snacks ready                  │
└─────────────────────────────────────────────┘

During Contest

Problems     → List of all problems
Standings    → Real-time leaderboard
Submit       → Submit your solution
My Submissions → Check verdicts

Verdict Meanings

VerdictMeaningWhat to Do
ACAccepted (pretests)Wait for system test
WAWrong AnswerCheck logic, edge cases
TLETime Limit ExceededOptimize algorithm
MLEMemory Limit ExceededUse less memory
RERuntime ErrorArray bounds, division by zero
CECompilation ErrorSyntax error
PRETESTS ≠ ACCEPTEDDuring contest, you only pass pretests. After contest ends, your solution runs on the full test set (system test). Many solutions fail system tests!

Reading CF Problems

Anatomy of a CF Problem

┌─────────────────────────────────────────────────────┐
│  PROBLEM TITLE                                      │
├─────────────────────────────────────────────────────┤
│  Time limit: 1 second                               │
│  Memory limit: 256 megabytes                        │
├─────────────────────────────────────────────────────┤
│  [Story/Context - often skip-able]                  │
│                                                     │
│  [Actual problem statement - READ CAREFULLY]        │
│                                                     │
│  [Constraints - VERY IMPORTANT]                     │
├─────────────────────────────────────────────────────┤
│  Input                                              │
│  [Input format description]                         │
│                                                     │
│  Output                                             │
│  [Output format description]                        │
├─────────────────────────────────────────────────────┤
│  Examples                                           │
│  Input:         Output:                             │
│  3              6                                   │
│  1 2 3                                              │
├─────────────────────────────────────────────────────┤
│  Note                                               │
│  [Explanation of examples - very helpful!]          │
└─────────────────────────────────────────────────────┘

How to Read (The Right Way)

1

Skim the Story (10 seconds)

Most CF problems have elaborate stories. Skim for keywords.
2

Read Constraints FIRST (30 seconds)

This tells you what complexity is acceptable.
  • n ≤ 100 → O(n³) OK
  • n ≤ 10⁵ → Need O(n log n) or O(n)
  • n ≤ 10⁶ → Must be O(n)
3

Read Problem Statement (1-2 minutes)

Understand what you need to compute/output.
4

Study Examples (1 minute)

Trace through by hand. Read the Note section!
5

Check Edge Cases

What if n=1? What if all elements are same?

Input/Output Differences from LeetCode

LeetCode Style

class Solution:
    def solve(self, nums: List[int]) -> int:
        return sum(nums)

Codeforces Style

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    
    long long sum = 0;
    for (int x : nums) sum += x;
    
    cout << sum << "\n";
    
    return 0;
}

Multiple Test Cases

Most CF problems have multiple test cases!
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        // Solve one test case
        int n;
        cin >> n;
        // ... solution ...
        cout << answer << "\n";
    }
    
    return 0;
}
Common Mistake: Forgetting to reset variables between test cases!
// WRONG - 'seen' accumulates across test cases
set<int> seen;  // Global

void solve() {
    // seen still has data from previous test case!
}

// CORRECT - reset or declare inside
void solve() {
    set<int> seen;  // Fresh each time
    // ...
}

Common CF Input Patterns

Pattern 1: Single Line of Numbers

Input:
5
1 2 3 4 5
int n;
cin >> n;
vector<int> a(n);
for (int& x : a) cin >> x;

Pattern 2: Matrix/Grid

Input:
3 4
1 2 3 4
5 6 7 8
9 10 11 12
int n, m;
cin >> n >> m;
vector<vector<int>> grid(n, vector<int>(m));
for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        cin >> grid[i][j];

Pattern 3: String Grid

Input:
3 3
...
.#.
...
int n, m;
cin >> n >> m;
vector<string> grid(n);
for (int i = 0; i < n; i++) cin >> grid[i];
// Access: grid[i][j]

Pattern 4: Graph Edges

Input:
4 5
1 2
2 3
3 4
4 1
1 3
int n, m;
cin >> n >> m;
vector<vector<int>> adj(n + 1);
for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);  // If undirected
}

Pattern 5: Queries

Input:
5 3
1 2 3 4 5
1 3
2 4
1 5
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int& x : a) cin >> x;

while (q--) {
    int l, r;
    cin >> l >> r;
    // Process query [l, r]
}

Output Patterns

YES/NO Questions

// Always check problem for exact format
cout << (condition ? "YES" : "NO") << "\n";
// Some problems want "Yes"/"No" or "yes"/"no"

Impossible Cases

if (impossible) {
    cout << -1 << "\n";  // or "NO" or "Impossible"
    return;
}

Floating Point

cout << fixed << setprecision(9) << answer << "\n";

Multiple Values

cout << a << " " << b << " " << c << "\n";

// Array output
for (int i = 0; i < n; i++) {
    cout << arr[i] << " \n"[i == n - 1];
}

Debugging on Codeforces

Using Custom Test

  1. After submitting (or before), go to problem page
  2. Scroll down to “Custom Test”
  3. Enter your test case
  4. Run and see output

Creating Test Cases

When you get WA, try:
  1. Edge cases: n=1, n=2, all same, all different
  2. Boundary values: Maximum n, minimum values
  3. Special patterns: Sorted, reverse sorted, alternating

Stress Testing

Compare your solution with a brute force on random inputs:
// Generate random test
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n = rng() % 10 + 1;
vector<int> a(n);
for (int& x : a) x = rng() % 100;

Your First Week Checklist

1

Create Account

Register at codeforces.com
2

Set Up Environment

Install VS Code + extensions + template
3

Solve 10 Problems Rated 800

Get comfortable with the format
4

Do a Virtual Contest

Go to Contests → Pick a past contest → Click “Virtual Participation” on the right sidebar
5

Participate in Live Contest

Register for next Div 3 or Div 4
6

Upsolve

Solve problems you couldn’t during contest

ResourcePurpose
ProblemsetFilter by rating/tags
GymPractice contests
EDU SectionInteractive courses
BlogEditorials, discussions
CSESStructured problem set

Key Takeaways

Read Constraints First

Constraints tell you what algorithm to use.

Handle Test Cases

Most problems have multiple test cases.

Use Fast I/O

Always use sync_with_stdio(false).

Upsolve Everything

Learning happens after the contest.

Next Up

Fast I/O & Templates

Set up your competitive programming template.