Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

7oSkaaa's blog

By 7oSkaaa, 7 months ago, In English

Hello Codeforces!

I want to share an update to an open-source project I've been building: a multi-agent AI pipeline that generates complete, Polygon-ready competitive programming problems from scratch — statement, tutorial, validator, checker, solutions (two ACCs, TLE, WA), test generator, and interactor — then checks them locally and uploads them to Polygon.

→ GitHub: https://github.com/7oSkaaa/polygon-problems-generator


The problem

Setting a proper problem for a contest takes a lot of time, even when you already know the idea:

  • Writing a clean LaTeX statement in Polygon style
  • Writing a bulletproof testlib.h validator (and validator tests)
  • Choosing or writing the right checker
  • Writing an accepted solution, a second ACC with a different approach, a TLE brute, and a WA solution
  • Writing a generator with a complete FreeMarker script and real min/max tests
  • Reviewing everything against Polygon conventions
  • Checking that the idea is not a copy of an existing problem
  • Uploading to Polygon and surviving package verification

That's hours of work per problem. The tool automates the mechanical parts. You still own the idea and the final Polygon pass.


Intended workflow (this is the important part)

Local first. Polygon second. Do not use Polygon as the debugger.

idea → /generate-problem → originality → ./verify.sh → python -m polyup → Polygon package verify
              ↑                              |                  |
              └──────── /fix-component ←─────┴──────────────────┘
  1. Generate locally with /generate-problem (or the orchestrator). Everything lands in problems/<name>/.
  2. Originality — search against ~250k known tasks via yuantiji.ac. Copies / near-duplicates block the pipeline except Ace and Div2-A (those stay advisory).
  3. Local verify — ./verify.sh problems/<name> compiles with -Wall -Wextra -Werror, runs validator tests, samples, ACC / Java / second ACC, WA rejection, and ACC-vs-brute stress.
  4. Upload — python -m polyup <name> pushes to Polygon and builds the package with verification. That is the official invocations pass.
  5. If something fails, do not regenerate the whole problem. Name the file, paste the log, keep the rest unchanged (/fix-component).

verify.sh is a pre-upload harness. It is not Polyman and it does not replace Polygon's test-script / invocations loop. Polyman is still the right tool if you want a full local Polygon-like runner. Use Polygon for statement PDF, full invocations, and time-limit calibration.

Docs in the repo: docs/workflow.md, docs/verify.md.


How it works

You describe the idea once. Specialised sub-agents (isolated context, strict instructions) each own one concern:

Agent Produces
statement-agent statement.tex, tutorial.tex
validator-agent validator.cpp
checker-agent standard checker or checker.cpp
interactor-agent interactor.cpp (interactive only)
solutions-agent acc.cpp, acc_java.java, acc_alt.cpp, brute.cpp, wa.cpp
generator-agent generator.cpp + FreeMarker script
reviewer-agent Full review — blocks on any FAIL
orchestrator Runs the pipeline; you don't call the others directly

Shared rules (roster, folder layout, pipeline, critical rules) live in one file: .claude/shared.md. Each agent file is a thin role stub: "read shared.md first, then do your job." A pre-commit hook syncs that to Cursor, Codex, Copilot, Windsurf, and Antigravity so the rules don't drift.

The reviewer is the gatekeeper. FAIL → regenerate only that component until every verdict is PASS. Then verify.sh is the local gate before upload.


Setup

Prerequisites: Git, Python 3.10+, g++ (C++17), optionally javac, and any AI coding tool that supports agents/skills (Claude Code, Cursor, Copilot, Windsurf, Codex, Antigravity).

# 1. Fork the repo, then clone your fork
git clone https://github.com/<your-username>/polygon-problems-generator.git
cd polygon-problems-generator

# 2. Pre-commit hook (one-time per machine)
git config core.hooksPath .githooks

