📖 The Mistake Journal System
Every wrong answer contains a lesson. Most competitive programmers make the same mistakes repeatedly because they don’t track them. This chapter gives you a systematic approach to eliminate recurring errors and accelerate your improvement.
🧠 Why Mistakes Repeat
The brutal truth: Without tracking, you will make the same mistake 10+ times before it sticks. With tracking, you can reduce that to 2-3 times.
The Memory Problem
// Week 1: You get WA due to integer overflow
// You fix it and move on
// Week 3: You forget about integer overflow
// You get WA again, spend 30 minutes debugging
// Week 5: Same mistake, same frustration
// You feel like you're not improving
// THE FIX: Write it down. Review it. Never forget.
The 5 Categories of CP Mistakes
| Category | Description | Example |
|---|
| Syntax | Language/compiler errors | Forgetting semicolon, wrong brackets |
| Logic | Algorithm is fundamentally wrong | Wrong recurrence relation |
| Implementation | Right idea, wrong code | Off-by-one, wrong index |
| Edge Cases | Works for most, fails for extremes | n=0, n=1, empty string |
| Careless | Silly mistakes under pressure | Wrong variable name, copy-paste error |
✏️ Setting Up Your Mistake Journal
Option 1: Notion Template
## Mistake Entry #[number]
**Date:** YYYY-MM-DD
**Problem:** [Problem Name + Link]
**Mistake Category:** [Syntax / Logic / Implementation / Edge Case / Careless]
### What Happened
[Describe the mistake in 1-2 sentences]
### The Code That Was Wrong
```cpp
// Paste the buggy code here
The Correct Code
// Paste the fixed code here
Root Cause Analysis
- Why did I make this mistake?
- What was I thinking when I wrote it?
- What should I have done differently?
Prevention Strategy
- How will I catch this next time?
- What mental check should I add?
- Any template/snippet to prevent this?
#overflow #off-by-one #edge-case #modulo #binary-search
### Option 2: Simple Spreadsheet
| Date | Problem | Category | Mistake | Fix | Prevention | Tags |
|------|---------|----------|---------|-----|------------|------|
| 2024-01-15 | CF 1234A | Overflow | Used int for n*n | Cast to ll | Always ll for products | #overflow |
| 2024-01-16 | CF 1235B | Edge | Empty string | Check s.empty() | Test n=0 first | #edge #string |
### Option 3: VS Code Snippets
Create a snippets file that grows from your mistakes:
```json
{
"Safe Modular Add": {
"prefix": "modadd",
"body": [
"((${1:a} % MOD) + (${2:b} % MOD) + MOD) % MOD"
],
"description": "Mistake #14: Negative mod issue"
},
"Binary Search Template": {
"prefix": "binsearch",
"body": [
"int lo = 0, hi = n - 1;",
"while (lo < hi) {",
" int mid = lo + (hi - lo) / 2;",
" if (${1:condition}) hi = mid;",
" else lo = mid + 1;",
"}",
"// Answer is at index lo"
],
"description": "Mistake #23: Binary search off-by-one"
}
}
🗄️ The Master Mistake Database
Top 50 Common CP Mistakes
Build your own database. Here’s a starter:
Integer Overflow (THE #1 KILLER)
// MISTAKE: Using int for large products
int n = 1e5;
int result = n * n; // OVERFLOW!
// FIX: Always use long long for products
long long result = (long long)n * n; // Correct
Off-By-One Errors
// MISTAKE: Wrong loop bounds
for (int i = 0; i <= n; i++) {
arr[i] = 0; // Access arr[n] - out of bounds!
}
// FIX: Use < n for 0-indexed arrays
for (int i = 0; i < n; i++) {
arr[i] = 0;
}
Modular Arithmetic Pitfalls
// MISTAKE: Negative numbers in modulo
int x = -5 % 3; // Result is -2 in C++!
// FIX: Safe modulo
int safe_mod(int x, int m) {
return ((x % m) + m) % m;
}
Binary Search Edge Cases
// MISTAKE: Infinite loop
while (lo <= hi) {
int mid = (lo + hi) / 2; // Can overflow!
if (arr[mid] < target) lo = mid; // INFINITE LOOP!
}
// FIX: Correct binary search
while (lo < hi) {
int mid = lo + (hi - lo) / 2; // Safe from overflow
if (arr[mid] < target) lo = mid + 1;
else hi = mid;
}
Graph Algorithm Mistakes
// MISTAKE: Not resetting visited array between test cases
bool visited[N];
void solve() {
// visited still has values from previous test!
}
// FIX: Reset at start of each test case
void solve() {
memset(visited, false, sizeof(visited));
// or
fill(visited, visited + n, false);
}
String Processing Errors
// MISTAKE: Using cin >> s for strings with spaces
string s;
cin >> s; // Only reads until first space!
// FIX: Use getline for full line
getline(cin, s);
// WATCH OUT: After cin >> n, you need cin.ignore()
int n; cin >> n;
cin.ignore();
getline(cin, s);
Array Initialization
// MISTAKE: Assuming global arrays are initialized
int dp[N][M]; // Local: RANDOM values!
// FIX: Always initialize
int dp[N][M] = {}; // All zeros
// or
memset(dp, 0, sizeof(dp));
memset(dp, -1, sizeof(dp)); // Works for -1 and 0 only!
// For other values, use fill
fill(&dp[0][0], &dp[0][0] + N*M, INF);
📊 Analyzing Your Mistakes
Weekly Mistake Review
Every Sunday, review your mistake journal:
Count by Category
How many of each type did you make this week?
- Overflow: 3
- Edge cases: 5
- Logic: 2
Focus next week on edge cases! Identify Patterns
Are certain topics causing more mistakes?
- Binary search: 4 mistakes
- DP: 1 mistake
Study binary search more! Check for Repeats
Did you make any mistake you’ve made before?
- Integer overflow: Made it twice this week!
Add reminder to pre-coding checklist! Update Your Checklist
Add the most common mistakes to your pre-submit checklist.
Monthly Mistake Trends
Track these metrics monthly:
- Total mistakes per week (should decrease)
- Repeat mistakes (should decrease faster)
- Time to debug (should decrease)
- New mistake types (sign of tackling harder problems)
🛡️ The Prevention System
Pre-Coding Checklist
Before you start coding ANY problem, ask:
☐ Does this problem involve large numbers? → Use long long
☐ Am I working with arrays? → Double-check bounds
☐ Is there modular arithmetic? → Use safe_mod function
☐ Multiple test cases? → Reset all global variables
☐ String input after integers? → cin.ignore() before getline
☐ Binary search needed? → Use tested template
Pre-Submit Checklist
Before hitting submit, verify:
☐ All variables use correct data types
☐ Array indices are within bounds
☐ Edge cases handled (n=0, n=1, empty input)
☐ Output format matches exactly (spaces, newlines)
☐ All test cases produce correct output
☐ No debug statements left in code (cerr, cout)
The “5 Second Rule”
Before submitting, pause for 5 seconds and scan for:
- Data types (int vs long long)
- Loop bounds (
< vs <=)
- Edge cases (n=0, n=1)
- Output format (newlines, spaces)
- Debug output (remove cerr/cout debugging)
📋 Mistake Templates by Topic
Binary Search Mistakes
// Template: Safe binary search (lower bound)
int binary_search_lower(vector<int>& arr, int target) {
int lo = 0, hi = arr.size(); // hi = size, not size-1
while (lo < hi) {
int mid = lo + (hi - lo) / 2; // Prevent overflow
if (arr[mid] < target) lo = mid + 1;
else hi = mid;
}
return lo; // First element >= target
}
// Common mistake: Using <= in while condition with this template
// Common mistake: Using (lo + hi) / 2 → can overflow
// Common mistake: lo = mid instead of lo = mid + 1 → infinite loop
DP Mistakes
// Template: Safe DP initialization
const long long INF = 1e18; // Not INT_MAX (adding to it overflows)
vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, INF));
// Common mistakes:
// 1. Using INT_MAX → addition causes overflow
// 2. Wrong dimension order
// 3. Not handling base cases
// 4. Wrong recurrence order (depends on what values)
Graph Mistakes
// Template: Safe BFS
void bfs(int start) {
queue<int> q;
vector<bool> visited(n + 1, false); // Always declare locally!
q.push(start);
visited[start] = true; // Mark BEFORE pushing
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
if (!visited[v]) {
visited[v] = true; // Mark BEFORE pushing
q.push(v);
}
}
}
}
// Common mistakes:
// 1. Marking visited AFTER pushing → duplicates in queue
// 2. Not resetting visited between test cases
// 3. Wrong graph size (1-indexed vs 0-indexed)
⚡ Quick Reference: The Mistake Lookup Table
When you get WA or TLE, check this table:
| Symptom | Likely Cause | Quick Fix |
|---|
| Wrong Answer on large input | Integer overflow | Cast to long long |
| Wrong Answer on sample | Logic error | Re-read problem, trace by hand |
| Wrong Answer test 2 | Edge case (n=1) | Add special case handling |
| Time Limit Exceeded | Algorithm too slow | Optimize or change approach |
| TLE with O(n²) | Need O(n log n) | Use sorting/binary search/map |
| Runtime Error | Array out of bounds | Check all array accesses |
| Runtime Error | Stack overflow | Convert recursion to iteration |
| Wrong Answer random tests | Off-by-one error | Check loop bounds carefully |
| Works locally, fails online | Uninitialized variables | Initialize everything |
🎓 Building Mistake Immunity
The 3-Strike Rule
If you make the same mistake 3 times:
- Create a snippet to prevent it
- Add it to pre-submit checklist
- Teach it to someone else (explaining cements memory)
The Mistake Flashcard System
Create flashcards for your top mistakes:
FRONT: Integer overflow in multiplication
BACK: Always cast at least one operand to long long
(long long)a * b NOT (long long)(a * b)
Review flashcards weekly before contests.
The “Never Again” List
Keep a pinned list of your top 5 most frustrating mistakes:
MY "NEVER AGAIN" LIST:
1. Integer overflow in n*n → ALWAYS use long long
2. Forgot to reset visited[] → Reset at start of solve()
3. Wrong binary search termination → Use tested template
4. Modulo with negative numbers → Use safe_mod()
5. Reading string after int → Always cin.ignore()
Read this before every contest.
Your mistakes are your competitive advantage.Most people make mistakes and forget them. If you track, analyze, and systematically eliminate your mistakes, you’ll improve faster than 90% of competitors.Start your mistake journal TODAY.