Hello, Codeforces.
This is a short blog to introduce you recent updates in Testlib and Polygon.
Testlib
Generate a Permutation
Now, you can easily generate a permutation with codes like this:
Code | Result |
---|---|
vector<int> p = rnd.perm(n); | Generates 0-indexed permutation of size n |
vector<int> p = rnd.perm(n, 1); | Generates 1-indexed permutation of size n |
Function println
Now, you can easily print space-separated lines in a generator. A println
uses cout
, thus prefer faster method if you print huge data.
Some examples:
Code | Result |
---|---|
println(5); | Print 5 and line break |
println(1, 2, 3); | Print 1 2 3 (three space separated integers) and line break |
println("one", "more", 5.5); | Print one more 5.5 (three space separated items) and line break |
vector<int> a; ...; println(a); | Print vector a (separate elements with spaces) and line break |
vector<int> a; ...; println(a.begin(), a.end()); | Exactly the same as above |
string b[5]; ...; println(b, b + 5); | Print array b (separate elements with spaces) and line break |
Here is the example of a generator to print a permutation:
#include "testlib.h"
using namespace std;
int main(int argc, char* argv[]) {
registerGen(argc, argv, 1);
int n = atoi(argv[1]);
println(n);
println(rnd.perm(n, 1));
}
Function readInts
and similar
Just as a reminder. Use functions readInts/readLongs/readStrictDoubles or readTokens/readLines in a validator to read and validate a sequence of values. To read a size of an array and array itself, use:
int n = inf.readInt(1, 200000, "n");
inf.readEoln();
inf.readInts(n, 1, 1000000, "a");
inf.readEoln();
inf.readEof();
Polygon
Example Problems
I've introduced three example problems. Each Polygon user has READ-access to them. Please, use them as examples how to write a problem in Polygon. They are:
example-a-plus-b
: simple A+B problemexample-almost-upper-bound
: simple problem to illustrate non-standard checker (always consider to usereadAnswer
function like in the example), generators and stress testsexample-interactive-binary-search
: simple interactive problem on a binary search
Other Small Fixes
- Allow to upload files (for example, images) as a contest property/file to use them in the statements.ftl. File names should start with 'statements-'.
- API has been improved to support general description, general tutorial, tags, test groups and points.
- Show problem ID on the summary box (on the righmost top block).
- Replace UTF-8 typographic characters to their ASCII equivalent (for example, replace em dash — with ---).
- Caching issue has been fixed. Previously, it could show RJ on tests even if the reason has been fixed.
Thanks to fcspartakm for implementing most features in Polygon.