Recently, I’ve been reorganizing my algorithm templates, which include some data structures and graph algorithms. Since my coding style tends to favor using std::vector instead of C-style arrays, I want my templates to be more encapsulated. I admit I’m not very familiar with this style of templates, so I thought of using AI to help me refine them. Below is a template for finding the LCA using Heavy-Light Decomposition:
My previous templates looked like this:
Meanwhile, I also directly generated the following template using ChatGPT-5:
As we can see, this template doesn’t really have any issues. In fact, in terms of readability, it is already better than most beginners’ code — or at least easier to maintain.
The above examples illustrate that AI has indeed proven to be very effective in maintaining algorithm templates (perhaps partly because such templates already appear in its training data). Whether it is using AI to polish existing templates, assist in modifying them, or directly generate a new one, AI shows strong usability.
Of course, in theory, using AI-generated code during contests is clearly not allowed. But my real question lies in the boundary of using such “templates generated by AI in advance.” On one hand, they are indeed produced by AI; on the other hand, they are prepared before the contest, just like how most participants maintain their own template libraries to bring into competitions.
As a beginner, I would also like to emphasize that AI has lowered the barrier to learning. With AI tools, we can more easily obtain high-quality reference code, and even detect and correct subtle mistakes we might otherwise overlook. At the very least, outside of contests, they can serve as effective learning tools.
Therefore, I started this discussion to hear opinions from the Codeforces community:
Should we allow the use of AI-generated templates?
- Absolutely not
- Allow polishing or debugging templates with AI
- Allow directly using AI-generated templates
If AI templates are allowed, in which scenarios should they be acceptable?
- Only in pre-contest preparation (AI-assisted template maintenance)
- Also during contests (AI-generated or AI-debugged templates)
Should templates indicate when they are generated or refined by AI?
For options not covered above, share it in the comments.
UPD: One feasible approach is to upload these templates to GitHub in advance. The commit history on GitHub can serve as evidence that the templates were prepared beforehand.









