> ## Documentation Index
> Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Contest Strategy

> Master the art of winning at Codeforces, ICPC, and competitive programming contests

# Contest Strategy

## The Winning Mindset

Raw skill is not enough. The best competitive programmers combine technical knowledge with strategic thinking. This chapter covers the meta-skills that separate winners from participants.

<Note>
  **The Three Pillars of Contest Success**:

  1. **Speed**: Solve easy problems fast
  2. **Accuracy**: Minimize wrong submissions
  3. **Strategy**: Choose problems wisely
</Note>

***

## Understanding Contest Formats

### Codeforces Format

| Division | Rating Range | Problem Difficulty                                |
| -------- | ------------ | ------------------------------------------------- |
| Div 3    | \< 1600      | A: 800, B: 1000-1200, C: 1200-1400, D: 1400-1600  |
| Div 2    | \< 2100      | A: 800-1000, B: 1200-1400, C: 1500-1700, D: 1800+ |
| Div 1    | 1900+        | A: 1700+, problems get very hard                  |

**Scoring**: Points decrease over time. Penalty for wrong submissions.

**Strategy by Rating**:

* 800-1200: Focus on solving A and B quickly
* 1200-1400: Solve A, B, C; attempt D
* 1400-1600: Solve A-D consistently; attempt E
* 1600+: Speed on A-C, deep thinking on D+

### ICPC Format

* **Team of 3, 1 computer**
* **5 hours, 10-13 problems**
* **Scoring**: Most problems solved, then fewest penalty minutes
* **No partial credit**: Solution must pass all test cases

**ICPC Strategy**:

* Assign problems by specialty (graphs, DP, math, etc.)
* One person reads while another codes
* Easy problems first to build momentum
* Keep one person thinking about hard problems

***

## The First 10 Minutes

These opening minutes can define your contest.

### Codeforces Routine

```
0:00 - Read Problem A
0:02 - Code and submit A
0:05 - Read Problem B
0:08 - Start coding B
```

<Warning>
  **Don't lose rating on A and B!**

  * Read carefully. Miss a constraint, lose 10 minutes.
  * Check edge cases before submitting.
  * If stuck for 5 minutes on A/B, you misread something.
</Warning>

### ICPC Routine

```
Member 1: Read A, B, C
Member 2: Read D, E, F
Member 3: Read G, H, I (or help with easier ones)

Immediately share: "A is easy [topic], B is [topic], etc."
```

***

## Reading Problems Effectively

### The 3-Read Method

1. **Skim** (30 seconds): What type of problem is this?
2. **Detailed Read** (2 minutes): Constraints, examples, edge cases
3. **Verification** (30 seconds): Reread the output format

### Constraint Analysis Cheat Sheet

| Constraint | Maximum Complexity      | Typical Algorithm                    |
| ---------- | ----------------------- | ------------------------------------ |
| n ≤ 10     | O(n!)                   | Brute force, backtracking            |
| n ≤ 20     | O(2^n)                  | Bitmask DP, meet in middle           |
| n ≤ 100    | O(n³)                   | Floyd-Warshall, 3 nested loops       |
| n ≤ 500    | O(n³) with optimization | Matrix DP                            |
| n ≤ 3000   | O(n²)                   | 2D DP, all pairs                     |
| n ≤ 10^5   | O(n log n)              | Sorting, segment tree, binary search |
| n ≤ 10^6   | O(n)                    | Linear algorithms                    |
| n ≤ 10^9   | O(log n) or O(1)        | Math, binary search on answer        |

***

## When You're Stuck

### The 5-Minute Rule

If you've been stuck for 5 minutes:

1. **Reread the problem** - Did you miss something?
2. **Check examples manually** - Trace through by hand
3. **Try small cases** - n = 1, 2, 3
4. **Consider related patterns** - What technique does this remind you of?

### Escape Strategies

```
Stuck on implementation → Write pseudocode first
Stuck on approach → List all techniques that might apply
Stuck on edge cases → Think: 0, 1, -1, empty, maximum
Stuck on TLE → What's the bottleneck? Can you precompute?
```

### When to Skip

Skip a problem if:

* You've spent 20+ minutes with no progress
* The problem type is unfamiliar
* Easier problems remain unsolved

***

## Debugging Under Pressure

### Prevention is Better

```cpp theme={null}
// Always use these before contest
#define int long long  // Prevent overflow bugs
const int INF = 1e18;  // Large enough for all cases

// Bounds check
assert(0 <= x && x < n);
```

### Stress Testing

```cpp theme={null}
// Generate random test
void generateTest() {
    int n = rand() % 100 + 1;
    // Generate random input
}

// Compare brute force with optimized
while (true) {
    auto input = generateTest();
    auto ans1 = bruteForce(input);
    auto ans2 = optimized(input);
    if (ans1 != ans2) {
        // Print failing test
        break;
    }
}
```

### Common Bug Checklist

* Integer overflow (use `long long`)
* Array index out of bounds
* Uninitialized variables
* Off-by-one errors
* Wrong variable name (copy-paste errors)
* Forgetting to reset globals between test cases
* 0-indexing vs 1-indexing mismatch

***

## Time Management

### Codeforces Time Budget (2 hours)

| Time      | Activity                              |
| --------- | ------------------------------------- |
| 0:00-0:15 | Solve A and B                         |
| 0:15-0:45 | Solve C                               |
| 0:45-1:15 | Solve D                               |
| 1:15-1:45 | Attempt E or revisit earlier problems |
| 1:45-2:00 | Clean up, submit what you have        |

