# Competitive Programming — Evolutionary Optimization Agent You are an autonomous optimization agent. Your goal is to iteratively evolve a C++ solution to achieve the highest possible score on an algorithmic problem. **Your workspace is `/workspace/frontier_cs_{NUM}/` (this directory).** All problem files, solutions, logs, and results must stay within this directory. Do not access files outside of it. ## Problem Read `statement.txt` for the full problem description and scoring formula. ## Evaluation The evaluation runs via a go-judge HTTP service inside the container: ```bash # Submit (replace PID with the problem ID from config.yaml) SID=$(curl -s -X POST http://Competitive-Programming:8081/submit \ -F "code=@solution.cpp" -F "pid=PID" -F "lang=cpp" \ | python3 -c "import sys,json; print(json.load(sys.stdin)['sid'])") # Poll (repeat every 2-3s until status is "done" or "error") curl -s http://Competitive-Programming:8081/result/$SID ``` Response format: ```json {"status": "done", "score": 74.84, "scoreUnbounded": 74.84, ...} ``` Check `config.yaml` for time limit, memory limit, and number of test cases. ## Your Workflow ### 1. Initialize - Start from the example solution in `examples/` as the baseline - Copy it to `solution.cpp` - Evaluate it to get the baseline score - Record it in the log ### 2. Evolve (repeat for many generations) For each generation: 1. **Analyze** the current best solution — understand its algorithm, identify bottlenecks and weaknesses 2. **Mutate** — apply ONE meaningful improvement per generation 3. **Write** the mutated solution to `solution.cpp` 4. **Evaluate** — submit to judge and get the score 5. **Select**: - If score improved: keep the new solution as the current best - If score decreased or errored: revert to the previous best 6. **Log** the result (see below) ### 3. Exploration vs Exploitation - Don't just make small tweaks. Periodically try bold algorithmic changes - If stuck at a plateau for 3+ generations, try a fundamentally different approach - Consider maintaining 2-3 alternative solution strategies and switching between them - Learn from failed attempts — record what didn't work and why ## Logging For each generation, append to `logs/evolution.log`: ``` Gen | Score: | Best: | Status: | Change: ``` Also save each generation's solution: ``` logs/gen_.cpp ``` Save the current best solution at `best/best.cpp` at all times. Also save the best score and key metrics to `best/scores.txt`. ## Important Rules 1. **Never read testdata/** — solve the problem algorithmically, do not hardcode answers 2. **Always keep a backup** of the current best before mutating 3. **The solution must compile and run correctly** — syntax errors waste a generation 4. **Stay within time/memory limits** — check `config.yaml` for limits 5. **Each solution must be a single .cpp file** — no external dependencies beyond standard library 6. **Aim for at least 50 generations** — keep going as long as you're making progress 7. **Be systematic** — don't repeat failed approaches, learn from each generation ## Getting Started Begin now. Read `statement.txt`, initialize from the example solution, evaluate it, then start evolving.