Auto comment: topic has been updated by susenyang (previous revision, new revision, compare).
My personal view: I think that using AI in any form of preparation before the contest should be acceptable. However, during the contest, one should not seek help from AI in any way — even for templates.
facts
ye
Before: good
During: bad
After: who cares, just use it
AI use to generate templates is allowed. This is why my code is frequently mistaken as AI — I have generated a whole bunch of my templates using GPT lol
It is what I am worried about. Be mistaken as a cheater is annoyed.
This is why my cheater database (cf-cheater-database.vercel.app) has an Appeals function where people who haven't cheated can tell us if they've been wrongly flagged.
But to be fair, how is a wrongly flagged person supposed to defend themselves when they don't even know why they were accused of cheating? Burden of proof lies on accuser, not on the accused. Shouldn't you consider giving the proof of cheating?
For the billionth time, the point of appeals is not for people to "prove innocence" for such a concept does not exist.
The point of appeals is to get the (of course, infallible!) admin team to look back over the evidence and ensure that it was correct. In 99% of cases, such (rare) false positives are removed. If someone is wrongly flagged and their appeal does not go through, they can DM me, and people have done this in the past.
I cannot publicly reveal cheating evidence because that would result in cheaters getting smarter and avoiding falling into the same traps.
I'm sorry I didn't know you have answered this before. So you are saying if someone is still wrongly flagged, they have to DM you to ask for evidence? Can't every cheater do that though? I do understand the drawback of revealing cheating evidence, but this is a big issue too.
That's okay. It's incredibly rare and unlikely that such instances happen when an appeal is declined and a person resorts to DMing me. And I am fairly sure i have yet to have seen a case where I have had to remove a person from the database even AFTER they have appealed — and that is with over 2.1k cheaters currently in the database. So I'd say I'm doing pretty well.
I think after appealing people just get annoyed and leave it, because it's not official after all. In particular, I know p1k4 who is like that.
I mean, the user clearly cheated, I have nothing more to say...
Well, I'm pretty sure he isn't a cheater, since he is active on Errichto's server (discussing solutions to hard problems) and it is highly unlikely that he cheated. He also denied when I asked if he did (of course every cheater would say that). Would you like to send the evidence to me in DM?
There's nonzero cheaters active on this server lol
I'm sorry for wasting your time, He just told me that he didn't know that what he did was cheating. So he didn't confess when I asked him.
a lot of my templates are generated with help of chat-GPT as C++ is not my main language so I use AI a lot to refactor / improve things ( but before the contest i mean )
I think LLMs can serve as a decent teacher, so asking them questions or requesting code before the competition begins is reasonable-just like we’re allowed to use pre-written code. But once the competition starts, we can only use what we’ve prepared in advance, and of course, we can’t ask the "teacher" anymore.
I have feeling that in future we should be able to use AI during contests. Contests might look different though.
Like calculator is allowed in some of our exams in engineering courses.
A calculator can be allowed but in classes like calculus you're not allowed to use calculators that solve integrals. Even if you use it, you're most likely getting 0 score because you have no understanding of how to reach the answer and the exam's role is testing if you can go through the path to the answer.
this is a classic theory vs application oriented perspective debate.
I am an engineer so I incline more towards application side and I know lot of people who study theory and say same things like this , so totally understandable and thanks for sharing your perspective
I'm also an engineer. You have to take into consideration where you're posting: in the biggest competitive programming website. CP is mostly about solving these really specific math/computer science-ish problems through programming. If you take out the solving and coding part of it, then there's no meaning to it.
I'd compare it to "well when playing counter-strike one of the goals is to hit bullets on the opposing team, so to optimize reaching that goal I should... of course, use an aim-bot to take the burden of aiming out of my hands!"
Can't agree more. In some engineering applications, if there are no confidentiality requirements, using LLMs for assistance is completely feasible. However, in competitive programming, it is against the rules.
thanks for clarifying that you are engineer.
Just want to mention I am not advocating for anyone to use AI during the contest, if my comment was understood that way.
I think this would inevitably lead to unfairness. The fact is that different models come with very different pricing. Some of them are free, while others cost tens or even hundreds of dollars per month. Their performance in competitive programming also varies greatly. If we allow the use of AI during contests, then programming competitions would essentially turn into an arms race of AI models, which clearly deviates from their original purpose.
true today,
but I am hopeful things will be more affordable in future,
Contests will have to adapt accordingly, and new kinds of puzzles / problems will be required.
Honestly, you're robbing yourself from a good chance to become a better programmer.
Curious to know your definition of a
better programmerIn this case it's about your capacity of reading ideas from other people and being able to implement them well according to your understanding.
thanks for sharing your perspective on this.
I think this issue can be divided into two different situations:
Practical preparation for a contest. For example, I need a segment tree template to prepare for tonight’s contest. I’m worried that I might realize during the contest that a segment tree is required, but I may not be able to implement it quickly. In this case, I think it is reasonable to use LLMs to assist in implementing the template, or even to directly generate one.
Learning and understanding the data structure. On the other hand, if my goal is to learn the segment tree, then I don’t think directly generating a template is the right way. A better approach is: try to write it out according to my own understanding first, and then compare it with a standard template. When I notice differences, I ask myself: " Could my version still be correct? If not, why ?" I believe this process deepens our understanding of the template, instead of just knowing how to use it.
That's fair, but even in the first situation: when people ask me "what should I study a week before ICPC regionals?" my answer is always "nothing, you should've studied during the whole year to prepare for now" because of experiences with unfamiliar templates enticing people to waste time trying to understand the template instead of trying other doable problems.
Yes. From my personal experience, the templates that can actually be used in official contests are always the ones that I have already mastered, not those prepared at the last minute in the first way.
im just commenting for my contribution to go up
Unfortunately, the simple act of leaving a comment does not increase contribution, and in the case of this comment, it will probably lower your contribution.https://mirror.codeforces.com/blog/entry/145815?#comment-1304663
that's my plan...
Auto comment: topic has been updated by susenyang (previous revision, new revision, compare).
i don't understand what you're talking about. AI use is forbidden DURING the contest. getting any code from any source before the contest is allowed, so I don't understand what is the problem with AI-generated templates if you created them in advance. what are we even talking about here?
I share the same view on the use of AI. What I am concerned about is: if we submit templates pre-generated with AI during a contest, would that be considered cheating? Anti-AI-cheating system cannot tell whether our template was created beforehand or obtained from AI during the contest. This is exactly the motivation behind me starting this discussion.
if you fear that, you can just publish your whole AI-generated template library on github in advance and then dispute the ban if you get banned.
Thank you for your suggestion! In fact, this is exactly what I’m doing right now, and your reminder made me realize that it can serve as strong evidence. Once again, I sincerely appreciate it.