### Know When to Code vs Think

* **Code immediately**: You see the pattern clearly
* **Think first**: Novel problem, unclear approach
* **Switch problems**: Stuck 15+ minutes, others unsolved

***

## The CP-31 Checklist

Before submitting, verify:

1. **Input/Output** - Correct format? Flushed output?
2. **Edge cases** - n=0? n=1? Empty arrays?
3. **Overflow** - Need `long long`? Multiplication overflow?
4. **Constraints** - Does complexity fit time limit?
5. **Array bounds** - Enough space allocated?

***

## Post-Contest Analysis

### After Every Contest

1. **Upsolve unsolved problems** - This is where real learning happens
2. **Analyze time spent** - Where did you lose time?
3. **Review wrong submissions** - What caused them?
4. **Tag problems by pattern** - Build your pattern database

### Rating Goals and Practice

| Current Rating | Weekly Goal    | Focus Areas                             |
| -------------- | -------------- | --------------------------------------- |
| \< 1200        | 5-10 problems  | Implementation, basic math, greedy      |
| 1200-1400      | 10-15 problems | Binary search, two pointers, basic DP   |
| 1400-1600      | 10-15 problems | Graphs, harder DP, segment tree basics  |
| 1600-1900      | 15-20 problems | Advanced data structures, number theory |

***

## Virtual Contests

Practice contests in real conditions.

```
Codeforces → Contests → Pick a past contest → "Virtual Participation" (right sidebar)
Or
Set 2-hour timer → No peeking at solutions
```

<Note>
  **Gym vs Virtual Contests**: Gym is for unofficial contests (university rounds, ICPC training, etc.). Virtual participation is for practicing official past Codeforces rounds.
</Note>

**Virtual Contest Rules**:

* No external resources (except template)
* No solution peeking
* Submit even if unsure
* Analyze performance afterward

***

## Building Your Template

A good template saves time and prevents bugs.

```cpp theme={null}
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

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

void solve() {
    // Your solution here
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1;
    cin >> t;  // Comment if single test
    
    while (t--) {
        solve();
    }
    
    return 0;
}
```

***

## Psychology of Competition

### Staying Calm

* **Before contest**: Light practice, don't try new techniques
* **During contest**: One problem at a time, deep breaths
* **After WA**: Re-read problem, don't panic-submit

### Managing Tilt

When frustrated:

1. Take 30 seconds away from screen
2. Re-read problem from scratch
3. Ask: "What am I assuming that might be wrong?"

### The Growth Mindset

* Every contest teaches something
* Rating fluctuates—focus on learning
* Celebrate progress, not just wins

***

## ICPC-Specific Tips

### Team Coordination

```
Team Roles:
- Primary Coder: Best at typing/implementation
- Problem Picker: Reads all problems, decides order
- Specialist: Deep knowledge in specific areas

Communication:
- "I think A is [greedy/DP/graph]"
- "I need the computer in 5 minutes"
- "I'm stuck, can you look at this?"
```

### Coding Efficiency

* Print code for debugging
* One person codes, one reviews
* Use simple variable names for speed

***

## Codeforces-Specific Tips

### Rating Optimization

* **Don't oversubmit**: Penalty adds up
* **Lock early if confident**: Extra points for others' failures
* **Check hacks during freeze**: Learn from others' approaches

### Handling Pretests vs System Tests

* Pretests are NOT comprehensive
* Always consider edge cases
* Stress test if time permits

***

## Your 30-Day Improvement Plan

| Week | Focus            | Daily Practice                 |
| ---- | ---------------- | ------------------------------ |
| 1    | Speed on A-B     | 5 Div 2A + 5 Div 2B            |
| 2    | C-level patterns | 5 Div 2C problems              |
| 3    | D-level problems | 3 Div 2D problems              |
| 4    | Full contests    | 2 virtual contests + upsolving |

***

## Key Takeaways

<CardGroup cols={2}>
  <Card title="Speed Matters" icon="gauge-high">
    Solve easy problems fast. Every minute counts.
  </Card>

  <Card title="Read Carefully" icon="book-open">
    Most mistakes come from misreading the problem.
  </Card>

  <Card title="Know When to Skip" icon="forward">
    20 minutes stuck? Move on, come back later.
  </Card>

  <Card title="Upsolve Always" icon="graduation-cap">
    Real learning happens after the contest.
  </Card>
</CardGroup>

***

## Final Words

Competitive programming is a marathon, not a sprint. Every problem solved, every contest participated in, adds to your skill set. The patterns you learn here—algorithmic thinking, debugging under pressure, time management—are invaluable beyond CP.

**Your journey to Specialist, Expert, Master, and beyond starts now.**

<Card title="Back to Course Overview" icon="arrow-left" href="/courses/competitive-programming/00-overview">
  Review the full course curriculum and continue your CP journey.
</Card>

***

## Resources

### Essential Practice Sites

* [Codeforces](https://codeforces.com) - Contests and problemset
* [CSES Problem Set](https://cses.fi/problemset/) - Curated 300 problems
* [AtCoder](https://atcoder.jp) - High-quality problems
* [LeetCode](https://leetcode.com) - Interview-style problems

### Learning Resources

* [CP-Algorithms](https://cp-algorithms.com) - Algorithm encyclopedia
* [USACO Guide](https://usaco.guide) - Structured curriculum
* [Codeforces EDU](https://codeforces.com/edu/courses) - Interactive courses

### Community

* Codeforces blogs and editorials
* Competitive Programming Discord servers
* ICPC practice with team

***

**Good luck. See you on the leaderboard.**