# 3. Polygon API keys (only needed to upload)
cp .env.example .env
# POLYGON_API_KEY / POLYGON_API_SECRET

# 4. Pull before generating — rules change often
git pull origin main

Generating a problem

Open the repo in your AI tool and run:

/generate-problem
name:         <snake_case_identifier>
statement:    <what to compute — keep it short, hide the algorithm>
solution:     <intended approach>
constraints:  <full constraint block>
multitest:    <yes / no>          (optional, default: yes)
interactive:  <yes / no>          (optional, default: no)
sample tests:
  Input:  ...
  Output: ...
Parameter Required Default Description
name yes — Snake_case id. Becomes the title: carrot_sum → Carrot Sum
statement yes — What the solver must compute
solution yes — Intended algorithm (not written into the statement)
constraints yes — e.g. 1 ≤ t ≤ 10^4, 1 ≤ n ≤ 10^5
multitest no yes Multiple test cases per file
interactive no no Needs an interactor
sample tests yes — At least one sample (or a full interaction)

Example (standard):

/generate-problem
name:         carrot_sum
statement:    Count integers in [L, R] whose digit sum is prime
              and the number is divisible by the sum of its digits.
solution:     Digit DP — precompute suffix-count tables for each
              prime digit-sum up to 162, then process queries offline.
constraints:  1 ≤ t ≤ 10^4, 1 ≤ L ≤ R ≤ 10^18
sample tests:
  Input:
  3
  1 10
  12 12
  1 100
  Output:
  4
  1
  10

Example (interactive):

/generate-problem
name:         find_the_number
statement:    There is a hidden integer x in [1, n]. Find it using
              at most ceil(log2(n)) queries of the form "? v",
              to which the judge responds "<", "=", or ">".
solution:     Binary search on [1, n].
constraints:  1 ≤ t ≤ 100, 1 ≤ n ≤ 10^9
multitest:    yes
interactive:  yes
sample tests:
  > ? 500000000
  < <
  > ? 250000000
  < >
  > ? 375000000
  < <
  > ! 312500000

The agent stops only if a required parameter is missing.


The pipeline

 1   Create folder from templates
 2   Generate LaTeX statement
 2b  Originality check (yuantiji) — block copies except Ace / Div2-A
 3   Generate LaTeX tutorial
 4   Generate validator
 5   Recommend or generate checker
 5b  (interactive) Generate interactor
 6   Suggest approaches
 7   ACC — C++ (relaxed, not over-optimized) + Java
 7b  Second ACC (`acc_alt.cpp`) — different approach
 8   TLE brute
 9   WA (subtle bug)
10   Generator + FreeMarker script (min and max for every variable)
10b  Sample tests + validator tests
11   Review — regenerate any FAIL
12   Tags (`#topic`, `#difficulty`) + Polygon solution tags
13   Difficulty note
14   ./verify.sh — then python -m polyup <name>

What gets generated

problems/carrot_sum/
├── statement/
│   ├── statement.tex
│   └── tutorial.tex
├── solutions/
│   ├── acc.cpp           ← main ACC (clear, relaxed)
│   ├── acc_java.java
│   ├── acc_alt.cpp       ← second ACC, different approach
│   ├── brute.cpp         ← TLE (WA if interactive — query limit)
│   └── wa.cpp
├── generators/
│   └── generator.cpp
├── samples/
├── validator_tests/
├── validator.cpp
├── checker.cpp
├── interactor.cpp        ← interactive only
├── tags.txt
├── difficulty.txt
└── originality.json

Local verify (verify.sh)

./verify.sh problems/<name>
./verify.sh problems/<name> --stress 200 --keep
./verify.sh problems/<name> --skip-originality   # offline

Compared to other tools:

  • verify.sh — fast local preflight (compile, validator tests, a slice of generated tests, cross-check solutions, stress). Does not run Polygon FreeMarker scripts the way Polygon does.
  • Polyman — local Polygon-like environment: pull a problem, generate tests, run invocations. Heavier, closer to the server.
  • python -m polyup + package verify — official compile + invocations on Polygon (--no-verify to skip).

