Introduction
In competitive programming, the "correctness" of a solution is a multi-dimensional constraint. While a program must produce the right output for a given input, it must also do so within strict temporal and spatial bounds. Current Large Language Models (LLMs) have shown remarkable progress in generating logically sound code, yet they frequently stumble when faced with large-scale inputs, leading to "Time Limit Exceeded" (TLE) or "Memory Limit Exceeded" (MLE) errors. This is because most LLM-based code generation frameworks treat efficiency as an afterthought.
SwiftSolve is a novel multi-agent framework that elevates algorithmic complexity to a first-class citizen. By coupling LLM-based reasoning with empirical profiling and automated complexity analysis, SwiftSolve identifies performance bottlenecks and iteratively refines solutions to meet the rigorous demands of competitive programming.
The SwiftSolve Architecture
SwiftSolve employs a modular, message-passing architecture designed to mimic the workflow of a human competitive programmer. The system consists of four specialized agents coordinated by a central Controller.
- Planner (Claude 4 Opus): The process begins with the Planner, which analyzes the problem statement to propose a high-level algorithmic strategy. It identifies critical input bounds and suggests appropriate data structures (e.g., segment trees or priority queues).
- Static Pruner: Before passing the plan to the Coder, a deterministic Static Pruner evaluates the proposed algorithm's theoretical complexity against the problem's constraints. If a plan is obviously doomed to fail—such as an $O(N^2)$ approach for $N=10^5$—it is rejected immediately, saving computational resources and LLM tokens.
- Coder (GPT-4.1): Once a plan is approved, the Coder translates the strategy into optimized ISO C++17 code.
- Profiler: The generated code is not just tested for correctness but is executed against a schedule of increasing input sizes. This empirical data provides a real-world performance profile, capturing wall-clock time and peak memory usage.
- Complexity Analyst: The Analyst serves as the system's "brain." It performs a least-squares regression in log-log space to estimate the code's growth rate. By comparing this empirical slope to the problem's limits, it can pinpoint exactly where a solution fails to scale and dispatch targeted instructions for repair.
Empirical Complexity Analysis
A key innovation of SwiftSolve is its use of empirical feedback. Rather than relying on the LLM to "guess" why a solution is slow, the Complexity Analyst provides hard data. By plotting runtime against input size on a log-log scale, the system can distinguish between constant-factor overheads and true asymptotic inefficiencies. This allows the framework to decide whether a minor "patch" (e.g., optimizing a loop) or a major "overhaul" (e.g., changing the underlying algorithm) is required.
Experimental Evaluation
The framework was tested on 26 tasks from BigO(Bench) and Codeforces Div. 2, totaling 78 runs across different seeds. The evaluation environment utilized a POSIX sandbox with a 2-second time limit, mirroring standard competitive programming contest conditions.
Results and Discussion
SwiftSolve demonstrated significant improvements over baseline models. While a single-agent approach achieved a success rate of approximately 52.6%, SwiftSolve’s iterative loop pushed the final success rate to 80.77%.
The system achieved a PASS@1 rate of 61.54%, which climbed to 80.77% within three iterations (SOLVED@≤3). Notably, the overhead of the multi-agent coordination was minimal; the average time per run increased by less than one second compared to a single-agent attempt. This efficiency suggests that SwiftSolve is viable for use in time-sensitive competitive environments.
Conclusion and Future Directions
SwiftSolve proves that integrating empirical profiling into the LLM development cycle is essential for solving resource-constrained tasks. By treating efficiency as a core constraint, the framework bridges the gap between "code that works" and "code that scales."
Future work will focus on improving the robustness of the log-log fitting process to handle noise at small input sizes and expanding the system's scope to support multiple programming languages and adversarial input generation.
Summary updated