Manuscript Offprint
arXiv:2611.09791Assessing the Impact of Retrieval-Augmented Generation on Algorithmic Problem-Solving
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Competitive programming problems pose distinctive challenges for Large Language Models, as they demand not only proficient code generation but also advanced algorithmic reasoning. This study presents a Retrieval-Augmented Generation approach specifically designed to enhance the capacity of Large Language Models to address such problems. Our approach integrates an embedding-based retrieval mechanism and a similarity search algorithm to identify analogous problems within a knowledge database, employing a dynamically adjusted threshold to mitigate retrieval noise. We conducted an evaluation using the CodeContests dataset, focusing on the test split problems that exhibit similarity to instances from the training split. The experimental framework considered three conditions: (i) problems provided solely with their original descriptions, (ii) problems supplemented with randomly selected examples from the training split, and (iii) problems augmented with similar examples retrieved through the proposed method. In addition, we incorporated a Min-K membership inference analysis to examine whether the generated code solutions were influenced by potential memorization of training data within the evaluated Large Language Models. This complementary perspective enables a deeper understanding of model behavior by distinguishing genuine generalization through retrieval from implicit recall of pretraining samples. Performance was assessed using both pass rates and the CodeForces Elo rating of the problems. The results provide empirical evi-dence that similarity-based retrieval substantially enhances Large Language Models performance in competitive programming scenarios, offering an scalable framework for improving code generation in algorithmic problem-solving contexts.
Keywords: Retrieval-Augmented Generation, Large Language Models, Code Generation, Programming Problems, Information Retrieval
1. Introduction
Large Language Models (LLMs) have demonstrated proficiency in solving generic problems across various professional domains [1, 2, 3]. Although some evaluation benchmarks indicate high performance — such as on HumanEval, where GPT-4o [4] and Claude-3.5-Sonnet [5] achieved precision scores of 90% and 92%, respectively [6] —, other benchmarks show that LLMs exhibit limitations on competitive programming tasks [7, 8, 9, 10]. For instance, in the analysis by Zheng et al. [8], Claude-3.5-Sonnet achieved a 0% precision rate on medium and hard problems and only 14.1% on easy ones. In the same benchmark, even the best-performing LLMs, such as Gemini-2.5-Pro [11] and DeepSeek-R1 [12], could not solve a single hard problem.
These errors typically arise due to a lack of specific contextual knowledge and a limited understanding of underlying data structures, leading to hallucinations — outputs that are syntactically invalid or logically inconsistent [13]. Under a deeper epistemological analysis, it becomes evident that Large Language Models (LLMs) operate on opinion-based trajectories—that is, on the formulation of statements not necessarily grounded in verifiable evidence, but rather derived from inferences or interpretations constructed within a limited context of knowledge. Hallucination, in this sense, may be understood as the generation of a perception or belief that, while internally coherent, does not correspond to empirical reality. In LLMs, this phenomenon arises because the model “believes” it is producing a consistent and contextually appropriate response, even though such a response lacks factual support.To mitigate this, Retrieval-Augmented Generation (RAG) [14, 15] has been proposed as a mechanism to ground the model’s outputs in relevant external knowledge by, with an Information Retrieval (IR) algorithm, retrieving contextually similar information from a structured corpus [14, 15]. This work investigates how RAG can be used to enhance the problem-solving capabilities of LLMs.
The proposition for applying RAG in this context is based on two key observations. First, studies indicate that problems within competitive programming repositories often share underlying algorithmic patterns and solution structures [16, 17]. Second, the practice of providing relevant examples in the prompt (few-shot prompting) is an established technique for improving LLM performance on complex tasks [18, 19]. Based on this, the hypothesis is that a RAG system that retrieves previously solved problems with analogous characteristics to a target problem can provide the model with relevant context and reduce hallucination.
To achieve this, we developed an Information Retrieval (IR) pipeline that employs embedding similarity with a dynamic threshold [20]. We evaluated this system on the CodeContests dataset [21], which is divided into a training set of 13,328 problems and a test set of 165 problems. In addition to the problem title and statement, each sample includes metadatdynamig programming, bitwise operations). The training split served as the knowledge base from which we retrieved similar examples to augment the LLM prompts for solving the problems in the test set. The correctness of the generated solutions was then evaluated using the CodeForces [22] judge system, allowing us to measure the impact of the retrieved context on the model's performance.
The evaluation involves three distinct prompting strategies: (i) a zero-shot baseline using only the original description, (ii) a random retrieval baseline retrieving unrelated problems from the knowledge base, and (iii) the proposed similarity-based RAG approach retrieving contextually aligned examples. Our analyses demonstrate that the similarity-based retrieval consistently outperforms both baselines, validating the hypothesis that retrieving analogous problems improves LLM reasoning on complex programming tasks. Furthermore, the Min-K membership inference results reveal that many generated code lines correspond to known training patterns, underscoring the importance of disentangling memorization effects from genuine reasoning improvements. Together, these findings provide a dual epistemic safeguard: RAG anchors outputs in external knowledge, while membership inference verifies their originality and data provenance. See Figure 1 for a graphical overview of the system architecture and execution pipeline.
The main contributions of this paper are summarized as follows:
- We design a RAG framework tailored to competitive programming tasks, integrating an embedding-based similarity search with an adaptive thresholding mechanism to retrieve contextually relevant problems while minimizing retrieval noise.