Use verify.sh until it is green, then Polyman or Polygon — not Polygon as the only test runner.


Originality (yuantiji.ac)

python -m polyup originality <name>

No Polygon keys required. If the closest hit looks like the same task (cosine ≥ 0.85 by default), the pipeline stops unless the problem is Ace or Div2-A. The report is written to originality.json.


If something fails — how to prompt a fix

Do not re-run the whole pipeline. Paste the failing component:

Fix problems/<name>/validator.cpp.
verify.sh (or Polygon) says:
<paste the log>
Keep the rest of the problem unchanged.

Or:

/fix-component
name: carrot_sum
component: validator
issue: <paste>

Same pattern for a statement wording issue, an invocation mismatch, or a checker WA. If originality blocked you, don't "rephrase to dodge the search" — pick a different idea.


Upload (polyup)

python -m polyup carrot_sum
python -m polyup carrot_sum --dry-run
python -m polyup carrot_sum --time-limit 2000 --memory-limit 512

Uploads statement, tutorial, validator, checker, interactor, solutions with Polygon tags (MA / OK / TL / WA), generator + script, validator tests, tags; then commits and builds the package.


Generator and interactive notes

The FreeMarker script must hit min and max for every variable (-n / -k exact-value flags). Boundary coverage is not optional.

Interactors use inf / ouf / cout + flush. On invalid query or query-limit exceeded they send -1 then quitf(_wa, ...). Solutions read responses as string (not char — that splits -1). Interactive solutions must not use cin.tie(nullptr). Interactive brute.cpp is tagged Wrong Answer, not TLE.


Multi-tool support

.claude/shared.md + .claude/agents/*.md are the source. sync-ai-configs.py (pre-commit hook) copies them to:

.cursor/rules/                  → Cursor
AGENTS.md                       → OpenAI Codex
.github/copilot-instructions.md → GitHub Copilot
.windsurfrules                  → Windsurf
.agents/skills/                 → Google Antigravity

You change shared rules in one place. Every tool stays in sync.


Repository

→ https://github.com/7oSkaaa/polygon-problems-generator

To use it: 1. Fork the repo 2. Clone your fork 3. git config core.hooksPath .githooks 4. git pull before each session 5. Open in your AI tool, run /generate-problem 6. Run ./verify.sh problems/<name> 7. Upload with python -m polyup <name> when local verify is green

Follow me on GitHub: https://github.com/7oSkaaa

I would love feedback from problem setters who try it. If something breaks, or the output is poor for a particular problem type, open an issue and I'll fix it.

  • Vote: I like it
  • +100
  • Vote: I do not like it

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

it's really helpful thanks for your efforts

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will use it myself, really helpful <3

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

orz

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great work, Thanks for your efforts

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will try it ^_^, Great Work 7oSkaaa

»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Has anybody used this tool and can recommend it?

What's the intended workflow? Create the problem locally and then check in Polygon for issues? If something fails or needs improving, what is the best way to prompt the tool to fix it?

It seems that there's now verify.sh tool for local test&run generation but there's no documentation. I wonder how it compares to other tools like Polyman.

  • »
    »
    3 months ago, hide # ^ |
    ← Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    Hello Errichto, I'm very happy to see your comment

    I'v update the blog here with the last version of the tool, you can check the README from the repo on GitHub, I also added that now the tool can create the problem on polygon and do all stuff to create a clear problem using Polygon API Key, also I'm integrating with http://yuantiji.ac/en/ to check the originality for the problem and try to avoid the copied problem or not original one, I will wait your feedback after trying the tool and if you have any negative feedback feel free to tell me and I will work on it, also the repo is public feel free to contribute if you wanna do that.

    I added the workflow used in the blog, and also I used verify.sh to verify all changes before uploading.