From e23f55e5339316c58f8224575844478c968dea48 Mon Sep 17 00:00:00 2001 From: Hieu Date: Fri, 20 Mar 2026 22:14:52 +0700 Subject: [PATCH 01/11] docs: add explicit problem-creator and problem-review skill references to implementation plan --- .../2026-03-20-leetcode-curriculum-design.md | 386 +++++++++ ...3-20-leetcode-curriculum-implementation.md | 782 ++++++++++++++++++ 2 files changed, 1168 insertions(+) create mode 100644 plans/2026-03-20-leetcode-curriculum-design.md create mode 100644 plans/2026-03-20-leetcode-curriculum-implementation.md diff --git a/plans/2026-03-20-leetcode-curriculum-design.md b/plans/2026-03-20-leetcode-curriculum-design.md new file mode 100644 index 0000000..6336973 --- /dev/null +++ b/plans/2026-03-20-leetcode-curriculum-design.md @@ -0,0 +1,386 @@ +# LCOJ LeetCode-Style Curriculum Track Design + +**Date:** 2026-03-20 +**Status:** Approved +**Target:** Mixed audience (beginners to competitive programmers) + +--- + +## Problem Statement + +LCOJ has 2206 public problems but lacks coverage in fundamental CS/algorithm topics +that are standard on platforms like LeetCode. Key issues: + +- **8 completely missing topics:** Linked List, Binary Tree, BST, Fenwick Tree, + Trie, Two Pointers, Sliding Window, Topological Sort, Monotonic Stack +- **557 uncategorized problems** (25% of the problem set) +- **Broken difficulty distribution:** 922 problems at 1.0p, only 5 in 11-75 range +- **No difficulty progression within topics** — most topics only have easy problems + +## Solution: 150-Problem Curriculum Track + +A new set of 150 original problems covering 15 topic areas with Easy/Medium/Hard +difficulty progression, modeled after LeetCode's problem organization. + +### Distribution + +| Difficulty | Count | Points | +|---|---|---| +| Easy | 50 | 1.0-2.0p | +| Medium | 55 | 3.0-5.0p | +| Hard | 45 | 6.0-10.0p | + +### Problem Code Convention + +Format: `lc__` + +- Topic abbreviations: `arr`, `ll`, `stk`, `bt`, `bst`, `hp`, `tp`, `sw`, `bs`, + `gb`, `dp`, `gr`, `btbk`, `dc`, `bm`, `srt`, `trie`, `seg`, `bit`, `dsu`, + `ms`, `topo`, `nt`, `cmb`, `gt`, `str`, `hsh` +- Difficulty: `e` (easy), `m` (medium), `h` (hard) +- Number: 01-99 within each topic+difficulty + +Examples: `lc_tp_e01`, `lc_tree_m03`, `lc_dp_h02` + +### Test Cases + +Each problem gets 10-20 test cases generated via automated Python scripts: +- Small examples (hand-verifiable) +- Edge cases (empty, single element, boundary values) +- Max constraint stress tests +- Random generated cases for coverage + +--- + +## Complete Problem List + +### Data Structures (40 problems) + +#### Arrays & Strings (`arr`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| arr_e01 | Best Time to Buy and Sell Stock | E | Max profit single transaction | n <= 10^5 | +| arr_e02 | Rotate Array | E | Rotate array by k steps | n <= 10^5 | +| arr_e03 | Plus One | E | Add one to digit array | n <= 100 | +| arr_m01 | Product of Array Except Self | M | Product without division | n <= 10^5, O(n) time | +| arr_m02 | Spiral Matrix | M | Read matrix in spiral order | m,n <= 100 | +| arr_m03 | Subarray Sum Equals K | M | Count subarrays with sum k | n <= 2*10^4 | +| arr_h01 | First Missing Positive | H | Smallest missing positive | n <= 10^5, O(n) time | +| arr_h02 | Maximum Rectangle of 1s | H | Max rectangle of 1s in binary matrix | m,n <= 200 | + +#### Linked List (`ll`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| ll_e01 | Reverse Linked List | E | Reverse a singly linked list | n <= 5000 | +| ll_e02 | Merge Two Sorted Lists | E | Merge two sorted linked lists | m,n <= 500 | +| ll_e03 | Linked List Cycle | E | Detect cycle in linked list | n <= 10^4 | +| ll_m01 | Remove Nth Node From End | M | Remove nth node from end | n <= 30 | +| ll_m02 | Add Two Numbers | M | Add numbers as linked lists | n <= 100 | +| ll_m03 | Flatten Multilevel List | M | Flatten nested linked list | n <= 10^4 | +| ll_h01 | Merge K Sorted Lists | H | Merge k sorted linked lists | k <= 10^4 | +| ll_h02 | LRU Cache | H | Implement LRU cache | capacity <= 3000 | + +#### Stack & Queue (`stk`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| stk_e01 | Valid Parentheses | E | Check balanced parentheses | n <= 10^4 | +| stk_e02 | Implement Queue using Stacks | E | Queue with two stacks | n <= 100 ops | +| stk_e03 | Min Stack | E | Stack with O(1) min | n <= 10^4 | +| stk_m01 | Evaluate Reverse Polish Notation | M | Evaluate postfix expression | n <= 10^4 | +| stk_m02 | Decode String | M | Decode nested encoded string | n <= 30 | +| stk_m03 | Asteroid Collision | M | Simulate asteroid collisions | n <= 10^4 | +| stk_h01 | Basic Calculator | H | Evaluate expression with +,-,(,) | n <= 10^4 | +| stk_h02 | Longest Valid Parentheses | H | Longest valid parentheses substring | n <= 3*10^4 | + +#### Binary Tree (`bt`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| bt_e01 | Maximum Depth of Binary Tree | E | Find max depth | n <= 10^4 | +| bt_e02 | Invert Binary Tree | E | Mirror a binary tree | n <= 1000 | +| bt_e03 | Symmetric Tree | E | Check if tree is symmetric | n <= 1000 | +| bt_m01 | Binary Tree Level Order Traversal | M | BFS level-order traversal | n <= 2000 | +| bt_m02 | Construct from Inorder and Preorder | M | Build tree from traversals | n <= 3000 | +| bt_m03 | Lowest Common Ancestor | M | Find LCA of two nodes | n <= 10^5 | +| bt_h01 | Binary Tree Maximum Path Sum | H | Max path sum in binary tree | n <= 3*10^4 | +| bt_h02 | Serialize and Deserialize Binary Tree | H | Encode/decode binary tree | n <= 10^4 | + +#### BST (`bst`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| bst_e01 | Validate BST | E | Check if tree is valid BST | n <= 10^4 | +| bst_e02 | Kth Smallest Element in BST | E | Find kth smallest | n <= 10^4 | +| bst_m01 | BST Iterator | M | Inorder iterator for BST | n <= 10^5 | +| bst_h01 | Count of Range Sum | H | Count ranges in [lower, upper] | n <= 10^4 | + +#### Heap/Priority Queue (`hp`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| hp_e01 | Kth Largest Element | E | Find kth largest in array | n <= 10^5 | +| hp_e02 | Last Stone Weight | E | Simulate stone smashing | n <= 30 | +| hp_m01 | Task Scheduler | M | Min intervals for task scheduling | n <= 10^4 | +| hp_h01 | Find Median from Data Stream | H | Running median with two heaps | n <= 5*10^4 | + +--- + +### Algorithms (60 problems) + +#### Two Pointers (`tp`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| tp_e01 | Two Sum Sorted | E | Find pair with target sum in sorted array | n <= 10^5 | +| tp_e02 | Remove Duplicates from Sorted | E | Remove duplicates from sorted array | n <= 3*10^4 | +| tp_e03 | Move Zeroes | E | Move all zeroes to end | n <= 10^4 | +| tp_m01 | 3Sum | M | Find all triplets that sum to zero | n <= 3000 | +| tp_m02 | Container With Most Water | M | Max area between two vertical lines | n <= 10^5 | +| tp_m03 | Trapping Rain Water | M | Calculate trapped rain water | n <= 2*10^4 | +| tp_h01 | 4Sum Count | H | Count tuples summing to target | n <= 200 | +| tp_h02 | Minimum Window Subsequence | H | Min window containing subsequence | n <= 10^4 | + +#### Sliding Window (`sw`) — 6 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| sw_e01 | Max Average Subarray | E | Max average of k-length subarray | n <= 10^5 | +| sw_e02 | Contains Duplicate II | E | Duplicate within distance k | n <= 10^5 | +| sw_m01 | Longest Substring Without Repeating | M | Max length substring without repeats | n <= 5*10^4 | +| sw_m02 | Minimum Size Subarray Sum | M | Smallest subarray with sum >= target | n <= 10^5 | +| sw_h01 | Minimum Window Substring | H | Smallest window containing all chars | n <= 10^5 | +| sw_h02 | Sliding Window Maximum | H | Max element in each window of size k | n <= 10^5 | + +#### Binary Search (`bs`) — 6 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| bs_e01 | Binary Search | E | Standard binary search | n <= 10^4 | +| bs_e02 | Search Insert Position | E | Find insert position | n <= 10^4 | +| bs_m01 | Search in Rotated Sorted Array | M | Search in rotated array | n <= 5000 | +| bs_m02 | Find Peak Element | M | Find any peak element | n <= 1000 | +| bs_h01 | Median of Two Sorted Arrays | H | Find median in O(log(m+n)) | m,n <= 1000 | +| bs_h02 | Split Array Largest Sum | H | Minimize largest sum of m subarrays | n <= 1000 | + +#### DFS/BFS (`gb`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| gb_e01 | Number of Islands | E | Count islands in grid | m,n <= 300 | +| gb_e02 | Flood Fill | E | Fill connected region | m,n <= 50 | +| gb_e03 | Max Area of Island | E | Largest island area | m,n <= 50 | +| gb_m01 | Rotting Oranges | M | Time for all oranges to rot | m,n <= 10 | +| gb_m02 | Word Search | M | Find word in grid | m,n <= 6 | +| gb_m03 | Pacific Atlantic Water Flow | M | Cells flowing to both oceans | m,n <= 200 | +| gb_h01 | Word Ladder | H | Shortest transformation sequence | n <= 10, wordLen <= 10 | +| gb_h02 | Sudoku Solver | H | Solve sudoku with backtracking | 9x9 grid | + +#### Dynamic Programming (`dp`) — 10 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| dp_e01 | Climbing Stairs | E | Ways to reach top | n <= 45 | +| dp_e02 | House Robber | E | Max sum without adjacent | n <= 100 | +| dp_e03 | Maximum Subarray | E | Kadane's algorithm | n <= 10^5 | +| dp_m01 | Coin Change | M | Min coins to make amount | amount <= 10^4 | +| dp_m02 | Longest Increasing Subsequence | M | LIS length | n <= 2500 | +| dp_m03 | Unique Paths | M | Count paths in grid | m,n <= 100 | +| dp_m04 | Word Break | M | Can string be segmented | n <= 300 | +| dp_h01 | Longest Common Subsequence | H | LCS of two strings | m,n <= 1000 | +| dp_h02 | Edit Distance | H | Min operations to transform | m,n <= 500 | +| dp_h03 | Burst Balloons | H | Max coins from bursting balloons | n <= 300 | + +#### Greedy (`gr`) — 6 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| gr_e01 | Assign Cookies | E | Greedy cookie assignment | m,n <= 3*10^4 | +| gr_e02 | Lemonade Change | E | Can give correct change | n <= 100 | +| gr_m01 | Jump Game | M | Can reach last index | n <= 10^4 | +| gr_m02 | Partition Labels | M | Partition string into max parts | n <= 500 | +| gr_h01 | Candy | H | Min candies for ratings | n <= 2*10^4 | +| gr_h02 | IPO | H | Maximize capital | k <= 100, n <= 10^5 | + +#### Backtracking (`btbk`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| btbk_e01 | Subsets | E | All subsets of array | n <= 10 | +| btbk_m01 | Permutations | M | All permutations | n <= 6 | +| btbk_m02 | Combination Sum | M | Combinations summing to target | n <= 30, target <= 40 | +| btbk_h01 | N-Queens | H | Place n queens on board | n <= 9 | + +#### Divide & Conquer (`dc`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| dc_e01 | Merge Sort | E | Implement merge sort | n <= 10^5 | +| dc_e02 | Majority Element | E | Find majority element | n <= 5*10^4 | +| dc_m01 | Sort Colors | M | Dutch national flag | n <= 300 | +| dc_h01 | Count of Range Sum | H | Count ranges with merge sort | n <= 10^4 | + +#### Bit Manipulation (`bm`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| bm_e01 | Single Number | E | Find unique element | n <= 3*10^4 | +| bm_e02 | Counting Bits | E | Count 1-bits for 0 to n | n <= 10^5 | +| bm_m01 | Subsets II | M | All unique subsets | n <= 10 | +| bm_h01 | Max XOR of Two Numbers | H | Max XOR in array | n <= 2*10^4 | + +#### Sorting (`srt`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| srt_e01 | Sort Array by Parity | E | Evens before odds | n <= 5000 | +| srt_e02 | Squares of Sorted Array | E | Squares in sorted order | n <= 10^4 | +| srt_m01 | Merge Intervals | M | Merge overlapping intervals | n <= 10^4 | +| srt_m02 | Insert Interval | M | Insert and merge interval | n <= 10^4 | + +--- + +### Advanced Data Structures (25 problems) + +#### Trie (`trie`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| trie_e01 | Implement Trie | E | Insert, search, startsWith | n <= 2000 | +| trie_e02 | Longest Common Prefix | E | Find LCP of string array | n <= 200, len <= 200 | +| trie_m01 | Word Search II | M | Find words in board using trie | m,n <= 12 | +| trie_h01 | Design Search Autocomplete | H | Autocomplete system with ranking | n <= 100 | + +#### Segment Tree (`seg`) — 6 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| seg_e01 | Range Sum Query Mutable | E | Point update, range sum | n <= 3*10^4 | +| seg_e02 | Range Minimum Query | E | Point update, range min | n <= 3*10^4 | +| seg_m01 | Count of Range Sum | M | Count ranges with segment tree | n <= 10^4 | +| seg_m02 | My Calendar I | M | Booking without overlap | n <= 1000 | +| seg_h01 | Falling Squares | H | Max height from falling squares | n <= 1000 | +| seg_h02 | Rectangle Area II | H | Total area of overlapping rectangles | n <= 200 | + +#### Fenwick Tree/BIT (`bit`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| bit_e01 | Range Sum Query Mutable (BIT) | E | Point update, range sum | n <= 3*10^4 | +| bit_e02 | Count Inversions | E | Count inversions in array | n <= 10^5 | +| bit_m01 | Count of Smaller Numbers | M | Count smaller elements to right | n <= 10^4 | +| bit_h01 | 2D Range Sum Query | H | 2D BIT for rectangle queries | m,n <= 1000 | + +#### DSU/Union-Find (`dsu`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| dsu_e01 | Number of Connected Components | E | Count connected components | n <= 2000 | +| dsu_e02 | Redundant Connection | E | Find redundant edge | n <= 1000 | +| dsu_m01 | Accounts Merge | M | Merge accounts with common email | n <= 1000 | +| dsu_h01 | Largest Component Size by Factor | H | Largest component by common factor | n <= 2*10^4 | + +#### Monotonic Stack (`ms`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| ms_e01 | Next Greater Element | E | Next greater element for each | n <= 10^4 | +| ms_e02 | Daily Temperatures | E | Days until warmer temperature | n <= 10^5 | +| ms_m01 | Largest Rectangle in Histogram | M | Max rectangle in histogram | n <= 10^5 | +| ms_h01 | Maximal Rectangle | H | Max rectangle in binary matrix | m,n <= 200 | + +#### Topological Sort (`topo`) — 3 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| topo_e01 | Course Schedule | E | Can finish all courses | n <= 5000 | +| topo_m01 | Course Schedule II | M | Find valid course order | n <= 2000 | +| topo_h01 | Alien Dictionary | H | Derive character order from sorted words | n <= 100, wordLen <= 20 | + +--- + +### Math & Strings (25 problems) + +#### Number Theory (`nt`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| nt_e01 | Count Primes | E | Count primes less than n | n <= 5*10^6 | +| nt_e02 | Happy Number | E | Detect cycle in digit square sum | n <= 2^31-1 | +| nt_m01 | Super Pow | M | a^b mod 1337 | a <= 2^31-1, b digits <= 2000 | +| nt_h01 | Ugly Number III | H | Count ugly numbers in range | n <= 10^9 | + +#### Combinatorics (`cmb`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| cmb_e01 | Pascal's Triangle | E | Generate pascal triangle | n <= 30 | +| cmb_e02 | Fibonacci Number | E | Nth fibonacci | n <= 30 | +| cmb_m01 | Unique Binary Search Trees | M | Catalan number | n <= 19 | +| cmb_h01 | Count Palindromic Subsequences | H | Count distinct palindromes | n <= 1000 | + +#### Game Theory (`gt`) — 3 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| gt_e01 | Nim Game | E | Can win nim game | n <= 2^31-1 | +| gt_m01 | Stone Game | M | Optimal stone game strategy | n <= 500 | +| gt_h01 | Can I Win | H | Can first player win with maxTotal | maxTotal <= 200 | + +#### String Algorithms (`str`) — 8 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| str_e01 | Valid Palindrome | E | Check palindrome ignoring non-alphanumeric | n <= 2*10^5 | +| str_e02 | Valid Anagram | E | Check anagram | n <= 5*10^4 | +| str_e03 | First Unique Character | E | First non-repeating char | n <= 10^5 | +| str_m01 | Group Anagrams | M | Group strings by anagram | n <= 10^4, len <= 100 | +| str_m02 | Longest Palindromic Substring | M | Find longest palindrome | n <= 1000 | +| str_m03 | Multiply Strings | M | Multiply two number strings | n <= 200 | +| str_h01 | Shortest Palindrome | H | Min chars to make palindrome | n <= 5*10^4 | +| str_h02 | Minimum Window Subsequence | H | Min window containing subsequence | n <= 10^4 | + +#### Hashing (`hsh`) — 4 problems + +| Code | Name | Diff | Description | Constraints | +|---|---|---|---|---| +| hsh_e01 | Two Sum | E | Find two indices summing to target | n <= 10^4 | +| hsh_e02 | Ransom Note | E | Can construct from magazine | m,n <= 10^5 | +| hsh_m01 | Longest Consecutive Sequence | M | Longest consecutive sequence | n <= 10^5 | +| hsh_h01 | Max Points on a Line | H | Max collinear points | n <= 300 | + +--- + +## Implementation Approach + +### Phase 1: Problem Creator Infrastructure +- Use the `problem-creator` skill for each problem +- Each problem: DB record + test generator script + init.yml + data.zip +- Problems marked as "manually managed" + +### Phase 2: Batch Creation +- Create problems in topic batches (e.g., all Linked List problems first) +- Generate test data with Python scripts per topic +- Create AC submissions for problem author (admin) + +### Phase 3: Quality Assurance +- Use `problem-review` skill to verify each batch +- Check: solution correctness, test coverage, difficulty calibration +- Ensure only intended algorithms pass (strictness) + +### Phase 4: Cleanup +- Tag the 557 uncategorized existing problems +- Organize into proper ProblemGroup (Easy/mid/hard) +- Link related problems with editorial references + +--- + +## Success Criteria + +1. All 150 problems created and public on the site +2. Each problem has 10-20 test cases covering edge cases and max constraints +3. No previously-missing topic has 0 problems +4. Difficulty distribution improved (more problems in 11-75 range) +5. Automated test generation scripts are reusable for future problems diff --git a/plans/2026-03-20-leetcode-curriculum-implementation.md b/plans/2026-03-20-leetcode-curriculum-implementation.md new file mode 100644 index 0000000..c7a6e03 --- /dev/null +++ b/plans/2026-03-20-leetcode-curriculum-implementation.md @@ -0,0 +1,782 @@ +# LeetCode-Style 150-Problem Curriculum Track Implementation Plan + +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. + +**Goal:** Create 150 original competitive programming problems covering 15 topic areas with Easy/Medium/Hard difficulty progression, filling all critical topic gaps on LCOJ. + +**Architecture:** Problems created via Django ORM (DB records) + Python test generators (data.zip + init.yml). Each problem follows the `problem-creator` skill workflow (design → DB insert → test data → init.yml → AC submission → editorial). After each batch, use the `problem-review` skill to verify quality. Problems grouped in topic batches for parallel creation. + +**Skills to invoke:** +- `problem-creator` — for each problem creation (Steps 0-6 per the skill) +- `problem-review` — mandatory after each batch of problems is created (Step 7) + +**Tech Stack:** Python 3.11 (Django shell for DB), Python 3.12 (test generators on host), MariaDB, DMOJ judge + +**Design doc:** `docs/plans/2026-03-20-leetcode-curriculum-design.md` + +--- + +## Phase 0: Infrastructure Setup + +### Task 0.1: Create problem type entries for new topics + +**Files:** +- Run: `./scripts/manage.py shell` from `dmoj/` + +**Step 1: Create new ProblemType entries** + +```python +from judge.models import ProblemType + +new_types = [ + ('linked-list', 'Danh sách liên kết'), + ('two-pointers', 'Hai con trỏ'), + ('sliding-window', 'Cửa sổ trượt'), + ('binary-tree', 'Cây nhị phân'), + ('binary-search-tree', 'Cây tìm kiếm nhị phân'), + ('trie', 'Cây tiền tố'), + ('fenwick-tree', 'Cây Fenwick'), + ('monotonic-stack', 'Ngăn xếp đơn điệu'), + ('topological-sort', 'Sắp xếp tô pô'), +] + +for name, full_name in new_types: + pt, created = ProblemType.objects.get_or_create( + name=name, + defaults={'full_name': full_name} + ) + print(f'{"CREATED" if created else "EXISTS":7s}: {pt.name} ({pt.full_name})') +``` + +**Step 2: Run to verify** + +Run: `./scripts/manage.py shell < create_types.py` +Expected: All 9 types created + +**Step 3: Commit** + +```bash +git add -A +git commit -m "feat: add problem type entries for curriculum topics" +``` + +--- + +### Task 0.2: Create reusable problem creation script + +**Files:** +- Create: `scripts/create_lc_problem.py` + +**Step 1: Write the batch problem creator script** + +```python +#!/usr/bin/env python3 +""" +create_lc_problem.py — Create an LCOJ problem from a problem spec dict. + +Usage: + docker compose exec site python3 manage.py shell < scripts/create_lc_problem.py + +The script reads PROBLEM_SPEC from stdin or can be imported as a module. +""" +import sys +import json +from django.utils import timezone +from judge.models import Problem, ProblemGroup, ProblemType, Language, Profile, Submission, SubmissionSource, Solution + + +def create_problem(spec, author_username='admin'): + """Create a problem from a spec dict.""" + code = spec['code'] + name = spec['name'] + description = spec['description'] + time_limit = spec.get('time_limit', 2.0) + memory_limit = spec.get('memory_limit', 262144) + points = spec.get('points', 100.0) + group_name = spec['group'] # 'Easy', 'mid', 'hard' + type_names = spec['types'] # list of type names + source_code = spec.get('source_code', '') + + # Group mapping + group_map = {'Easy': 'Easy', 'mid': 'mid', 'hard': 'hard', 'super-hard': 'super-hard'} + group = ProblemGroup.objects.get(name=group_map.get(group_name, group_name)) + + # Create problem + p, created = Problem.objects.get_or_create( + code=code, + defaults={ + 'name': name, + 'description': description, + 'time_limit': time_limit, + 'memory_limit': memory_limit, + 'points': points, + 'partial': False, + 'is_public': True, + 'is_manually_managed': True, + 'date': timezone.now(), + 'group': group, + } + ) + + if not created: + print(f'EXISTS: {code}') + return p + + # Set types + types = [] + for tn in type_names: + pt, _ = ProblemType.objects.get_or_create( + name=tn, + defaults={'full_name': tn} + ) + types.append(pt) + p.types.set(types) + + # Set allowed languages + p.allowed_languages.set(Language.objects.filter(include_in_problem=True)) + + # Create AC submission if source provided + if source_code: + try: + profile = Profile.objects.get(user__username=author_username) + lang = Language.objects.get(key='PY3') + sub = Submission.objects.create( + user=profile, + problem=p, + language=lang, + status='D', + result='AC', + points=points, + case_points=points, + case_total=points, + time=0.5, + memory=32768, + judged_date=timezone.now(), + ) + SubmissionSource.objects.create(submission=sub, source=source_code) + print(f'AC sub #{sub.id} created') + except Exception as e: + print(f'WARNING: AC submission not created: {e}') + + print(f'CREATED: {code} — {name} ({group_name}, {points}p)') + return p +``` + +**Step 2: Verify script runs** + +Run: `echo "print('OK')" | ./scripts/manage.py shell` +Expected: No import errors + +**Step 3: Commit** + +```bash +git add scripts/create_lc_problem.py +git commit -m "feat: add reusable problem creation script" +``` + +--- + +## Phase 1: Create Linked List Problems (8 problems) + +### Task 1.1: Create ll_e01 — Reverse Linked List + +**Files:** +- Run: `./scripts/manage.py shell < create_ll_e01.py` +- Create: `dmoj/problems/lc_ll_e01/init.yml` +- Create: `dmoj/problems/lc_ll_e01/data.zip` + +**Step 1: Insert problem into DB** + +```python +# create_ll_e01.py +from django.utils import timezone +from judge.models import Problem, ProblemGroup, ProblemType, Language + +p = Problem.objects.create( + code='lc_ll_e01', + name='Đảo ngược Danh sách Liên kết', + description='''## Đề bài + +Cho một danh sách liên kết đơn gồm ~n~ nút. Hãy đảo ngược danh sách liên kết và trả về danh sách đã đảo ngược. + +## Input + +Dòng đầu tiên chứa số nguyên ~n~ (~1 \leq n \leq 5000~) — số lượng nút. +Dòng thứ hai chứa ~n~ số nguyên ~a_1, a_2, \\ldots, a_n~ (~|a_i| \leq 10^9~) — giá trị các nút. + +## Output + +In ra ~n~ số nguyên — giá trị các nút sau khi đảo ngược. + +## Ví dụ + +### Input 1 +``` +5 +1 2 3 4 5 +``` + +### Output 1 +``` +5 4 3 2 1 +``` + +**Giải thích:** Danh sách 1→2→3→4→5 được đảo ngược thành 5→4→3→2→1. + +### Input 2 +``` +1 +42 +``` + +### Output 2 +``` +42 +``` +''', + time_limit=1.0, + memory_limit=262144, + points=1.0, + partial=False, + is_public=True, + is_manually_managed=True, + date=timezone.now(), + group=ProblemGroup.objects.get(name='Easy'), +) +p.types.set([ProblemType.objects.get_or_create(name='linked-list', defaults={'full_name': 'Danh sách liên kết'})[0]]) +p.allowed_languages.set(Language.objects.filter(include_in_problem=True)) +print(f'Created {p.code}') +``` + +**Step 2: Create test data generator** + +```python +#!/usr/bin/env python3 +# gen_ll_e01.py — run from lcoj-docker/ +import os, random, zipfile + +CODE = 'lc_ll_e01' +PROBLEMS_DIR = 'dmoj/problems' + +def solve(inp: str) -> str: + lines = inp.strip().split('\n') + n = int(lines[0]) + if n == 0: + return '\n' + arr = list(map(int, lines[1].split())) + return ' '.join(map(str, arr[::-1])) + '\n' + +def make_cases(): + cases = [] + rng = random.Random(42) + + # Sample + cases.append(('5\n1 2 3 4 5\n', '5 4 3 2 1\n')) + cases.append(('1\n42\n', '42\n')) + + # Edge cases + cases.append(('2\n1 2\n', '2 1\n')) + cases.append(('3\n-1 0 1\n', '1 0 -1\n')) + cases.append(('10\n' + ' '.join(str(i) for i in range(1, 11)) + '\n', + ' '.join(str(i) for i in range(10, 0, -1)) + '\n')) + + # All same + cases.append(('5\n7 7 7 7 7\n', '7 7 7 7 7\n')) + + # Large stress + for _ in range(10): + n = rng.randint(4000, 5000) + arr = [rng.randint(-10**9, 10**9) for _ in range(n)] + inp = f'{n}\n' + ' '.join(map(str, arr)) + '\n' + cases.append((inp, solve(inp))) + + return cases + +def verify(cases): + for i, (inp, expected) in enumerate(cases, 1): + actual = solve(inp) + if actual.strip() != expected.strip(): + raise ValueError(f'Case {i} FAILED') + print(f'All {len(cases)} cases verified') + +def write(cases): + problem_dir = os.path.join(PROBLEMS_DIR, CODE) + os.makedirs(problem_dir, exist_ok=True) + pts = max(1, 100 // len(cases)) + + with zipfile.ZipFile(os.path.join(problem_dir, 'data.zip'), 'w', zipfile.ZIP_DEFLATED) as zf: + for i, (inp, out) in enumerate(cases, 1): + zf.writestr(f'{i}.in', inp) + zf.writestr(f'{i}.out', out) + + lines = ['archive: data.zip', 'checker: standard', 'test_cases:'] + for i in range(1, len(cases) + 1): + lines += [f'- in: {i}.in', f' out: {i}.out', f' points: {pts}'] + with open(os.path.join(problem_dir, 'init.yml'), 'w') as f: + f.write('\n'.join(lines) + '\n') + print(f'Written {len(cases)} cases to {problem_dir}/') + +if __name__ == '__main__': + cases = make_cases() + verify(cases) + write(cases) +``` + +**Step 3: Run generator** + +Run: `python3 gen_ll_e01.py` +Expected: "All 17 cases verified" + "Written 17 cases" + +**Step 4: Commit** + +```bash +git add dmoj/problems/lc_ll_e01/ scripts/gen_ll_e01.py +git commit -m "feat(lc_ll_e01): Reverse Linked List — Easy" +``` + +--- + +### Tasks 1.2–1.8: Remaining Linked List problems + +Repeat the same pattern for each. Key specs: + +| Task | Code | Name | Points | TL | Key edge cases | +|---|---|---|---|---|---| +| 1.2 | lc_ll_e02 | Merge Two Sorted Lists | 1.0 | 1.0s | empty lists, one empty, duplicates | +| 1.3 | lc_ll_e03 | Linked List Cycle | 1.0 | 1.0s | no cycle, cycle at head, cycle at tail | +| 1.4 | lc_ll_m01 | Remove Nth Node From End | 3.0 | 1.0s | remove head, remove tail, n=1 | +| 1.5 | lc_ll_m02 | Add Two Numbers | 3.0 | 1.0s | different lengths, carry at end | +| 1.6 | lc_ll_m03 | Flatten Multilevel Linked List | 3.0 | 1.0s | no children, deeply nested | +| 1.7 | lc_ll_h01 | Merge K Sorted Lists | 6.0 | 2.0s | k=1, all empty, unequal lengths | +| 1.8 | lc_ll_h02 | LRU Cache | 6.0 | 2.0s | capacity=1, full capacity, repeated keys | + +**Each task follows steps 1-4 from Task 1.1.** + +--- + +## Phase 2: Create Two Pointers Problems (8 problems) + +### Tasks 2.1–2.8 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 2.1 | lc_tp_e01 | Two Sum Sorted | E | 1.0 | 1.0s | +| 2.2 | lc_tp_e02 | Remove Duplicates from Sorted | E | 1.0 | 1.0s | +| 2.3 | lc_tp_e03 | Move Zeroes | E | 1.0 | 1.0s | +| 2.4 | lc_tp_m01 | 3Sum | M | 3.0 | 2.0s | +| 2.5 | lc_tp_m02 | Container With Most Water | M | 3.0 | 1.0s | +| 2.6 | lc_tp_m03 | Trapping Rain Water | M | 3.0 | 1.0s | +| 2.7 | lc_tp_h01 | 4Sum Count | H | 6.0 | 3.0s | +| 2.8 | lc_tp_h02 | Minimum Window Subsequence | H | 6.0 | 2.0s | + +--- + +## Phase 3: Create Sliding Window Problems (6 problems) + +### Tasks 3.1–3.6 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 3.1 | lc_sw_e01 | Max Average Subarray | E | 1.0 | 1.0s | +| 3.2 | lc_sw_e02 | Contains Duplicate II | E | 1.0 | 1.0s | +| 3.3 | lc_sw_m01 | Longest Substring Without Repeating | M | 3.0 | 1.0s | +| 3.4 | lc_sw_m02 | Minimum Size Subarray Sum | M | 3.0 | 1.0s | +| 3.5 | lc_sw_h01 | Minimum Window Substring | H | 6.0 | 2.0s | +| 3.6 | lc_sw_h02 | Sliding Window Maximum | H | 6.0 | 2.0s | + +--- + +## Phase 4: Create Binary Tree Problems (8 problems) + +### Tasks 4.1–4.8 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 4.1 | lc_bt_e01 | Maximum Depth of Binary Tree | E | 1.0 | 1.0s | +| 4.2 | lc_bt_e02 | Invert Binary Tree | E | 1.0 | 1.0s | +| 4.3 | lc_bt_e03 | Symmetric Tree | E | 1.0 | 1.0s | +| 4.4 | lc_bt_m01 | Binary Tree Level Order Traversal | M | 3.0 | 1.0s | +| 4.5 | lc_bt_m02 | Construct from Inorder and Preorder | M | 3.0 | 1.0s | +| 4.6 | lc_bt_m03 | Lowest Common Ancestor | M | 3.0 | 1.0s | +| 4.7 | lc_bt_h01 | Binary Tree Maximum Path Sum | H | 6.0 | 1.0s | +| 4.8 | lc_bt_h02 | Serialize and Deserialize Binary Tree | H | 6.0 | 2.0s | + +--- + +## Phase 5: Create BST Problems (4 problems) + +### Tasks 5.1–5.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 5.1 | lc_bst_e01 | Validate BST | E | 1.0 | 1.0s | +| 5.2 | lc_bst_e02 | Kth Smallest Element in BST | E | 1.0 | 1.0s | +| 5.3 | lc_bst_m01 | BST Iterator | M | 3.0 | 1.0s | +| 5.4 | lc_bst_h01 | Count of Range Sum | H | 6.0 | 2.0s | + +--- + +## Phase 6: Create Stack & Queue Problems (8 problems) + +### Tasks 6.1–6.8 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 6.1 | lc_stk_e01 | Valid Parentheses | E | 1.0 | 1.0s | +| 6.2 | lc_stk_e02 | Implement Queue using Stacks | E | 1.0 | 1.0s | +| 6.3 | lc_stk_e03 | Min Stack | E | 1.0 | 1.0s | +| 6.4 | lc_stk_m01 | Evaluate Reverse Polish Notation | M | 3.0 | 1.0s | +| 6.5 | lc_stk_m02 | Decode String | M | 3.0 | 1.0s | +| 6.6 | lc_stk_m03 | Asteroid Collision | M | 3.0 | 1.0s | +| 6.7 | lc_stk_h01 | Basic Calculator | H | 6.0 | 2.0s | +| 6.8 | lc_stk_h02 | Longest Valid Parentheses | H | 6.0 | 1.0s | + +--- + +## Phase 7: Create Heap/Priority Queue Problems (4 problems) + +### Tasks 7.1–7.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 7.1 | lc_hp_e01 | Kth Largest Element | E | 1.0 | 1.0s | +| 7.2 | lc_hp_e02 | Last Stone Weight | E | 1.0 | 1.0s | +| 7.3 | lc_hp_m01 | Task Scheduler | M | 3.0 | 1.0s | +| 7.4 | lc_hp_h01 | Find Median from Data Stream | H | 6.0 | 2.0s | + +--- + +## Phase 8: Create DFS/BFS Problems (8 problems) + +### Tasks 8.1–8.8 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 8.1 | lc_gb_e01 | Number of Islands | E | 1.0 | 1.0s | +| 8.2 | lc_gb_e02 | Flood Fill | E | 1.0 | 1.0s | +| 8.3 | lc_gb_e03 | Max Area of Island | E | 1.0 | 1.0s | +| 8.4 | lc_gb_m01 | Rotting Oranges | M | 3.0 | 1.0s | +| 8.5 | lc_gb_m02 | Word Search | M | 3.0 | 2.0s | +| 8.6 | lc_gb_m03 | Pacific Atlantic Water Flow | M | 3.0 | 1.0s | +| 8.7 | lc_gb_h01 | Word Ladder | H | 6.0 | 3.0s | +| 8.8 | lc_gb_h02 | Sudoku Solver | H | 6.0 | 5.0s | + +--- + +## Phase 9: Create Dynamic Programming Problems (10 problems) + +### Tasks 9.1–9.10 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 9.1 | lc_dp_e01 | Climbing Stairs | E | 1.0 | 1.0s | +| 9.2 | lc_dp_e02 | House Robber | E | 1.0 | 1.0s | +| 9.3 | lc_dp_e03 | Maximum Subarray | E | 1.0 | 1.0s | +| 9.4 | lc_dp_m01 | Coin Change | M | 3.0 | 1.0s | +| 9.5 | lc_dp_m02 | Longest Increasing Subsequence | M | 3.0 | 1.0s | +| 9.6 | lc_dp_m03 | Unique Paths | M | 3.0 | 1.0s | +| 9.7 | lc_dp_m04 | Word Break | M | 3.0 | 1.0s | +| 9.8 | lc_dp_h01 | Longest Common Subsequence | H | 6.0 | 2.0s | +| 9.9 | lc_dp_h02 | Edit Distance | H | 6.0 | 2.0s | +| 9.10 | lc_dp_h03 | Burst Balloons | H | 6.0 | 3.0s | + +--- + +## Phase 10: Create Greedy Problems (6 problems) + +### Tasks 10.1–10.6 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 10.1 | lc_gr_e01 | Assign Cookies | E | 1.0 | 1.0s | +| 10.2 | lc_gr_e02 | Lemonade Change | E | 1.0 | 1.0s | +| 10.3 | lc_gr_m01 | Jump Game | M | 3.0 | 1.0s | +| 10.4 | lc_gr_m02 | Partition Labels | M | 3.0 | 1.0s | +| 10.5 | lc_gr_h01 | Candy | H | 6.0 | 1.0s | +| 10.6 | lc_gr_h02 | IPO | H | 6.0 | 2.0s | + +--- + +## Phase 11: Create Backtracking Problems (4 problems) + +### Tasks 11.1–11.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 11.1 | lc_btbk_e01 | Subsets | E | 1.0 | 1.0s | +| 11.2 | lc_btbk_m01 | Permutations | M | 3.0 | 1.0s | +| 11.3 | lc_btbk_m02 | Combination Sum | M | 3.0 | 2.0s | +| 11.4 | lc_btbk_h01 | N-Queens | H | 6.0 | 3.0s | + +--- + +## Phase 12: Create Divide & Conquer Problems (4 problems) + +### Tasks 12.1–12.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 12.1 | lc_dc_e01 | Merge Sort | E | 1.0 | 2.0s | +| 12.2 | lc_dc_e02 | Majority Element | E | 1.0 | 1.0s | +| 12.3 | lc_dc_m01 | Sort Colors | M | 3.0 | 1.0s | +| 12.4 | lc_dc_h01 | Count of Range Sum | H | 6.0 | 2.0s | + +--- + +## Phase 13: Create Bit Manipulation Problems (4 problems) + +### Tasks 13.1–13.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 13.1 | lc_bm_e01 | Single Number | E | 1.0 | 1.0s | +| 13.2 | lc_bm_e02 | Counting Bits | E | 1.0 | 1.0s | +| 13.3 | lc_bm_m01 | Subsets II | M | 3.0 | 1.0s | +| 13.4 | lc_bm_h01 | Max XOR of Two Numbers | H | 6.0 | 2.0s | + +--- + +## Phase 14: Create Sorting Problems (4 problems) + +### Tasks 14.1–14.4 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 14.1 | lc_srt_e01 | Sort Array by Parity | E | 1.0 | 1.0s | +| 14.2 | lc_srt_e02 | Squares of Sorted Array | E | 1.0 | 1.0s | +| 14.3 | lc_srt_m01 | Merge Intervals | M | 3.0 | 1.0s | +| 14.4 | lc_srt_m02 | Insert Interval | M | 3.0 | 1.0s | + +--- + +## Phase 15: Create Advanced DS Problems (25 problems) + +### Tasks 15.1–15.4: Trie + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.1 | lc_trie_e01 | Implement Trie | E | 1.0 | 1.0s | +| 15.2 | lc_trie_e02 | Longest Common Prefix | E | 1.0 | 1.0s | +| 15.3 | lc_trie_m01 | Word Search II | M | 3.0 | 3.0s | +| 15.4 | lc_trie_h01 | Design Search Autocomplete | H | 6.0 | 2.0s | + +### Tasks 15.5–15.10: Segment Tree + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.5 | lc_seg_e01 | Range Sum Query Mutable | E | 1.0 | 1.0s | +| 15.6 | lc_seg_e02 | Range Minimum Query | E | 1.0 | 1.0s | +| 15.7 | lc_seg_m01 | Count of Range Sum (SegTree) | M | 3.0 | 2.0s | +| 15.8 | lc_seg_m02 | My Calendar I | M | 3.0 | 1.0s | +| 15.9 | lc_seg_h01 | Falling Squares | H | 6.0 | 2.0s | +| 15.10 | lc_seg_h02 | Rectangle Area II | H | 6.0 | 2.0s | + +### Tasks 15.11–15.14: Fenwick Tree (BIT) + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.11 | lc_bit_e01 | Range Sum Query (BIT) | E | 1.0 | 1.0s | +| 15.12 | lc_bit_e02 | Count Inversions | E | 1.0 | 2.0s | +| 15.13 | lc_bit_m01 | Count of Smaller Numbers | M | 3.0 | 2.0s | +| 15.14 | lc_bit_h01 | 2D Range Sum Query | H | 6.0 | 2.0s | + +### Tasks 15.15–15.18: DSU/Union-Find + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.15 | lc_dsu_e01 | Connected Components Count | E | 1.0 | 1.0s | +| 15.16 | lc_dsu_e02 | Redundant Connection | E | 1.0 | 1.0s | +| 15.17 | lc_dsu_m01 | Accounts Merge | M | 3.0 | 2.0s | +| 15.18 | lc_dsu_h01 | Largest Component Size by Factor | H | 6.0 | 2.0s | + +### Tasks 15.19–15.22: Monotonic Stack + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.19 | lc_ms_e01 | Next Greater Element | E | 1.0 | 1.0s | +| 15.20 | lc_ms_e02 | Daily Temperatures | E | 1.0 | 1.0s | +| 15.21 | lc_ms_m01 | Largest Rectangle in Histogram | M | 3.0 | 1.0s | +| 15.22 | lc_ms_h01 | Maximal Rectangle | H | 6.0 | 2.0s | + +### Tasks 15.23–15.25: Topological Sort + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 15.23 | lc_topo_e01 | Course Schedule | E | 1.0 | 1.0s | +| 15.24 | lc_topo_m01 | Course Schedule II | M | 3.0 | 1.0s | +| 15.25 | lc_topo_h01 | Alien Dictionary | H | 6.0 | 2.0s | + +--- + +## Phase 16: Create Math & String Problems (25 problems) + +### Tasks 16.1–16.4: Number Theory + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.1 | lc_nt_e01 | Count Primes | E | 1.0 | 2.0s | +| 16.2 | lc_nt_e02 | Happy Number | E | 1.0 | 1.0s | +| 16.3 | lc_nt_m01 | Super Pow | M | 3.0 | 1.0s | +| 16.4 | lc_nt_h01 | Ugly Number III | H | 6.0 | 1.0s | + +### Tasks 16.5–16.8: Combinatorics + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.5 | lc_cmb_e01 | Pascal's Triangle | E | 1.0 | 1.0s | +| 16.6 | lc_cmb_e02 | Fibonacci Number | E | 1.0 | 1.0s | +| 16.7 | lc_cmb_m01 | Unique Binary Search Trees | M | 3.0 | 1.0s | +| 16.8 | lc_cmb_h01 | Count Palindromic Subsequences | H | 6.0 | 2.0s | + +### Tasks 16.9–16.11: Game Theory + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.9 | lc_gt_e01 | Nim Game | E | 1.0 | 1.0s | +| 16.10 | lc_gt_m01 | Stone Game | M | 3.0 | 1.0s | +| 16.11 | lc_gt_h01 | Can I Win | H | 6.0 | 2.0s | + +### Tasks 16.12–16.19: String Algorithms + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.12 | lc_str_e01 | Valid Palindrome | E | 1.0 | 1.0s | +| 16.13 | lc_str_e02 | Valid Anagram | E | 1.0 | 1.0s | +| 16.14 | lc_str_e03 | First Unique Character | E | 1.0 | 1.0s | +| 16.15 | lc_str_m01 | Group Anagrams | M | 3.0 | 1.0s | +| 16.16 | lc_str_m02 | Longest Palindromic Substring | M | 3.0 | 1.0s | +| 16.17 | lc_str_m03 | Multiply Strings | M | 3.0 | 1.0s | +| 16.18 | lc_str_h01 | Shortest Palindrome | H | 6.0 | 2.0s | +| 16.19 | lc_str_h02 | Minimum Window Subsequence | H | 6.0 | 2.0s | + +### Tasks 16.20–16.23: Hashing + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.20 | lc_hsh_e01 | Two Sum | E | 1.0 | 1.0s | +| 16.21 | lc_hsh_e02 | Ransom Note | E | 1.0 | 1.0s | +| 16.22 | lc_hsh_m01 | Longest Consecutive Sequence | M | 3.0 | 1.0s | +| 16.23 | lc_hsh_h01 | Max Points on a Line | H | 6.0 | 2.0s | + +### Tasks 16.24–16.25: Arrays & Strings + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 16.24 | lc_arr_m01 | Product of Array Except Self | M | 3.0 | 1.0s | +| 16.25 | lc_arr_h01 | First Missing Positive | H | 6.0 | 1.0s | + +--- + +## Phase 17: Create Binary Search Problems (6 problems) + +### Tasks 17.1–17.6 + +| Task | Code | Name | Diff | Points | TL | +|---|---|---|---|---|---| +| 17.1 | lc_bs_e01 | Binary Search | E | 1.0 | 1.0s | +| 17.2 | lc_bs_e02 | Search Insert Position | E | 1.0 | 1.0s | +| 17.3 | lc_bs_m01 | Search in Rotated Sorted Array | M | 3.0 | 1.0s | +| 17.4 | lc_bs_m02 | Find Peak Element | M | 3.0 | 1.0s | +| 17.5 | lc_bs_h01 | Median of Two Sorted Arrays | H | 6.0 | 1.0s | +| 17.6 | lc_bs_h02 | Split Array Largest Sum | H | 6.0 | 2.0s | + +--- + +## Per-Problem Workflow (use problem-creator skill) + +For **each problem** in the phases below, follow the `problem-creator` skill workflow: + +1. **Design** — identify intended algorithm, wrong approaches to reject, constraints, time limit +2. **DB insert** — create Problem record via Django ORM (code, name, description, group, types) +3. **Test data** — write generator script with reference solution, verify outputs, pack into data.zip +4. **init.yml** — write test case configuration +5. **AC submission** — create first AC for problem author +6. **Editorial** — create Solution model entry +7. **problem-review** — invoke `problem-review` skill to verify quality before moving to next problem + +After each **batch of problems** (e.g., all 8 Linked List problems), run `problem-review` on any +problems that weren't individually reviewed, and fix any FAIL/WARN findings. + +--- + +## Phase 18: Quality Assurance — Run problem-review on all problems + +### Task 18.1: Batch review all created problems + +**Invoke:** Use the `problem-review` skill for each problem that hasn't been individually reviewed. + +**Files:** +- Review: all `dmoj/problems/lc_*/init.yml` +- Review: all test generators + +**Step 1: Verify all problems exist in DB** + +```python +from judge.models import Problem +lc_problems = Problem.objects.filter(code__startswith='lc_') +print(f'Total LC curriculum problems: {lc_problems.count()}') +for p in lc_problems.order_by('code'): + types = ', '.join(t.name for t in p.types.all()) + g = p.group.name if p.group else 'N/A' + print(f'{p.code:20s} | {p.name:45s} | {p.points:>5.1f}p | {g:5s} | [{types}]') +``` + +Run: `./scripts/manage.py shell < verify_problems.py` +Expected: 150 problems listed + +**Step 2: Verify all have test data on disk** + +```bash +# Count problems with init.yml +find dmoj/problems/lc_* -name init.yml | wc -l +# Expected: 150 + +# Count problems with data.zip +find dmoj/problems/lc_* -name data.zip | wc -l +# Expected: 150 +``` + +**Step 3: Verify all have AC submissions** + +```python +from judge.models import Problem, Submission +for p in Problem.objects.filter(code__startswith='lc_'): + ac = Submission.objects.filter(problem=p, result='AC').count() + if ac == 0: + print(f'MISSING AC: {p.code}') +print('Done checking AC submissions') +``` + +**Step 4: Commit** + +```bash +git add -A +git commit -m "feat: complete 150-problem LeetCode curriculum track" +``` + +--- + +## Summary + +| Phase | Topics | Problems | Tasks | +|---|---|---|---| +| 0 | Infrastructure | 0 | 2 | +| 1 | Linked List | 8 | 8 | +| 2 | Two Pointers | 8 | 8 | +| 3 | Sliding Window | 6 | 6 | +| 4 | Binary Tree | 8 | 8 | +| 5 | BST | 4 | 4 | +| 6 | Stack & Queue | 8 | 8 | +| 7 | Heap/PQ | 4 | 4 | +| 8 | DFS/BFS | 8 | 8 | +| 9 | Dynamic Programming | 10 | 10 | +| 10 | Greedy | 6 | 6 | +| 11 | Backtracking | 4 | 4 | +| 12 | Divide & Conquer | 4 | 4 | +| 13 | Bit Manipulation | 4 | 4 | +| 14 | Sorting | 4 | 4 | +| 15 | Advanced DS | 25 | 25 | +| 16 | Math & Strings | 25 | 25 | +| 17 | Binary Search | 6 | 6 | +| 18 | QA & Review | 0 | 1 | +| **Total** | **15 topics** | **150** | **151** | From 53c1f735549afcbae981b1a0a2b7869d712bceb9 Mon Sep 17 00:00:00 2001 From: Hieu Date: Tue, 21 Apr 2026 21:35:35 +0700 Subject: [PATCH 02/11] docs: design agent contributor guides --- ...6-04-21-agents-contributor-guide-design.md | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 superpowers/specs/2026-04-21-agents-contributor-guide-design.md diff --git a/superpowers/specs/2026-04-21-agents-contributor-guide-design.md b/superpowers/specs/2026-04-21-agents-contributor-guide-design.md new file mode 100644 index 0000000..43b5d30 --- /dev/null +++ b/superpowers/specs/2026-04-21-agents-contributor-guide-design.md @@ -0,0 +1,146 @@ +# AGENTS Contributor Guide Design + +Date: 2026-04-21 + +## Goal + +Create AI-agent-focused contributor guides for the Luyencode workspace so agents can work in the correct environment, run the right Docker and Django commands, and avoid production-impacting mistakes. + +## Scope + +The implementation will create or refine these files: + +- `/home/hieu/workspaces/luyencode/AGENTS.md` +- `/home/hieu/workspaces/luyencode/lcoj-docker/AGENTS.md` +- `/home/hieu/workspaces/luyencode/dev-lcoj-docker/AGENTS.md` + +The root guide is a workspace router. The environment guides are self-contained operational references for agents that start inside either repository. + +## Environment Model + +The workspace has two LCOJ Docker environments: + +- `lcoj-docker`: production environment for `https://luyencode.net`. +- `dev-lcoj-docker`: development environment for `https://dev.luyencode.net`. + +Both environments run the Django-based LCOJ platform through Docker Compose. Public traffic reaches each environment through Cloudflare Tunnel. Inside each compose stack, nginx serves HTTP and proxies to the Django/uWSGI site and WebSocket event server. + +Production must be treated as sensitive. Agents should use `dev-lcoj-docker` for experimentation and validation by default, and should not restart production services, deploy, migrate, or touch production data unless the user explicitly requests that action. + +## Chosen Approach + +Use a root router plus mirrored environment guides. + +The root `AGENTS.md` will identify the workspace, describe the production and development directory split, explain shared architecture, and state safety defaults. It will point agents to the nearest environment guide for concrete commands. + +Each environment `AGENTS.md` will keep the same section structure so agents can compare them quickly, but will include environment-specific domains, container names, bridged ports, and nginx defaults. + +This balances discoverability with drift control: agents get enough context from the root, but each environment remains usable when opened directly. + +## Guide Structure + +Each guide should be concise and operational, with these sections: + +- Identity and scope. +- Environment map. +- Architecture summary. +- Key directories. +- Command rules. +- Change workflow. +- Validation and debugging. +- Style and code conventions. +- Safety rules. + +The guides should avoid human onboarding narrative. They should prioritize instructions that prevent common agent mistakes. + +## Architecture Content + +The guides will document the shared LCOJ stack: + +- `nginx`: reverse proxy and static/media serving. +- `site`: Django app running under uWSGI. +- `celery`: background task worker. +- `db`: MariaDB database. +- `redis`: cache and Celery broker. +- `wsevent`: WebSocket event server. +- `bridged`: connector between the Django site and judge servers. + +They will state that Django application code lives in `dmoj/repo/`, a git submodule pointing at `lcoj-site`, and that Docker commands should be run from `dmoj/`. + +## Environment-Specific Facts + +The production guide will document: + +- Domain: `https://luyencode.net`. +- Directory: `/home/hieu/workspaces/luyencode/lcoj-docker`. +- Container prefix: `lcoj_`. +- Bridged host ports: `9998` and `9999`. +- Compose nginx default: `${NGINX_PORT:-8071}:80`. + +The development guide will document: + +- Domain: `https://dev.luyencode.net`. +- Directory: `/home/hieu/workspaces/luyencode/dev-lcoj-docker`. +- Container prefix: `lcoj_dev_`. +- Bridged host ports: `19998` and `19999`. +- Compose nginx default: `${NGINX_PORT:-80}:80`. + +## Command Contract + +All Docker Compose commands run from the relevant `dmoj/` directory. + +Common commands to document: + +- `docker compose ps` +- `docker compose logs -f ` +- `docker compose restart site celery` +- `docker compose restart nginx` +- `docker compose up -d` +- `docker compose up -d --build base site celery bridged wsevent` +- `./scripts/manage.py ` +- `./scripts/migrate` +- `./scripts/copy_static` +- `./scripts/enter_site` + +Change workflow rules: + +- Python/Django code changes usually require `docker compose restart site celery`. +- Static, SCSS, or JavaScript changes require `./scripts/copy_static`, then nginx restart if served assets need refresh. +- Model changes require `./scripts/manage.py makemigrations`, review of generated migrations, then `./scripts/migrate`. +- Dependency or Dockerfile changes require rebuilding relevant images. + +## Validation + +The guides will instruct agents to prefer targeted validation: + +- Run specific Django tests with `./scripts/manage.py test `. +- Check service state with `docker compose ps`. +- Inspect logs with `docker compose logs -f site`, `celery`, `nginx`, `bridged`, or `wsevent`. +- Validate static changes with `./scripts/copy_static`. + +When tests or Docker commands are not run, agents should state that clearly in their final response. + +## Safety Rules + +The guides will include these safety rules: + +- Never commit secrets or environment files. +- Do not hardcode secrets or deployment-specific values in Django code. +- Preserve git submodule boundaries. +- Do not edit generated database data, media, or problem data unless explicitly requested. +- Do not run production-impacting actions in `lcoj-docker` without explicit user approval. +- Keep changes focused; avoid unrelated refactors. + +## Out Of Scope + +The guides will not include a full installation tutorial, Cloudflare Tunnel setup instructions, judge server provisioning, or human contributor policy. Existing README files remain the place for installation walkthroughs. + +## Review Criteria + +The implementation is complete when: + +- The root guide clearly routes agents between production and development. +- Both environment guides are self-contained and aligned in structure. +- Production and development differences are explicit. +- Commands match the Docker Compose files in each environment. +- The guides are concise enough for agents to read quickly. From febc6237cf40914af5d58699580301a3346dc25f Mon Sep 17 00:00:00 2001 From: Hieu Date: Tue, 21 Apr 2026 22:15:14 +0700 Subject: [PATCH 03/11] docs: add LCOJ problem skill suite design --- ...6-04-21-lcoj-problem-skill-suite-design.md | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 superpowers/specs/2026-04-21-lcoj-problem-skill-suite-design.md diff --git a/superpowers/specs/2026-04-21-lcoj-problem-skill-suite-design.md b/superpowers/specs/2026-04-21-lcoj-problem-skill-suite-design.md new file mode 100644 index 0000000..109d93c --- /dev/null +++ b/superpowers/specs/2026-04-21-lcoj-problem-skill-suite-design.md @@ -0,0 +1,210 @@ +# LCOJ Problem Skill Suite Design + +Date: 2026-04-21 + +## Goal + +Create a workspace-level Codex skill suite that guides agents through creating complete, reviewable LCOJ problem artifact packages from a short seed or source/example problem. + +The suite must support continuous work until a package is ready for manual import review, while keeping all generated artifacts outside live LCOJ problem storage and avoiding automatic database mutations. + +## Scope + +The implementation will create skills under: + +- `/home/hieu/workspaces/luyencode/.agents/skills/` + +Generated problem packages will be written under: + +- `/home/hieu/workspaces/luyencode/problem-packages//` + +The first version focuses on one problem at a time. Batch creation is out of scope for the initial skill suite. + +## Core Decisions + +- Artifact-first workflow: generated problem packages are reviewable files, not live database changes. +- Vietnamese is the default language for problem statements and editorials. +- A problem workflow can start from either a short seed or a source/example problem. +- The orchestrator must interact with the user like the existing `brainstorming` skill: ask one focused question at a time and use approval gates. +- The suite must support standard IO, custom checker, custom grader, interactive, signature, and generator-backed problem modes. +- Generated packages must include runnable validation automation. +- Generated packages must include a non-executing import artifact for later manual LCOJ creation. + +## Architecture + +Use one orchestrator skill plus focused specialist skills. + +The top-level skill is `lcoj-create-problem`. Users invoke this skill directly. It owns the conversation, asks intake questions, gets design approval, and coordinates the specialist skills in the correct order. + +Specialist skills: + +- `lcoj-problem-design`: converts a seed or source/example into an approved problem design. +- `lcoj-statement-writing`: writes the Vietnamese LCOJ Markdown statement with compatible LaTeX. +- `lcoj-test-data`: creates generators, test data, `data.zip`, `init.yml`, and optional checker/grader/interactor files. +- `lcoj-solution-editorial`: creates an accepted reference solution and Vietnamese editorial. +- `lcoj-package-review`: validates the package and reports `PASS`, `WARN`, or `FAIL`. + +The orchestrator is the only skill that should define the whole order. Specialist skills should stay narrow and should not duplicate the full workflow. + +## Workflow + +The workflow accepts either: + +- a short seed containing topic, difficulty, and rough idea +- a source/example problem used for style and inspiration, while producing original LCOJ content + +The orchestrator first classifies the judging mode: + +- standard IO +- custom checker +- custom grader +- interactive +- signature +- generator-backed + +If the mode is unclear, the orchestrator asks one focused question before proceeding. + +The gated workflow is: + +1. Intake and context: problem seed/example, audience, topic, difficulty, score, constraints, and judging mode. +2. Problem design: intended solution, rejected weaker approaches, edge cases, subtasks if any, and limits. +3. User approval of the problem design. +4. Statement generation: Vietnamese problem statement with input/output, constraints, samples, explanation, and LaTeX. +5. Test data generation: deterministic generator/reference logic, samples, edge cases, stress/random cases, `data.zip`, and `init.yml`. +6. Accepted solution: at least one reference solution, normally C++ unless the problem mode requires another language. +7. Editorial generation: Vietnamese explanation, insight/proof, complexity, pitfalls, and implementation notes. +8. Package review: run validation automation, inspect consistency, and report findings. +9. Final handoff: package path, validation result, and next manual import steps. + +The workflow may loop after statement, tests, solution, editorial, or review if the artifacts do not match the approved design. + +## Package Format + +Each problem package should use this base structure: + +```text +/home/hieu/workspaces/luyencode/problem-packages// + README.md + problem.yml + statement.md + editorial.md + solutions/ + ac.cpp + tests/ + gen.py + cases/ + data.zip + init.yml + validators/ + validate.py + import/ + create_problem.py +``` + +Custom-mode files are added only when required: + +```text + checkers/ + checker.cpp | checker.py + graders/ + grader.cpp | grader.py + header.h + interactors/ + interactor.cpp | interactor.py +``` + +`problem.yml` is the canonical metadata manifest. It must include: + +- problem code +- title +- language +- source or inspiration note +- topic +- tags/types +- group/category +- score +- time limit +- memory limit +- judging mode +- checker/grader/interactor settings when applicable +- constraints +- sample tests +- package notes for later LCOJ import + +`import/create_problem.py` is a reviewable Django shell/import artifact. The skill suite must not execute it automatically. + +`validators/validate.py` is the package validation entry point. It should parse the manifest, check required files, inspect `init.yml`, verify `data.zip` contents, and run the accepted solution against generated cases when practical. + +## Validation And Review + +`lcoj-package-review` is the release gate for the artifact package. + +Review checks: + +- `problem.yml` has all required metadata for later LCOJ import. +- `statement.md` is Vietnamese and includes clear input/output, constraints, samples, and LCOJ-compatible LaTeX. +- `editorial.md` explains the intended algorithm, insight/proof, complexity, pitfalls, and implementation. +- `solutions/ac.cpp` matches the intended algorithm and passes all generated cases. +- `tests/init.yml` is valid DMOJ/LCOJ configuration and references files inside `tests/cases/data.zip`. +- Test data covers samples, edge cases, random/stress cases, and anti-wrong-solution cases. +- Custom checker/grader/interactor artifacts are present and match the selected judging mode. +- The package does not contain secrets, live database mutations, or production actions. + +Review outcomes: + +- `PASS`: package is ready for manual import review. +- `WARN`: package has accepted caveats; the user must explicitly accept the warning or request fixes. +- `FAIL`: package is blocked and must be fixed before handoff. + +The orchestrator must not claim package completion without a fresh validation run and review result. + +## Skill Authoring Requirements + +The implementation must follow the local `writing-skills` guidance: + +- Write skills as reusable process documentation, not one-off narratives. +- Keep frontmatter descriptions focused on trigger conditions. +- Avoid summarizing the full workflow in specialist skill descriptions. +- Use concise skill bodies with links to supporting files only where needed. +- Define pressure scenarios before writing the skills. +- Verify that the skills prevent common agent failures. + +Required pressure scenarios: + +- Standard IO problem from a short seed. +- Custom checker problem from a short seed. +- Problem from a source/example prompt. +- Ambiguous problem mode where the orchestrator must ask a clarifying question. +- Validation failure where the orchestrator must loop instead of handing off. + +## Guardrails + +- Ask one focused question at a time during intake and design. +- Do not write problem artifacts until the problem design is approved. +- Do not mutate LCOJ database records. +- Do not write generated packages into `lcoj-docker/dmoj/problems/`. +- Do not restart services or run production-impacting commands. +- Prefer deterministic generators with fixed seeds. +- Keep problem content original when using an example for inspiration. +- Stop and ask if the intended algorithm, constraints, or judging mode are ambiguous enough to affect test quality. +- Make generated import scripts non-executing by default and clearly marked for manual review. + +## Out Of Scope + +- Batch problem creation. +- Automatic import into the LCOJ database. +- Automatic upload to live `dmoj/problems`. +- Production deployment or service restarts. +- Full site UI changes. + +## Success Criteria + +The implementation is complete when: + +- The six workspace skills exist under `.agents/skills/`. +- The orchestrator guides a user through one-problem artifact creation with approval gates. +- The suite supports all required judging modes at the design and package-structure level. +- A generated package follows the approved directory structure. +- Validation automation can be run from the package. +- The review skill reports `PASS`, `WARN`, or `FAIL` with concrete findings. +- Pressure scenarios show the suite avoids premature artifact writing, live DB mutation, skipped validation, and skipped user approval. From cf1697c3736c897bf6d2f377199e4562457ab457 Mon Sep 17 00:00:00 2001 From: Hieu Date: Tue, 21 Apr 2026 22:26:02 +0700 Subject: [PATCH 04/11] docs: add LCOJ problem skill suite plan --- .../2026-04-21-lcoj-problem-skill-suite.md | 956 ++++++++++++++++++ 1 file changed, 956 insertions(+) create mode 100644 superpowers/plans/2026-04-21-lcoj-problem-skill-suite.md diff --git a/superpowers/plans/2026-04-21-lcoj-problem-skill-suite.md b/superpowers/plans/2026-04-21-lcoj-problem-skill-suite.md new file mode 100644 index 0000000..16f6ba9 --- /dev/null +++ b/superpowers/plans/2026-04-21-lcoj-problem-skill-suite.md @@ -0,0 +1,956 @@ +# LCOJ Problem Skill Suite Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Create six workspace-level Codex skills that guide one LCOJ problem from seed/example to a validated artifact-first package. + +**Architecture:** The implementation creates one orchestrator skill and five specialist skills under `/home/hieu/workspaces/luyencode/.agents/skills/`. The skills generate future problem packages under `/home/hieu/workspaces/luyencode/problem-packages//`, avoid live LCOJ database/problem-data mutation, and use pressure scenarios as process tests. + +**Tech Stack:** Markdown skill documents, Codex skill frontmatter, shell verification with `rg` and `python3`. + +--- + +## Important Repository Note + +`/home/hieu/workspaces/luyencode` is not a git repository, so the skill files under `.agents/skills/` cannot be committed directly. Do not move the skills into `lcoj-docker` to make commits easier; the approved spec requires workspace-level skills. + +For each implementation task, verify the exact files on disk. At the end, commit only this plan document and any docs-submodule changes if they are edited during implementation. + +## File Structure + +Create these files: + +- `.agents/skills/lcoj-create-problem/SKILL.md`: orchestrator skill and hard gates. +- `.agents/skills/lcoj-create-problem/pressure-scenarios.md`: process tests and pass/fail criteria. +- `.agents/skills/lcoj-problem-design/SKILL.md`: problem design specialist. +- `.agents/skills/lcoj-statement-writing/SKILL.md`: Vietnamese statement specialist. +- `.agents/skills/lcoj-test-data/SKILL.md`: data, `init.yml`, and custom-mode specialist. +- `.agents/skills/lcoj-solution-editorial/SKILL.md`: AC solution and editorial specialist. +- `.agents/skills/lcoj-package-review/SKILL.md`: validation and review gate specialist. + +Do not create generated problem packages while implementing this plan. + +## Task 1: Pressure Scenarios + +**Files:** +- Create: `.agents/skills/lcoj-create-problem/pressure-scenarios.md` + +- [ ] **Step 1: Create the pressure scenario directory** + +Run: + +```bash +mkdir -p .agents/skills/lcoj-create-problem +``` + +Expected: command exits with status `0`. + +- [ ] **Step 2: Write the pressure scenarios** + +Create `.agents/skills/lcoj-create-problem/pressure-scenarios.md` with this content: + +```markdown +# LCOJ Problem Skill Suite Pressure Scenarios + +Use these scenarios to verify that the skill suite changes agent behavior. A passing agent should follow approval gates, avoid live mutations, and produce or request reviewable package artifacts only. + +## Scenario 1: Standard IO Seed + +Prompt: + +> Use `lcoj-create-problem`. Create an easy array problem about finding the longest strictly increasing contiguous segment. Vietnamese statement and editorial. Artifact-first package. + +Expected behavior: + +- Asks missing intake questions one at a time if code, score, or constraints are unclear. +- Presents a design before creating files. +- Waits for design approval. +- Uses package root `/home/hieu/workspaces/luyencode/problem-packages//`. +- Plans standard IO artifacts: `problem.yml`, `statement.md`, `editorial.md`, `solutions/ac.cpp`, `tests/gen.py`, `tests/cases/data.zip`, `tests/init.yml`, `validators/validate.py`, `import/create_problem.py`. +- Does not write to `lcoj-docker/dmoj/problems/`. +- Does not run a Django import script. + +## Scenario 2: Custom Checker Seed + +Prompt: + +> Use `lcoj-create-problem`. Create a graph construction problem where many valid answers exist. Need custom checker support. + +Expected behavior: + +- Classifies the judging mode as custom checker. +- Designs output validity requirements before data generation. +- Includes `checkers/checker.cpp` or `checkers/checker.py` in the package plan. +- Requires validation to compile or run the checker when practical. +- Does not treat sample output as the only valid output. + +## Scenario 3: Source Example + +Prompt: + +> Use `lcoj-create-problem`. Learn from this problem idea: shortest path with one discounted edge. Create an original LCOJ version. + +Expected behavior: + +- States that the new problem must be original and the source is inspiration only. +- Asks what difficulty, topic, and constraints are desired if missing. +- Produces a distinct story, variables, constraints, and samples. +- Keeps the intended algorithm explicit. + +## Scenario 4: Ambiguous Mode + +Prompt: + +> Use `lcoj-create-problem`. Create a problem where contestants output any valid team assignment. + +Expected behavior: + +- Does not assume standard IO comparison. +- Asks whether to use a custom checker or constrain output to a canonical answer. +- Waits for the answer before designing test data. + +## Scenario 5: Validation Failure + +Prompt: + +> Use `lcoj-package-review` on a package where `tests/init.yml` references `7.out` but `data.zip` only contains `1.out` through `6.out`. + +Expected behavior: + +- Reports `FAIL`. +- Names the missing file and the referencing config. +- Does not claim the package is complete. +- Directs the workflow back to test-data repair. +``` + +- [ ] **Step 3: Verify pressure scenarios exist** + +Run: + +```bash +rg -n "Scenario 1|Scenario 2|Scenario 3|Scenario 4|Scenario 5" .agents/skills/lcoj-create-problem/pressure-scenarios.md +``` + +Expected: five scenario headings are printed. + +## Task 2: Problem Design Skill + +**Files:** +- Create: `.agents/skills/lcoj-problem-design/SKILL.md` + +- [ ] **Step 1: Create the skill directory** + +Run: + +```bash +mkdir -p .agents/skills/lcoj-problem-design +``` + +Expected: command exits with status `0`. + +- [ ] **Step 2: Write `lcoj-problem-design`** + +Create `.agents/skills/lcoj-problem-design/SKILL.md` with this content: + +```markdown +--- +name: lcoj-problem-design +description: Use when an LCOJ problem seed, topic, difficulty, or source/example needs to become an approved original problem design +--- + +# LCOJ Problem Design + +## Purpose + +Turn a rough seed or source/example into a precise LCOJ problem design before any artifacts are written. + +## Inputs + +Accept either: + +- a short seed: topic, difficulty, rough idea +- a source/example problem used for inspiration + +If required details are missing, ask one focused question at a time. Do not ask a bundle of questions. + +## Required Design Decisions + +Classify and document: + +- problem code proposal +- Vietnamese title proposal +- source or inspiration note +- topic and tags/types +- group/category and score +- judging mode: standard IO, custom checker, custom grader, interactive, signature, or generator-backed +- time limit and memory limit +- constraints and variable definitions +- intended algorithm +- weaker approaches that should fail or time out +- edge cases and anti-wrong-solution cases +- sample tests and explanation +- required custom artifacts, if any + +## Approval Gate + +Present the design and ask for approval before artifact creation. Use this wording: + +> Does this problem design look right? I will not create the package artifacts until you approve it. + +If the user requests changes, revise the design and ask again. + +## Originality Rule + +When using a source/example, learn the concept and style only. Create original story, constraints, samples, wording, and test strategy. Do not copy statements, examples, or editorial text. + +## Mode Guidance + +- Standard IO: use when each input has one canonical output. +- Custom checker: use when many valid outputs exist. +- Custom grader: use when contestants implement functions or use special judging logic. +- Interactive: use when contestant and judge exchange messages during execution. +- Signature: use for IOI-style function-only submissions. +- Generator-backed: use when tests are generated by DMOJ from generator arguments instead of stored static files. + +If the mode affects correctness, stop and ask before continuing. + +## Output Template + +Use this structure for the proposed design: + +```markdown +**Problem Code:** `` +**Title:** `` +**Mode:** `` +**Topic/Tags:** `` +**Difficulty/Score:** `, ` +**Limits:** `