Figure 1: System Architecture and Execution Pipeline
-
We construct a comprehensive experimental setup using the CodeContests dataset, evaluating six prominent LLMs across three prompting strategies, zero-shot, random retrieval, and RAG-based enhancement, to systematically quantify the effect of similarity-driven retrieval on code generation performance.
-
We introduce a complementary Min-K Membership Inference analysis to assess model exposure and memorization biases, providing a novel perspective on the interplay between retrieval-based augmentation and pretraining data recall.
-
We present an integrated evaluation pipeline combining RAG effectiveness and membership inference insights, offering a dual perspective on both performance improvement and epistemic grounding in competitive programming contexts.
-
Finally, we discuss the implications of these findings for the design of future reasoning-oriented LLMs and outline directions for extending this work to upcoming state-of-the-art models such as Gemini 3 and GPT-5.
2.1. Evaluation Strategies
A main challenge in this domain is developing evaluation metrics that go beyond simple pass/fail rates and accurately reflect a model's problem-solving skill [24]. While simply annotating the number of correctly solved problems is informative, it fails to distinguish between solving a trivial problem and solving one that challenges even the best human competitors [8].
To address this gap, recent benchmarks [24, 26, 27] have adopted the Elo rating system [28], a method widely recognized for assessing the relative skill levels of players in competitive games — and is also used in CodeForces platform. In the context of competitive programming platforms, the Elo system provides a unified scale to quantify both problem difficulty and competitor skill. The difficulty rating assigned to a problem is calibrated against the entire community of human participants; a contestant with an Elo rating of has a 50% probability of solving this given problem [27].
The Elo rating of a contestant, in turn, provides a clear measure of their standing within the competitive community [8]. For example, a rating of 1600 (an “Expert” on CodeForces) places a user in the top 11% of active participants, while a rating of 2400 (“Grandmaster”) signifies performance in the top 1%. An elite rating of 2700 indicates a skill level superior to approximately 99.9% of competitors. By framing LLM performance in this way, we can move from asking “how many” problems a model solved to “how skilled” the model is.
Following this evaluation method, our study treats each LLM as a virtual contestant and calculates its equivalent Elo rating. We specifically employ Bayesian Maximum-A-Posteriori (MAP) Elo rating [29], a method also utilized in [8], to estimate the most probable skill level of a model given its performance.
The estimation process begins with the standard Elo probability function, , which calculates the likelihood of a model with rating correctly solving a problem with difficulty :
These individual probabilities are used to construct the unnormalized log-posterior function, . This function combines the log-likelihood of the observed outcomes () across all problems with a regularizing Gaussian prior on the model's rating (with mean and variance ):
Finally, the MAP estimate, , is the rating that maximizes this log-posterior function:
Since our benchmark utilizes the CodeContests dataset [21], which contains most of its problems from CodeForces, we annotated each problem's official Elo difficulty rating. This provides a standardized metric that allows for a comparison of our results against other benchmarks (assuming they also use Elo), even when the test sets are composed of different problems.
2.2. Performance Enhancement Approaches
Prior research has explored enhancing LLM performance through two main strategies: granting models access to external knowledge sources or fine-tuning them on specific datasets. For instance, augmenting models with tools like terminal and internet access has enabled systems such as o3 and o4-mini-high to achieve Elo ratings of 2706 and 2719 respectively [26]. Another strategy involves fine-tuning LLMs on competitive programming datasets to train them on problem-solving patterns, a notable example being Google's AlphaCode [21]. Since these benchmarks also use Elo for evaluation, we used it as a common metric to assess the effectiveness of our technique in relation to these prior work.
2.3. Problem Datasets
Several datasets have been proposed to benchmark the ability of LLMs to solve competitive programming problems [23, 24, 25, 8, 21]. Table 1 summarizes these datasets, detailing how many problems each contains and the time period from which they were sourced.
Table 1: Summary of competitive programming datasets used for LLM evaluation
| Dataset | # Problems | Problems' Year(s) |
|---|---|---|
| USACO [23] | 307 | 2011-2024 |
| CodeElo [24] | 408 | 2024 |
| LiveCodeBench [25] | 442 | 2023-2024 |
| LiveCodeBench Pro [8] | ~584 | Updated Lively |
| CodeContests [21] | 13,493 | 2021 |
For this study, we selected the CodeContests dataset due to its extensive scale. Our central hypothesis is that retrieving similar, previously solved problems can enhance an LLM's performance. The large repository of over 13,000 problems in CodeContests provides a sufficiently dense knowledge base, which is essential for a retrieval-based approach to effectively find analogous examples.
Other benchmarks, while valuable, were less suited for our research objectives. The USACO dataset, for instance, sources its problems from a platform other than CodeForces, making it incompatible with the Elo rating system used for our evaluation. Datasets like CodeElo, LiveCodeBench, and LiveCodeBench Pro, despite their advantages of containing more recent problems and potentially having less data contamination, offer a very limited number of problems.
3. Methodology
To evaluate RAG's impact on our work, we used six well-known LLMs and a set of programming questions, each paired with a previously tested and accepted solution. These entries serve as the knowledge base for the RAG. All datasets and code used in the methodology are included in our open-source repository¹.
¹https://anonymous.4open.science/r/ArtigoSBBD-C51C
3.1. Model Selection
The models utilized were chosen based on their use in prior research: DeepSeek-R1 [8, 6, 16], Gemini 2.0 Flash [8, 25, 16], Claude 3.7 Sonnet [8, 16], Qwen models [8, 25, 6, 24], GPT-4-omni [8, 25, 9, 6, 24, 16], and GPT-3.5 Turbo [23, 25]. This section provides information about the models used:
Table 2: Overview of models with organization, context window and cut-off date.
| Full Model Name | Org. | Context Tokens | Cut-off Date |
|---|---|---|---|
| DeepSeek-R1 [30] | DeepSeek | 131K | Not specified |
| Gemini 2.0 Flash [31] | 1 million | June 2024 | |
| Claude 3.7 Sonnet [32] | Anthropic | 200K | October 2024 |
| Qwen2.5-Coder-32B [33] | Alibaba | 128K | End of 2023 |
| GPT-4-omni [4] | OpenAI | 128K | September 2023 |
| GPT-3.5 Turbo [34] | OpenAI | 16K | September 2021 |
Another decisive factor in the model selection was the diversity in training focus and knowledge cutoff date: we included a code-specialized model (Qwen2.5-Coder-32B), a model known for advanced reasoning capabilities (DeepSeek-R1), a less powerful model (GPT-3.5 Turbo), as well as general-purpose models with broader training data.
3.2. Information Retrieval Algorithm
The IR algorithm retrieves similar solved problems from the database. First, each problem description in the database is transformed into a high-dimensional vector embedding using the ‘all-MiniLM-L6-v2’² model. These embeddings capture the semantic essence of the problems [35]. The collection of embeddings is then indexed using FAISS (Facebook AI Similarity Search) [36], employing an ‘IndexFlatL2’ structure that computes Euclidean distances. Because the vectors are already normalized, we can compute the similarity directly from the Euclidean distance (on a 0-to-1 scale).
A distinctive aspect of our IR system is its adaptive threshold mechanism, introduced by [20]. Instead of a fixed cutoff, the threshold for deeming a retrieved problem “similar enough” is dynamically adjusted based on the
²https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 highest similarity score. The initial threshold used for the similarity is 70%, but if the highest similarity is strong (above 85%), the threshold becomes more stringent; if weaker (less than 75%), it relaxes, but never below the 70% minimum. Similar adaptive strategies are used in RAG to reduce noise [37], and we apply it with the same intent. As an additional measure to mitigate noise, the system is configured to return a maximum of the three most similar problems.
3.3. Dataset Overview
We utilized the CodeContests dataset [21] for this study, designating its training set as the knowledge base for our RAG system and its test set for evaluation. The dataset, sourced primarily from CodeForces problems, is structured as a JSON file where each entry contains the problem's title, its full description, input/output examples, the official CodeForces rating (when applicable), relevant thematic tags, and verified code solutions. These problems do not require a specific programming language for implementation, allowing for flexibility in the solution approaches. This section describes how we leveraged this dataset to construct our RAG pipeline and analyzes the distribution of difficulties and categories of the problems used.
Of the 165 problems in the CodeContests test set, 81 had at least one similar problem found in the knowledge base by our Information Retrieval algorithm. The evaluation was therefore performed on this subset, as the remaining problems had no retrieved counterparts and would not receive any additional information from the RAG system. Furthermore, none of the problems in this evaluation set were part of the RAG's knowledge base, ensuring a fair assessment of its generalization capabilities [14, 15, 38, 39]. Problems can be classified into one or more categories (e.g., dynamic programming, sorting, binary search), and the distribution of these thematic tags across both datasets is shown in Figure 2.
To better understand the difficulty distribution of the problems, we performed a classification based on their CodeForces Elo ratings. While the Elo system provides a continuous scale, we grouped the problems into three discrete categories for a better analysis: Easy, Medium, and Hard. Problems with an Elo rating between 0 and 1000 were classified as Easy, those in the range (1000, 2000] as Medium, and any problem rated above 2000 as Hard. It is worth noting that while every problem in the test set is from CodeForces, the training set (our knowledge base) also contains problems from other sources, so not all of them had the CodeForces Elo information.
available. Table 3 shows the distribution of these difficulty levels across the knowledge base and our filtered test dataset.

