The First Actual AI Agent for Competitive Programming and Problem Solving

Revision en2, by Hmzaawy, 2025-12-19 17:32:08

The First Actual AI Agent for Competitive Programming and Problem Solving

Hello Codeforces!

Yes. It is me again :D .

I’m excited to share a project I've been working on at Repovive, with the Grate Shayan.

We all know the struggle: you're stuck on a problem, the editorial is confusing (or non-existent), and you just need a small hint to nudge you in the right direction—not the full solution. That's exactly what this tool is built for.

What is it?

The new addition to the Repovive Chorme Extension, an AI Agent, that embeds a context-aware AI chat directly into Codeforces (and AtCoder/LeetCode) problem pages.

It isn't just a wrapper around ChatGPT, nor is it a proprietary "Black Box" model trained from scratch. * Powered by Gemini: It leverages the Google Gemini API (gemini-pro/flash) for reasoning. * Your Own Keys: You use your own free API key from Google AI Studio. This means no subscription fees and total control over your usage. * Context Aware: It specifically understands competitive programming contexts: * It reads the problem statement, constraints, and test cases automatically. * It fetches Accepted solutions from top rankers (Red Coders) to understand the optimal approach. * It simulates a "Socratic Coach": it refuses to give you the code initially. Instead, it asks you guiding questions to help you derive the solution yourself.

Platform Deep Dive: Under the Hood

Each platform requires a unique engineering approach. Here is how we handle the "Big Three":

1. Codeforces

  • How it works:
    • Parsing: We use the official codeforces.com/api to fetch problem metadata.
    • Solution Mining: We identify the contest "Winners" via the API, find their submission IDs, and then get their source code.
    • Anti-Cheat: We detect the specific .countdown timer element used in active rounds.
  • Tradeoffs & Limitations:
    • API Rate Limits: Codeforces has a strict 5 req/sec limit. If the site is under load (e.g., right after a contest), the "Solution Mining" might fail or be slow.
    • Old Contests: Some very old problems ($$$ \lt 2015$$$) might have missing metadata or different DOM structures that break parsing.

2. AtCoder

  • How it works:
    • Parsing: Since AtCoder has no official API, we built a robust HTML parser that reads the DOM directly to extract inputs/outputs.
    • Solution Mining: The agent navigates to the submissions page, filters for "Accepted" + "C++" + "Fastest", and gets the code from the top result.
  • Tradeoffs & Limitations:
    • Login Wall: For some contests, you must be logged in to view submissions. The agent might show a "Cookie Error" if it can't access the submission page (it tries to inherit your session, but browser security can block this).
    • Fragility: If AtCoder changes their website UI (class names), the geter will break until we update the extension.

3. LeetCode

  • How it works:
    • Parsing: We reverse-engineered LeetCode's GraphQL API to fetch clean problem questions without parsing messy HTML.
    • Knowledge Source:
      • Old Problems (ID < 3200): Since these are in the LLM's training data, we rely on the model's internal knowledge for faster responses.
      • New Problems: We fetch the top-voted "Community Solution" via GraphQL to give the model context on brand new questions.
    • Anti-Cheat: We strictly disable the agent on any URL containing /contest/.
  • Tradeoffs & Limitations:
    • SPA Navigation: LeetCode is a Single Page Application (React). Sometimes the button might disappear when navigating between problems; a page refresh fixes this.
    • Community Quality: For new problems, if the top community solution is bad/wrong, the AI's advice might be skewed (Garbage In, Garbage Out).

Legal & Ethical Notices (Anti-Cheat)

Crucial Point: We take fair play seriously.

  • Strict Anti-Cheat: The agent is programmed to automatically disable itself during live contests.
    • Codeforces: It detects the server-side countdown timer for active rounds.
    • AtCoder: It checks the contest timer element.
    • LeetCode: It hard-blocks any URL containing /contest/.
  • Purpose: This tool is strictly for upsolving and practice. Using AI assistance during a rated contest is cheating and will get you banned. Don't do it.

How to Get Started

  1. Install Repovive: Link to Extension Store / GitHub
  2. Get a Gemini API Key:
  3. Open a Problem: Navigate to any Codeforces problem.
  4. Click the Sparkle: You'll see the floating AI button. Click it, paste your API key once, and start upsolving!
Tags training, codeforces, upsolving, chome extension, ai-assisted development

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en21 English Hmzaawy 2025-12-26 15:22:05 94 Tiny change: '! \n```\n\n```\nC' -> '! \n```\n___\n\n```\nC'
en20 English Hmzaawy 2025-12-26 15:20:41 0
en19 English Hmzaawy 2025-12-26 15:20:41 23
en18 English Hmzaawy 2025-12-26 15:20:03 750
en17 English Hmzaawy 2025-12-23 20:09:36 2 Tiny change: '\nHello Code' -> 'Hello Code' (published)
en16 English Hmzaawy 2025-12-23 19:35:26 77
en15 English Hmzaawy 2025-12-23 19:35:11 11
en14 English Hmzaawy 2025-12-19 20:14:03 6
en13 English Hmzaawy 2025-12-19 19:20:29 2 Tiny change: '76a.png)\nThe exte' -> '76a.png)\n\nThe exte'
en12 English Hmzaawy 2025-12-19 19:19:28 20
en11 English Hmzaawy 2025-12-19 19:16:44 2 Tiny change: '387.png)\n* **Ho' -> '387.png)\n\n* **Ho'
en10 English Hmzaawy 2025-12-19 19:15:57 6
en9 English Hmzaawy 2025-12-19 19:13:04 2 Tiny change: 'ith the Grate [user:Sha' -> 'ith the Great [user:Sha'
en8 English Hmzaawy 2025-12-19 18:55:29 164
en7 English Hmzaawy 2025-12-19 18:54:23 1583
en6 English Hmzaawy 2025-12-19 18:21:45 180
en5 English Hmzaawy 2025-12-19 18:12:28 566
en4 English Hmzaawy 2025-12-19 18:11:33 560
en3 English Hmzaawy 2025-12-19 18:06:50 1850
en2 English Hmzaawy 2025-12-19 17:32:08 4998
en1 English Hmzaawy 2025-12-19 17:23:15 97 Initial revision (saved to drafts)