feat: problem formatted.

This commit is contained in:
2026-06-01 18:54:52 -03:00
parent d931bb6422
commit edcd2211b5
58 changed files with 1817978 additions and 54 deletions

View File

@@ -12,7 +12,7 @@ for _ in range(t):
adj[v].append(u)
if 2 * da >= db:
print("Alice")
print("Delegado")
continue
def bfs(start):
@@ -38,12 +38,12 @@ for _ in range(t):
dist_from_a, furthest_from_a, _ = bfs(a)
if dist_from_a[b] <= da:
print("Alice")
print("Delegado")
continue
_, _, diameter = bfs(furthest_from_a)
if diameter <= 2 * da:
print("Alice")
print("Delegado")
else:
print("Bob")
print("Noivo")

View File

@@ -7,20 +7,59 @@ const string YES = "Delegado";
const string NO = "Noivo";
int main(int argc, char *argv[]) {
setName("%s", (YES + " or " + NO + " (case insensitive)").c_str());
setName("%s", ("multiple " + YES + "/" + NO + " (case insensitive)").c_str());
registerTestlibCmd(argc, argv);
std::string ja = upperCase(ans.readWord());
std::string pa = upperCase(ouf.readWord());
int index = 0, yesCount = 0, noCount = 0;
string pa;
while (!ans.seekEof() && !ouf.seekEof()) {
index++;
string ja = ans.readToken();
pa = ouf.readToken();
if (ja != YES && ja != NO)
quitf(_fail, "%s or %s expected in answer, but %s found", YES.c_str(), NO.c_str(), compress(ja).c_str());
if (ja != YES && ja != NO)
quitf(_fail, "%s or %s expected in answer, but %s found [%d%s token]",
YES.c_str(), NO.c_str(), compress(ja).c_str(), index, englishEnding(index).c_str());
if (pa != YES && pa != NO)
quitf(_pe, "%s or %s expected, but %s found", YES.c_str(), NO.c_str(), compress(pa).c_str());
if (pa == YES)
yesCount++;
else if (pa == NO)
noCount++;
else
quitf(_pe, "%s or %s expected, but %s found [%d%s token]",
YES.c_str(), NO.c_str(), compress(pa).c_str(), index, englishEnding(index).c_str());
if (ja != pa)
quitf(_wa, "expected %s, found %s", compress(ja).c_str(), compress(pa).c_str());
if (ja != pa)
quitf(_wa, "expected %s, found %s [%d%s token]",
compress(ja).c_str(), compress(pa).c_str(), index, englishEnding(index).c_str());
}
quitf(_ok, "answer is %s", ja.c_str());
int extraInAnsCount = 0;
while (!ans.seekEof()) {
ans.readToken();
extraInAnsCount++;
}
int extraInOufCount = 0;
while (!ouf.seekEof()) {
ouf.readToken();
extraInOufCount++;
}
if (extraInAnsCount > 0)
quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements",
index + extraInAnsCount, index);
if (extraInOufCount > 0)
quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements",
index + extraInOufCount, index);
if (index == 0)
quitf(_ok, "Empty output");
else if (index == 1)
quitf(_ok, "%s", pa.c_str());
else
quitf(_ok, "%d token(s): yes count is %d, no count is %d", index, yesCount, noCount);
quitf(_fail, "Impossible case");
}

View File

@@ -1,69 +1,108 @@
#include "testlib.h"
#include "jngen.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 0;
const int MAX_N = 100;
const int rnd_test_n = 100;
const int MIN_N = 2;
const int MAX_SUM_N = 100000;
const int MAX_N = 100000;
const int MAX_T = 10000;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
string output_tc(int x, int y) {
ostringstream oss;
oss << x << " " << y << endl;
return oss.str();
string output_tc_file(const vector<int>& ns, int type = 0) {
ostringstream oss;
int t = ns.size();
oss << t << "\n";
for (int n : ns) {
int a = rnd.next(1, n);
int b = rnd.next(1, n);
while (a == b) {
b = rnd.next(1, n);
}
int da = rnd.next(1, n - 1);
int db = rnd.next(1, n - 1);
oss << n << " " << a << " " << b << " " << da << " " << db << "\n";
Tree tree;
if (type == 0) tree = Tree::random(n);
else if (type == 1) tree = Tree::star(n);
else if (type == 2) tree = Tree::bamboo(n);
else if (type == 3) tree = Tree::caterpillar(n, max(1, rnd.next(1, n)));
else tree = Tree::random(n);
vector<pair<int, int>> edges = tree.edges();
for (auto e : edges) {
oss << e.first + 1 << " " << e.second + 1 << "\n";
}
}
return oss.str();
}
string generate_random_tc_file(int min_n, int max_n, int type) {
vector<int> ns;
int sum_n = 0;
while (ns.size() < MAX_T && sum_n + max_n <= MAX_SUM_N) {
int n = rnd.next(min_n, max_n);
ns.push_back(n);
sum_n += n;
}
return output_tc_file(ns, type);
}
string generate_manual_sample(int n, int a, int b, int da, int db, const vector<pair<int, int>>& edges) {
ostringstream oss;
oss << 1 << "\n";
oss << n << " " << a << " " << b << " " << da << " " << db << "\n";
for (auto e : edges) {
oss << e.first << " " << e.second << "\n";
}
return oss.str();
}
vector<string> generate_sample_tests() {
vector<string> tests;
tests.push_back(output_tc(1, 1));
tests.push_back(output_tc(2, 2));
tests.push_back(output_tc(0, 0));
tests.push_back(generate_manual_sample(4, 3, 2, 1, 2, {{1, 2}, {1, 3}, {1, 4}}));
tests.push_back(generate_manual_sample(6, 6, 1, 2, 5, {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc(100, 0));
tests.push_back(output_tc(0, 100));
tests.push_back(output_tc_file({10, 20}));
return tests;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
if(i<rnd_test_n / 3){
max_n = 5;
}
else if(i<rnd_test_n / 2){
max_n = 20;
}
int x = rnd.next(min_n, max_n);
int y = rnd.next(min_n, max_n);
return(output_tc(x, y));
}
vector<string> generate_random_tests() {
vector<string> tests;
for (int i = 0; i < rnd_test_n; i++){
tests.push_back(rnd_test(i));
}
return tests;
}
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_tc_file(MIN_N, 10, i % 4));
}
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_tc_file(10, 1000, i % 4));
}
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_tc_file(10000, 20000, i % 4));
}
string extreme_test_1(){
return(output_tc(100, 100));
return tests;
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(extreme_test_1());
tests.push_back(output_tc_file({MAX_N}, 0));
tests.push_back(output_tc_file({MAX_N}, 1));
tests.push_back(output_tc_file({MAX_N}, 2));
tests.push_back(output_tc_file({MAX_N}, 3));
vector<int> max_t(MAX_T, 10);
tests.push_back(output_tc_file(max_t, 0));
return tests;
}

7293
pique-pega/src/jngen.h Normal file

File diff suppressed because it is too large Load Diff