Figure 2: Categories of the Problems from the Knowledge and Test Datasets
Table 3: Distribution of Problem Difficulty in the Knowledge and Test Datasets
| Difficulty | Knowledge Dataset | Test Dataset | ||
|---|---|---|---|---|
| Count | Proportion (%) | Count | Proportion (%) | |
| Easy | 901 | 11.70 | 18 | 22.22 |
| Medium | 3759 | 48.81 | 31 | 38.27 |
| Hard | 3041 | 39.49 | 32 | 39.51 |
3.4. Min-K-Based Membership Inference Analysis
To complement the RAG evaluation and assess whether any code solutions in the test set were potentially present in the training corpora of the evaluated LLMs, we implemented a Min-K Membership Inference approach [40]. This method estimates the likelihood that a given code sample was part of a model's pretraining data, thereby quantifying exposure bias and memorization within large language models.
The core intuition behind this algorithm is that language models assign systematically higher confidence to samples encountered during training compared to unseen ones. Training data typically yield higher average token probabilities (or equivalently, lower perplexities). Rather than relying on mean likelihoods, the Min-K approach focuses on the lowest of token log-probabilities, representing the model's most uncertain predictions, because these regions provide stronger discriminatory signals between memorised and novel samples [40]. By analyzing the extremal uncertainty pattern rather than overall fluency, the method enhances detection precision and reduces false positives.
Algorithm 1 summarizes the membership inference detection process for code snippets. Given a tokenized code sequence , the model computes the conditional log-probabilities for each token. These values are sorted in ascending order to extract the Min-K% subset, from which a stability-based membership score is computed as:
If this score exceeds a threshold , the sample is classified as Non-member (likely unseen by the model); otherwise, it is labeled as Member, suggesting partial or full memorization.
Algorithm 1: Membership Inference Detection for Code Snippets
Input: Token sequence ; threshold ; parameter
Output: Membership classification (Member / Non-member)
for to do Compute log-probability via model ; Sort log-probabilities in ascending order ; Extract the lowest values: ; Compute membership score: ; if then return Non-member (code likely unseen); else return Member (code likely in training data);
To transform continuous Min-K scores into binary membership classifications, we apply a percentile-based thresholding strategy [41]. The threshold is defined as the average of the 75th percentile of known member scores and the 25th percentile of non-member scores. This empirically driven approach efficiently separates the two distributions while maintaining robustness to outliers and noise. Compared to fixed or heuristic thresholds, percentile-based selection adapts better to model variance and dataset composition, leading to more stable and interpretable decision boundaries. The overall inference workflow comprises three main phases:
-
Problem Evaluation Phase: For each competitive programming problem, the corresponding verified solution code is tokenized and evaluated by the target LLM. In this phase, we considered the best solution for each problem (a total of 81 problems) across the six selected LLMs. Owing to the high computational and API costs associated with probability estimation, only one representative solution per problem was analyzed. The best solution was determined according to the shortest and earliest correct submission among all generated outputs. This choice ensures consistency across models while maintaining a fair and cost-efficient evaluation process.
-
Detection Phase: The Min-K algorithm computes per-token log-probabilities, sorts them, and derives for each solution. This score is then compared against to classify each code sample as Member or Non-member.
-
Analysis Phase: Membership inference outcomes are aggregated to estimate model exposure levels across problem categories and difficulty levels, complementing the RAG-based performance evaluation.
By integrating this step, our methodology not only measures performance improvement via retrieval augmentation but also accounts for potential memorization biases in LLMs. This enriches the interpretability of results, distinguishing genuine reasoning gains from possible recall of pretraining data in competitive programming contexts.
3.5. Experiments
To perform the experiment, we designed an experiment involving the six selected LLMs and the 81 problems from the filtered test set. Each problem was presented to every LLM under three distinct conditions. The first scenario, a zero-shot baseline, provided the LLM with only the original problem description. The second, a random-retrieval baseline, augmented the prompt with randomly selected problems from the knowledge base to analyze the effect of simply adding more context. The third scenario, our proposed RAG approach, enhanced the prompt with the most similar problems identified by our IR algorithm. For the RAG scenario, each test problem was matched against all problems in the knowledge base using the IR system.
The semantic similarity was computed exclusively using the textual content of the problems' descriptions. This was a choice to simulate a scenario where, upon encountering a new problem, one only has access to its textual statement, not pre-existing metadata like a solution or tags. After generation, all outputs were submitted to the CodeForces judge system, which verifies correctness by running the solution against a comprehensive set of hidden test cases and returns whether the solution was accepted or rejected (rejection occurs if any test case fails).
The structure of the prompts was kept consistent in all experiments to ensure a fair comparison. For the zero-shot baseline, the prompt contained the problem's title, its full textual description, and any provided input/output examples, followed by an instruction to generate a solution. For the few-shot conditions (random and RAG-based), the prompt began with the target problem's information, followed by a clear demarcation for the upcoming examples. Each retrieved example included its original title, description, tags, similarity score, and verified solution. In the prompts that had examples, an additional instruction was included to direct the model to take advantage of the provided examples when formulating its solution.
The primary objective was to quantify the performance improvement attributable to the quality of the examples. We measured performance using two metrics: the overall pass rate (pass@1), calculated as the percentage of problems correctly solved on the first attempt, and the Elo rating of each model — which is translated from the Elo data of the solved and unsolved problems. The pass rate provides a direct measure of success, while analyzing the Elo ratings offers a nuanced understanding of the model's capability to solve problems.
In addition to these benchmarks, we performed a complementary Min-K Membership Inference analysis on the generated code solutions. This step estimated the likelihood that a given solution resembled or originated from the model's pretraining data. We calculated a probability confidence score for each line of code within a problem's best solution, indicating its likelihood of being a member (i.e., part of the model's pretraining data) or a non-member, as determined by Algorithm 1.
4. Results and Analysis
This section presents the results of our experiments, analyzing the performance of six LLMs on 81 problems across three prompting conditions: zero-shot, random-retrieval, and our RAG approach. We evaluated performance using two primary metrics: the pass@1 rate and the Elo rating. Other factors like the categories and difficulty of the problems are also considered.
On average, our RAG approach achieved a 20.37% success rate, outperforming both the zero-shot (17.9%) and random-retrieval (17.28%) approaches. These results demonstrate a crucial trade-off. On the one hand, the retrieval of any additional problem inevitably introduces a degree of noise to the prompt [42]. On the other, selecting the right examples can provide useful content and insights to the model [43]. The performance decrease seen with random retrieval (-0.62%) suggests that when examples are irrelevant, the negative impact of this noise reduces the model's reasoning process. However, the 2.47 percentage point gain from our RAG method demonstrates that when the examples are contextually relevant, the value of the provided insights outweighs this negative impact, leading to performance gains.
The individual pass@1 rates are detailed in Figure 3. Weaker models like GPT-3.5 Turbo and Qwen2.5-Coder-32B struggled across all conditions.

Figure 3: Correctness analysis
Although providing extra context led to some performance gains, the inherent limitations of these models were a more significant factor than the content of the examples. On the other side, DeepSeek-R1 had the best performance. Using our proposed framework, its pass rate improved from 61.7% to 64.2% (a relative improvement of 4.05%). In this case, the random-retrieval scenario had the worst performance, with only 59.3% correctness. Opposed to that, other models like GPT-4o and Qwen-2.5-Coder-32B showed an increase in accuracy in the random-retrieval scenario.
See Table 4 for Elo and difficulty analysis. These ratings were calculated using a MAP Elo estimation, and we collected its prior distribution's mean () and variance () from CodeForces list of all users. The percentile column represents the model's standing within the entire community. On average, our RAG method resulted in an Elo rating of 1014, an increase of 89 points over the zero-shot baseline (925) and 87 points over the random-retrieval baseline (927).
To understand whether our RAG approach favors certain problem types, we analyzed the performance of the top-performing model, DeepSeek-R1, in
https://codeforces.com/api/user.ratedList?activeOnly=false
Table 4: Performance Based on Difficulty and Community Percentile Rating
| Model | Easy | Medium | Hard | Rating | Pct. |
|---|---|---|---|---|---|
| Zero-shot | |||||
| DeepSeek R1 | 100.0% | 80.6% | 21.9% | 2080 | 2.9% |
| Gemini 2.0 | 61.1% | 12.9% | 0.0% | 983 | 54.3% |
| Claude 3.7 Sonnet | 50.0% | 16.1% | 0.0% | 955 | 57.0% |
| GPT 4o | 27.8% | 3.2% | 0.0% | 706 | 79.8% |
| GPT-3.5 | 5.6% | 0.0% | 0.0% | 412 | 90.3% |
| Qwen2.5-Coder | 0.0% | 3.2% | 0.0% | 412 | 90.3% |
| Random-retrieval | |||||
| DeepSeek R1 | 100.0% | 77.4% | 18.8% | 2020 | 3.3% |
| Gemini 2.0 | 61.1% | 12.9% | 0.0% | 983 | 54.3% |
| Claude 3.7 Sonnet | 38.9% | 9.7% | 0.0% | 839 | 68.7% |
| GPT 4o | 33.3% | 3.2% | 0.0% | 742 | 77.5% |
| Qwen2.5-Coder | 11.1% | 3.2% | 0.0% | 568 | 87.3% |
| GPT-3.5 | 5.6% | 0.0% | 0.0% | 412 | 90.3% |
| RAG approach | |||||
| DeepSeek R1 | 100.0% | 83.9% | 25.0% | 2140 | 2.2% |
| Gemini 2.0 | 72.2% | 16.1% | 0.0% | 1069 | 46.5% |
| Claude 3.7 Sonnet | 50.0% | 22.6% | 0.0% | 1012 | 51.7% |
| GPT 4o | 22.2% | 9.7% | 0.0% | 742 | 77.5% |
| Qwen2.5-Coder | 16.7% | 3.2% | 0.0% | 621 | 83.9% |
| GPT-3.5 | 5.6% | 3.2% | 0.0% | 502 | 88.0% |
different problem categories. Table 5 shows the Elo rating (and the corresponding community rank) that the model achieved when evaluated on problems with a specific tag.
The biggest difference was observed in problems tagged with ‘number theory’, where the model’s Elo increased from 1604 in both the zero-shot and random-retrieval scenarios to 2191 with RAG. This substantial leap is likely due to the logic-heavy nature of this category [8]. Number theory problems often hinge on discovering a mathematical insight that transforms a brute-force approach, such as an O(n) calculation, into an elegant O(1) formula. In these cases, a relevant example that reveals this insight can guide the model directly to the optimal solution. However, in categories such as ‘data
Table 5: DeepSeek-R1 Elo Rating and Rank by Problem Category
| Category | Zero-shot | Random-retrieval | RAG |
|---|---|---|---|
| math | 2177 (1.7%) | 2042 (3.2%) | 2177 (1.7%) |
| dp | 2066 (3.0%) | 1852 (5.4%) | 2066 (3.0%) |
| implementation | 1832 (5.7%) | 1832 (5.7%) | 1832 (5.7%) |
| greedy | 1963 (3.9%) | 1806 (6.1%) | 2052 (3.1%) |
| brute force | 1967 (3.8%) | 1967 (3.8%) | 1967 (3.8%) |
| data structures | 2063 (3.0%) | 1957 (3.9%) | 1851 (5.5%) |
| sortings | 1862 (5.3%) | 1862 (5.3%) | 1862 (5.3%) |
| constructive algorithms | 1894 (5.0%) | 1778 (6.6%) | 1778 (6.6%) |
| combinatorics | 2041 (3.2%) | 2041 (3.2%) | 1858 (5.4%) |
| dfs and similar | 1915 (4.6%) | 1915 (4.6%) | 2075 (3.0%) |
| binary search | 1442 (19.4%) | 1609 (12.3%) | 1609 (12.3%) |
| number theory | 1604 (12.6%) | 1604 (12.6%) | 2191 (1.6%) |
| strings | 1834 (5.7%) | 1834 (5.7%) | 2138 (2.2%) |
| divide and conquer | 1859 (5.4%) | 1859 (5.4%) | 1859 (5.4%) |
| two pointers | 2155 (2.0%) | 2155 (2.0%) | 2155 (2.0%) |
structures' and 'combinatorics', the performance decreased, suggesting that the retrieved examples can still introduce misleading information or noise.
In the Figure 4, there is a display of the average time and memory consumed in the runtime of the code generated for each problem by each LLM in all 3 scenarios. The problems considered were the ones that the given LLM solved in all the 3 approaches. Considering all models, in our RAG approach there was a decrease in computational resources used running the code with the test cases from the online judge.
For the 81 best solutions analyzed across the six evaluated LLMs DeepSeek-R1, Gemini 2.0, Claude 3.7 Sonnet, GPT-4o, Qwen2.5-Coder-32B, and GPT-3.5 Turbo, the majority of code lines exhibited a membership confidence greater than 0.5. This indicates that a substantial portion of the generated code segments were likely seen or closely related to samples present in the models' pretraining corpora. This finding suggests that earlier versions of these models were likely trained, at least partially, on subsets of the CodeContests dataset or similar competitive programming sources. However, it is plausible that these models were not trained on explicit <Problem, Solution>(i.e., input/output) pairs. Consequently, while they may have encountered frag-

Figure 4: Correctness analysis
ments of relevant code during pretraining, they did not necessarily learn the mapping between specific problem statements and their corresponding solutions. This lack of structured alignment may explain why these models often struggle with complex or higher-difficulty problems despite apparent familiarity with source code patterns.
In contrast, more recent state-of-the-art models have undergone advanced post-training procedures such as reinforcement learning from human feedback (RLHF) and supervised fine-tuning on curated <Problem, Solution>pairs across domains such as programming, mathematics, and logical reasoning [44]. These additional training stages strengthen their capacity for algorithmic reasoning and structured code synthesis, enabling them to generalize more effectively and solve harder problems. In future work, we plan to extend our analysis to the next generation of LLMs, such as GPT-5, Gemini 3, and other emerging architectures. Evaluating these models under the same retrieval-augmented and membership inference framework will allow a deeper understanding of how continual advances in model alignment and post-training optimization contribute to reasoning ability and code generation performance in competitive programming tasks.
5. Conclusion and Future Work
This paper investigated whether Retrieval-Augmented Generation (RAG) can systematically improve Large Language Models (LLMs) on competitive programming — a setting where success depends on algorithmic reasoning, robustness to hidden test cases, and the ability to avoid hallucinated or logically inconsistent code. We proposed a similarity-based RAG pipeline that retrieves up to three relevant solved problems from a large knowledge base using embedding similarity and a dynamic, query-dependent threshold designed to reduce retrieval noise while preserving useful exemplars. We evaluated six representative LLMs on a filtered subset of 81 CodeContests test problems for which at least one similar training example could be retrieved, comparing three conditions: zero-shot, random-retrieval augmentation, and similarity-based RAG.
Across models, similarity-based retrieval delivered consistent net gains over both baselines. On average, our RAG condition increased pass@1 to 20.37%, compared to 17.9% (zero-shot) and 17.28% (random retrieval), indicating that example relevance is critical: adding unrelated context tends to introduce harmful noise, whereas aligned examples provide actionable algorithmic structure that outweighs this cost. In Elo terms, the proposed RAG approach produced an average rating of 1014, improving over the zero-shot (925) and random-retrieval (927) conditions, reinforcing that RAG benefits are not only about solving more problems but also about solving harder ones.
Model-level analysis showed that stronger reasoners benefited most reliably from retrieval. DeepSeek-R1 achieved the highest overall performance and improved from 61.7% to 64.2% pass@1 under RAG, while random retrieval reduced it to 59.3%, again highlighting the importance of retrieval precision. Category-level results suggested that RAG can be especially valuable in domains where a single key insight unlocks the solution (e.g., number theory, where DeepSeek-R1's Elo increased markedly under RAG), while other categories exhibited occasional degradation, consistent with remaining sensitivity to misleading or weakly matched exemplars.
To complement performance evaluation with an epistemic perspective, we applied a Min-K membership inference analysis to estimate whether generated solutions were likely influenced by memorized training patterns. The analysis indicated that a substantial portion of code lines across the best solutions had membership confidence above 0.5, suggesting meaningful exposure to competitive-programming-like code in model pretraining corpora. Importantly, this does not imply that models learned exact problem-solution mappings; rather, it supports the interpretation that models may have seen fragments of similar code patterns without robust alignment to the corresponding statements — helping explain why retrieval of structured, relevant worked examples can still provide measurable gains in problem-solving.
Despite these findings, the study has limitations. First, evaluation was necessarily restricted to the subset of test problems with retrieved neighbors, which focuses the analysis on settings where retrieval is feasible. Second, we used a fixed embedding model and a bounded number of retrieved examples (up to three), leaving open questions about the optimal representation, retrieval depth, and prompt packaging under tight context budgets. Third, the membership inference is an indirect signal and should be interpreted as evidence of exposure patterns rather than definitive proof of duplication.
Future work will extend this framework along four directions. (i) Retrieval quality: explore hybrid retrieval (dense + sparse), reranking, and retrieval-time verification to further reduce harmful exemplars, especially for categories where RAG occasionally degrades performance. (ii) Adaptation and personalization: learn per-model and per-category retrieval policies (thresholds, number of examples, and formatting) to maximize gains while controlling noise. (iii) Broader benchmarks: replicate the pipeline on more recent and contamination-aware datasets, enabling a clearer separation between genuine reasoning improvements and latent memorization. (iv) Next-generation models and safety diagnostics: evaluate upcoming models under the same dual protocol—performance plus membership inference — to better understand how post-training advances (e.g., alignment and reasoning-tuned training) interact with retrieval grounding in competitive programming contexts.
References
[1] J. Wang, Y. Chen, A review on code generation with llms: Application and evaluation, in: 2023 IEEE International Conference on Medical Artificial Intelligence (MedAI), IEEE, 2023, pp. 284–289.
[2] C. E. Jimenez, J. Yang, A. Wettig, S. Yao, K. Pei, O. Press, K. Narasimhan, Swe-bench: Can language models resolve real-world github issues? (2024). arXiv:2310.06770. URL https://arxiv.org/abs/2310.06770
[3] L. Wang, C. Shi, S. Du, Y. Tao, Y. Shen, H. Zheng, X. Qiu, Performance review on llm for solving leetcode problems, in: 2024 4th International Symposium on Artificial Intelligence and Intelligent Manufacturing (AIIM), 2024, pp. 1050–1054.
[4] OpenAI, :, A. Hurst, A. Lerer, A. P. Goucher, A. Perelman, A. Ramesh, A. Clark, A. Ostrow, A. Welihinda, A. Hayes, A. Radford, et al., Gpt-4o system card (2024). arXiv:2410.21276. URL https://arxiv.org/abs/2410.21276
[5] Anthropic, Model Card Addendum: Claude 3.5 Sonnet, Model card, Anthropic (2024).
[6] Z. Yu, Y. Zhao, A. Cohan, X.-P. Zhang, Humaneval pro and mbpp pro: Evaluating large language models on self-invoking code generation (2024). arXiv:2412.21199. URL https://arxiv.org/abs/2412.21199
[7] M. Chen, J. Tworek, H. Jun, Q. Yuan, H. P. de Oliveira Pinto, J. Kaplan, H. Edwards, Y. Burda, N. Joseph, et al., Evaluating large language models trained on code (2021). arXiv:2107.03374. URL https://arxiv.org/abs/2107.03374
[8] Z. Zheng, Z. Cheng, Z. Shen, S. Zhou, K. Liu, H. He, D. Li, S. Wei, H. Hao, J. Yao, et al., Livecodebench pro: How do olympiad medalists judge llms in competitive programming? (2025). arXiv:2506.11928. URL https://arxiv.org/abs/2506.11928
[9] M. S. Hossain, A. Tabassum, M. F. Arefin, T. S. Zaman, Llm-pros: Analyzing large language models' performance in competitive problem solving (2025). arXiv:2502.04355. URL https://arxiv.org/abs/2502.04355
[10] Y. Xia, W. Shen, Y. Wang, J. K. Liu, H. Sun, S. Wu, J. Hu, X. Xu, Leetcodedataset: A temporal dataset for robust evaluation and efficient training of code llms (2025).
[11] Google DeepMind, Model Card: Gemini 2.5 Pro, Model card, Google DeepMind (2025).
URL https://storage.googleapis.com/model-cards/documents/gemini-2.5-pro.pdf
[12] DeepSeek-AI, D. Guo, D. Yang, H. Zhang, J. Song, R. Zhang, R. Xu, Q. Zhu, S. Ma, P. Wang, X. Bi, et al., Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning (2025). arXiv:2501.12948. URL https://arxiv.org/abs/2501.12948
[13] F. Liu, Y. Liu, L. Shi, H. Huang, R. Wang, Z. Yang, L. Zhang, Z. Li, Y. Ma, Exploring and evaluating hallucinations in llm-powered code generation (2024).
[14] G. Izacard, E. Grave, Leveraging passage retrieval with generative models for open domain question answering (2021). arXiv:2007.01282.
[15] Y. Gao, Y. Xiong, X. Gao, K. Jia, J. Pan, Y. Bi, Y. Dai, J. Sun, H. Wang, H. Wang, Retrieval-augmented generation for large language models: A survey 2 (2023) 1.
[16] H. Deng, Y. Meng, S. Tang, W. Ouyang, X. Ma, Cpret: A dataset, benchmark, and model for retrieval in competitive programming (2025). arXiv:2505.12925. URL https://arxiv.org/abs/2505.12925
[17] E. Dickey, The failure of plagiarism detection in competitive programming (2025). arXiv:2505.08244. URL https://arxiv.org/abs/2505.08244
[18] Prompt engineering, https://platform.openai.com/docs/guides/prompt-engineering, acesso em: 26 de agosto de 2025 (2025).
[19] H. Ma, C. Zhang, Y. Bian, L. Liu, Z. Zhang, P. Zhao, S. Zhang, H. Fu, Q. Hu, B. Wu, Fairness-guided few-shot prompting for large language models (2023). arXiv:2303.13217. URL https://arxiv.org/abs/2303.13217
[20] N. Balasubramanian, Query-dependent selection of retrieval alternatives, Ph.D. thesis, University of Massachusetts Amherst (2011).
[21] Y. Li, D. Choi, J. Chung, N. Kushman, J. Schrittwieser, R. Leblond, T. Eccles, J. Keeling, F. Gimeno, A. Dal Lago, et al., Competition-level code generation with alphacode, arXiv preprint arXiv:2203.07814 (2022).
[22] M. Mirzayanov, Codeforces (2010). URL https://codeforces.com/
[23] Q. Shi, M. Tang, K. Narasimhan, S. Yao, Can language models solve olympiad programming? (2024). arXiv:2404.10952. URL https://arxiv.org/abs/2404.10952
[24] S. Quan, J. Yang, B. Yu, B. Zheng, D. Liu, A. Yang, X. Ren, B. Gao, Y. Miao, Y. Feng, et al., Codeelo: Benchmarking competition-level code generation of llms with human-comparable elo ratings (2025). arXiv:2501.01257. URL https://arxiv.org/abs/2501.01257
[25] N. Jain, K. Han, A. Gu, W.-D. Li, F. Yan, T. Zhang, S. Wang, A. Solar-Lezama, K. Sen, I. Stoica, Livecodebench: Holistic and contamination free evaluation of large language models for code (2024). arXiv:2403.07974. URL https://arxiv.org/abs/2403.07974
[26] OpenAI, Introducing openai o3 and o4-mini, https://openai.com/index/introducing-o3-and-o4-mini/ (2025).
[27] M. Boubdir, E. Kim, B. Ermis, S. Hooker, M. Fadaee, Elo uncovered: Robustness and best practices in language model evaluation (2023). arXiv:2311.17295. URL https://arxiv.org/abs/2311.17295
[28] A. E. Elo, S. Sloan, The Rating of Chessplayers: Past and Present, 1978, no Title.
[29] S. Zhou, F. Yao, C. Dong, Z. Wang, J. Shang, Evaluating the smooth control of attribute intensity in text generation with llms (2024). arXiv:2406.04460. URL https://arxiv.org/abs/2406.04460
[30] D. AI, Deepseek-r1, https://huggingface.co/deepseek-ai/DeepSeek-R1 (2025).
[31] Google DeepMind, Model card: Gemini 2.0 Flash Reasoning, https://blog.google/technology/google-deepmind/gemini-model-updates-february-2025/ (2025).
[32] Anthropic, System card: Claude 3.7 Sonnet (no reasoning variant), https://assets.anthropic.com/m/785e231869ea8b3b/original/claude-3-7-sonnet-system-card.pdf (2025).
[33] Alibaba Cloud, Model card: Qwen (qwen 2.5-coder-32b), https://huggingface.co/Qwen (2025).
[34] OpenAI, GPT-3.5 Turbo model documentation, https://platform.openai.com/docs/models/gpt-3.5-turbo (2024).
[35] O. Levy, Y. Goldberg, Dependency-based word embeddings, in: Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), 2014, pp. 302–308.
[36] J. Johnson, M. Douze, H. Jégou, Billion-scale similarity search with gpus (2017).
[37] Z. Zhang, M. Fang, L. Chen, Retrievalqa: Assessing adaptive retrieval-augmented generation for short-form open-domain question answering (2024).
[38] T. S. Soares, R. L. H. Costa, E. Soares, I. Calderon, G. M. Lunardi, P. H. D. Valle, G. T. Guedes, W. Silva, Machine learning-assisted tools for user experience evaluation: A systematic mapping study, Simpósio Brasileiro de Sistemas de Informação (SBSI) (2025) 379–388.
[39] A. L. Miranda, R. Garcia, G. M. Lunardi, R. Vilela, P. H. Vale, W. Silva, Projeto e avaliação de um template de worked examples para o ensino de programação, in: Simpósio Brasileiro de Informática na Educação (SBIE), SBC, 2023, pp. 1673–1684.
[40] W. Shi, A. Ajith, M. Xia, Y. Huang, D. Liu, T. Blevins, D. Chen, L. Zettlemoyer, Detecting pretraining data from large language models, in: The Twelfth International Conference on Learning Representations, 2024.
URL https://openreview.net/forum?id=zWqr3MQuNs
[41] S. Zanella-Beguelin, L. Wutschitz, S. Tople, A. Salem, V. Rühle, A. Paverd, M. Naseri, B. Köpf, D. Jones, Bayesian estimation of differential privacy, in: International Conference on Machine Learning, PMLR, 2023, pp. 40624–40636.
[42] A. Havrilla, M. Iyer, Understanding the effect of noise in llm training data with algorithmic chains of thought (2024). arXiv:2402.04004. URL https://arxiv.org/abs/2402.04004
[43] T. B. Brown, B. Mann, N. Ryder, M. Subbiah, J. Kaplan, P. Dhariwal, A. Neelakantan, P. Shyam, G. Sastry, A. Askell, S. Agarwal, A. Herbert-Voss, G. Krueger, T. Henighan, R. Child, A. Ramesh, D. M. Ziegler, J. Wu, C. Winter, C. Hesse, M. Chen, E. Sigler, M. Litwin, S. Gray, B. Chess, J. Clark, C. Berner, S. McCandlish, A. Radford, I. Sutskever, D. Amodei, Language models are few-shot learners (2020). arXiv:2005.14165.
URL https://arxiv.org/abs/2005.14165
[44] G. Tie, Z. Zhao, D. Song, F. Wei, R. Zhou, Y. Dai, W. Yin, Z. Yang, J. Yan, Y. Su, et al., Large language models post-training: Surveying techniques from alignment to reasoning, arXiv preprint arXiv:2503.06072 (2025).