ICPC Competitive Programming

Introduction to Competitive Programming

An introduction to the world of Competitive Programming and preparation for ICPC

Introduction to Competitive Programming

This document is prepared by KU SRC (Kasetsart University Sriracha Campus) as a guide for preparing for the ICPC (International Collegiate Programming Contest).

What is Competitive Programming?

Competitive Programming is a competition to solve computer problems within a limited time. Participants must:

  • Read problems and understand them
  • Design algorithms that are efficient
  • Write code that is correct and runs fast
  • Debug and fix errors

ICPC Competition

ICPC (International Collegiate Programming Contest) is an international programming competition for university students.

Competition Format

  • Teams of 3 people using 1 computer
  • Duration: 5 hours
  • Approximately 10-15 problems
  • Must solve as many problems as possible in the least time

Scoring Criteria

  1. Number of problems solved (more is better)
  2. Total time used (less is better)
  3. Penalty time from wrong submissions (+20 minutes per attempt)

Required Skills

1. Data Structures

// Common data structures used
vector<int> arr;           // Dynamic array
set<int> s;                // Balanced BST
map<int, int> m;           // Key-value mapping
priority_queue<int> pq;    // Heap

Data structures you should know:

  • Array, Vector, String
  • Stack, Queue, Deque
  • Set, Map (Hash & Balanced)
  • Priority Queue (Heap)
  • Disjoint Set Union (DSU)
  • Segment Tree, Fenwick Tree

2. Algorithms

// Sorting
sort(arr.begin(), arr.end());

// Binary search
int idx = lower_bound(arr.begin(), arr.end(), x) - arr.begin();

// BFS/DFS
void dfs(int u) {
    visited[u] = true;
    for (int v : adj[u]) {
        if (!visited[v]) dfs(v);
    }
}

Algorithms you should know:

  • Sorting & Searching
  • Graph (BFS, DFS, Dijkstra, MST)
  • Dynamic Programming
  • Number Theory (GCD, Prime, Modular)
  • String Algorithms (KMP, Hashing)

3. Programming Language

Most competitors use C++ because:

  • Fast execution
  • Rich Standard Template Library (STL)
  • Well-supported in all competitions

Template Code for Competition

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Solution here
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) solve();
    
    return 0;
}

Fast I/O

// Use this at the start of main()
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

// Or use scanf/printf for faster I/O
scanf("%d", &n);
printf("%d\n", ans);

Practice Resources

  1. Codeforces - Regular contests, large problem archive
  2. AtCoder - High-quality problems
  3. CSES Problem Set - Categorized problems for learning
  4. LeetCode - Good for beginners
  5. Kattis - ICPC-style problems

Tips for Beginners

  1. Start with basics - Make sure you understand data structures well
  2. Practice regularly - Solve at least 1-2 problems daily
  3. Learn from solutions - Read others’ code after solving
  4. Participate in contests - Join virtual or live contests regularly
  5. Don’t give up - Some problems take time to understand

“The key to success in competitive programming is consistent practice and learning from mistakes.”

Good luck with your competitive programming journey! 🚀