Hi, I want to share a recent change in my CP workflow and ask for your help on it.
Story: For a long time, I was heavily reliant on VSCode with the CPH extension (for those who don't know, it's an extension that makes running and testing code for CP incredibly easy). CPH was convenient, so it got to the point where I didn't even know how to compile C++ code with the CLI (I never knew how to).
Then, I switched to CPEditor for a few months. It was pretty similar to VSCode + CPH, maybe even faster. But recently I've been solving some IOI-like batch problems (where we are given a grader and just need to implement some functions, unlike the common format of CP problems). I don't even run sample test cases when solving these because I think CPEditor defaults to single-file compilation, not supporting linking multiple files.
So, I decided to switch back to VSCode, but with a different setup this time.
I would like to ask 2 questions:
- How do you set up raw VSCode (no extensions, no snippets) fast before an onsite competition? Can you share your workflow?
- How do you test batch/grader problems? Can you share your workflow?
Thanks in advance.









Auto comment: topic has been updated by IWantImprovement (previous revision, new revision, compare).
I think the main thing is to stop treating VS Code as the tool that runs your code. It's just the editor; the compiler and terminal do the actual work. Once you're comfortable with that, you don't really need CPH or any other extension for the basic workflow.
1. Setting up raw VS Code before a contest
I would keep the setup as simple as possible. The most important thing is to have a working compiler and know how to use it before the contest starts.
First, check that
g++is available:Then open your contest folder in VS Code, create a
main.cppfile, and open the integrated terminal using `Ctrl + ``.For a normal single-file problem, I would compile and run it using:
The exact standard flag should match the one you intend to use in the contest. On Windows with MinGW, the executable will generally be
main.exe, which you can run with.\main.exein PowerShell.For testing against a file, I usually find input redirection more convenient than repeatedly typing the same test case:
You can also save the output and compare it with the expected output:
The last command is available on Linux and similar environments.
If I wanted a little more convenience without installing extensions, I would create a VS Code build task in
.vscode/tasks.json. ThenCtrl + Shift + Bcan compile the currently open source file. However, I wouldn't spend contest time building a complicated setup. A working terminal and a compiler command you can remember are enough.Before an onsite contest, I would verify the compiler version, the C++ standard, the build command, and the way to run programs with input files. I would also practise doing everything from a clean folder, so I wouldn't have to depend on any extension or existing configuration.
2. Testing batch/grader problems
For grader-based problems, the workflow is slightly different because the submitted file often doesn't contain
main().Suppose the problem provides these files:
Here,
grader.cppusually contains the testing code andmain(),solution.hdeclares the functions you need to implement, andsolution.cppcontains your implementation.I would first inspect the provided files and read the compilation instructions. If the package includes
compile.sh,run.sh, or a Makefile, I would try to use those rather than inventing my own commands.If the instructions say to compile the grader and solution together, the command would look something like this:
Then run the executable:
If there are additional implementation files, include them in the compilation command as well.
The important thing to understand is that you generally need to compile and link all the relevant
.cppfiles together. Compilingsolution.cppby itself may fail because it doesn't containmain(). You also normally shouldn't includesolution.cppdirectly insidegrader.cpp; compile the source files separately and let the linker connect them.I would keep the provided function signatures exactly as they are and pay attention to the header file. A small mismatch in a function's name, parameters, or return type can cause compilation errors even when the algorithm itself is correct.
For testing, I would run every sample provided with the problem. When the input and expected output are available as files, I would save the actual output and compare it against the expected output. This makes differences easier to spot.
One thing worth remembering is that a sample grader is not necessarily identical to the actual judge. It is useful for checking your implementation, function interface, and basic logic, but passing the samples alone doesn't guarantee correctness. When possible, I would also create additional test cases, especially small edge cases.
For problems where writing a brute-force solution is practical, I would generate random small inputs and compare the optimized solution against the brute-force answer. This can expose bugs that the official samples miss.
My overall approach would be to keep two simple workflows:
I wouldn't worry too much about reproducing all the convenience of CPH. The real advantage comes from being comfortable with the compiler and knowing exactly which files need to be compiled and linked. Once you understand that, switching editors becomes a pretty minor issue.