9#if __cplusplus < 201300L
10#error "carefree library need C++ 14 or higher version"
13#error "carefree library need GCC compiler or similar"
17#error "carefree library need Linux or Windows system."
19#error "carefree library don't support Linux system now.Please wait."
28#define CAREFREE_VERSION_MAJOR 0
29#define CAREFREE_VERSION_MINOR 7
30#define CAREFREE_VERSION "0.7"
42#include <ext/pb_ds/assoc_container.hpp>
43#include <ext/pb_ds/tree_policy.hpp>
45#include <initializer_list>
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wliteral-suffix"
62#if __cplusplus >= 201703L
63#define maybe_unused [[maybe_unused]]
65#define maybe_unused __attribute__((unused))
68constexpr unsigned long long operator"" B(
unsigned long long x) {
return x; }
70constexpr unsigned long long operator"" KiB(
unsigned long long x) {
return x * 1024; }
72constexpr unsigned long long operator"" MiB(
unsigned long long x) {
return x * 1024 * 1024; }
74constexpr unsigned long long operator"" GiB(
unsigned long long x) {
return x * 1024 * 1024 * 1024; }
76constexpr unsigned long long operator"" TiB(
unsigned long long x) {
return x * 1024 * 1024 * 1024 * 1024; }
78constexpr unsigned long long operator"" NS(
unsigned long long x) {
return x; }
80constexpr unsigned long long operator"" MS(
unsigned long long x) {
return x * 1000 * 1000; }
82constexpr unsigned long long operator"" S(
unsigned long long x) {
return x * 1000 * 1000 * 1000; }
84constexpr unsigned long long operator"" MIN(
unsigned long long x) {
return x * 1000 * 1000 * 1000 * 60; }
91 virtual string name() {
return "carefree_exception"; }
94 template <
class cpp_err_type,
class err_name = carefree_exception_name>
109 cls_name = err_name().name();
120 string name() {
return "carefree_invalid_argument"; }
124 string name() {
return "carefree_range_exception"; }
128 string name() {
return "carefree_unsupported_operation"; }
132 string name() {
return "carefree_file_exception"; }
136 string name() {
return "carefree_runtime_exception"; }
140 string name() {
return "carefree_system_exception"; }
144 string name() {
return "carefree_validate_failed"; }
155 virtual const
char*
what() const noexcept {
return msg.c_str(); };
223 template <
class T1,
class T2>
230 std::fprintf(stderr,
"CareFree Library : An Error Occured.\n%s\n", err.
what().c_str());
233 std::fprintf(stderr,
"CareFree Library : An Error Occured.\n%s\n", err.
what().c_str());
237 std::fprintf(stderr,
"CareFree Library : An Error Occured.\n%s\n", err.
what().c_str());
241 __builtin_unreachable();
249 string errmsg = func_name +
" : " +
"l(" + std::to_string(l) +
") > r(" + std::to_string(r) +
").";
255 string errmsg = func_name +
" : " + var_name +
" is empty.";
261 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not positive.";
267 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not natural.";
273 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not in range [" + std::to_string(l) +
", " + std::to_string(r) +
"].";
279 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not less than " + std::to_string(l) +
".";
285 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not greater than " + std::to_string(l) +
".";
291 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not less than or equal to " + std::to_string(l) +
".";
297 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not greater than or equal to " + std::to_string(l) +
".";
303 string errmsg = func_name +
" :" + var_name +
"(" + std::to_string(x) +
") is not equal to " + std::to_string(l) +
".";
309 string errmsg = func_name +
" : " + var_name +
"(" + std::to_string(x) +
") is not unequal to " + std::to_string(l) +
".";
320 template <
class T1,
class T2>
322 return string(a) + string(b);
326 string __fts(T val,
unsigned precision = 10) {
327 static char buffer[255], buffer2[2047];
328 if (std::is_same<T, float>::value)
329 sprintf(buffer,
"%%.%df", precision);
330 else if (std::is_same<T, double>::value)
331 sprintf(buffer,
"%%.%dlf", precision);
332 else if (std::is_same<T, long double>::value)
333 sprintf(buffer,
"%%.%dlf", precision);
335 const std::type_info& x =
typeid(T);
338 sprintf(buffer2, buffer, val);
343 string fts(
float val,
unsigned precision = 10) {
344 return __fts(val, precision);
347 string fts(
double val,
unsigned precision = 10) {
348 return __fts(val, precision);
351 string fts(
long double val,
unsigned precision = 10) {
352 return __fts(val, precision);
356 std::vector<string>
fts(std::vector<T> val,
unsigned precision = 10) {
357 std::vector<string> ans;
358 for (
auto it = val.begin(); it != val.end(); ++it) {
359 ans.push_back(
fts(*it, precision));
365 std::vector<T>
ltv(std::initializer_list<T> val) {
366 return std::vector<T>(val);
398 template <
class T,
class Value>
400 std::vector<Value> data;
402 for (
int i = 1; i <= n; i++) {
403 data.push_back(function(i));
410 static_assert(std::is_integral<T>::value || std::is_floating_point<T>::value,
"T must be integral or floating point");
412 if (std::is_integral<T>::value)
420 std::vector<T>
sequence(
int lengthL,
int lengthR, T l, T r) {
421 static_assert(std::is_integral<T>::value || std::is_floating_point<T>::value,
"T must be integral or floating point");
423 if (std::is_integral<T>::value)
431 const string lower =
"abcdefghijklmnopqrstuvwxyz";
432 const string upper =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
452 for (
int i = 0; i < length; i++) str +=
choice(sset);
462 auto start = std::chrono::system_clock::now();
464 auto end = std::chrono::system_clock::now();
465 return (
double)std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
469 void gen_data(
int subtask_count,
int task_per_subtask, T function) {
472 int total_tasks = subtask_count * task_per_subtask;
473 int current_task = 0;
477 for (
int k = 0; k < barWidth; ++k) {
480 std::cout <<
"] " << 0 <<
"% ";
481 std::cout <<
"#-# N/A it / s\r";
482 for (
int i = 1; i <= subtask_count; i++) {
483 for (
int j = 1; j <= task_per_subtask; j++) {
484 double time_ =
timer([&]() {
489 float progress =
static_cast<float>(current_task) / total_tasks;
490 int pos =
static_cast<int>(barWidth * progress);
492 for (
int k = 0; k < barWidth; ++k) {
500 std::cout <<
"] " << int(progress * 100.0) <<
"% ";
501 std::cout << i <<
"-" << j <<
" ";
502 std::cout <<
fts(average / current_task, 2) <<
" it / s";
507 std::cout << std::endl;
513 int total_tasks = task_count;
514 int current_task = 0;
518 for (
int k = 0; k < barWidth; ++k) {
521 std::cout <<
"] " << 0 <<
"% ";
522 std::cout <<
"# N/A it / s\r";
523 for (
int i = 1; i <= task_count; i++) {
524 double time_ =
timer([&]() {
529 float progress =
static_cast<float>(current_task) / total_tasks;
530 int pos =
static_cast<int>(barWidth * progress);
532 for (
int k = 0; k < barWidth; ++k) {
540 std::cout <<
"] " << int(progress * 100.0) <<
"% ";
541 std::cout << i <<
" ";
542 std::cout <<
fts(average / current_task, 2) <<
" it / s";
546 std::cout << std::endl;
553 template <
class T,
class Compare = std::less<T>>
556 __gnu_pbds::tree<T, __gnu_pbds::null_type, Compare, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> tree;
561 bool erase(T x) {
return tree.erase(x); }
563 int rnk(T x) {
return tree.order_of_key(x) + 1; }
565 T
kth(
int x) {
return *tree.find_by_order(x - 1); }
567 int size() {
return tree.size(); }
569 bool empty() {
return tree.empty(); }
579 edge(
int from,
int to,
_Weight weight = 0) : from(from), to(to), weight(weight) {}
584 return std::to_string(edg.
from) +
" " + std::to_string(edg.
to) +
" " + std::to_string(edg.
weight);
590 return std::to_string(edg.
from) +
" " + std::to_string(edg.
to);
599 chain_node(
int nxt,
int to, _Weight w) : nxt(nxt), to(to), w(w) {}
601 std::vector<chain_node> chain;
602 std::vector<int> head;
603 std::vector<std::map<int, bool>> edge_map;
604 std::vector<edge> edge_vct;
613 graph(
int N,
bool directed =
false,
bool enable_edge_map =
true) {
616 this->directed = directed;
617 this->enable_edge_map = enable_edge_map;
618 head = std::vector<int>(N + 1, -1);
619 edge_map = std::vector<std::map<int, bool>>(N + 1);
622 void add(
edge edg,
bool __add_vector =
true) {
625 chain.push_back(chain_node(head[edg.
from], edg.
to, edg.
weight));
626 head[edg.
from] = chain.size() - 1;
627 if (!directed && __add_vector) add(
edge(edg.
to, edg.
from, edg.
weight),
false);
628 if (__add_vector) edge_vct.push_back(edg);
629 if (enable_edge_map) edge_map[edg.
from][edg.
to] =
true;
633 add(
edge(from, to, weight));
638 return edge_map[edg.
from][edg.
to];
642 return has_edge(
edge(from, to));
651 std::vector<edge> edges;
652 for (
int i = head[from]; ~i; i = chain[i].nxt) edges.push_back(
edge(from, chain[i].to, chain[i].w));
656 template <
class T = weighted_output>
658 std::vector<edge> edges = get_edges();
661 for (
auto it = edges.begin(); it != edges.end(); ++it) {
663 if ((it + 1) != edges.end()) str +=
'\n';
676 std::vector<int> fa(g.
N + 1);
677 for (
int i = 1; i <= g.
N; i++) fa[i] = i;
679 if (edges.size() != (
unsigned)(g.
N - 1))
return false;
680 std::function<int(
int)> find = [&](
int x) {
681 return fa[x] == x ? x : fa[x] = find(fa[x]);
683 for (
auto i : edges) {
684 int u = i.from, v = i.to;
685 if (find(u) == find(v))
return false;
686 fa[find(u)] = find(v);
692 std::vector<int> perm;
693 for (
int i = 1; i <= g.
N; i++) perm.push_back(i);
697 new_.
add(perm[i.from - 1], perm[i.to - 1], i.weight);
703 std::vector<int> deg(n + 1, 1);
704 prufer.insert(prufer.begin(), 0);
707 for (
int i = 1; i <= (n - 2); i++) {
710 for (
int i = 1; i <= (n - 2); i++) deg[prufer[i]]++;
711 int ptr = 1, leaf = 0;
712 while (deg[ptr] != 1) ptr++;
714 for (
int i = 1; i <= (n - 2); i++) {
717 if (--deg[v] == 1 && v < ptr)
721 while (deg[ptr] != 1) ptr++;
731 std::vector<int> depth(g.
N + 1);
739 depth[i.to] = depth[u] + 1;
751 int u = i.from, v = i.to;
753 if (depth[u] < depth[v]) std::swap(u, v);
763 int u = i.from, v = i.to;
765 if (depth[u] > depth[v]) std::swap(u, v);
773 for (
int i = 2; i <= n; i++) {
774 int fa =
randint(std::max((
int)((i - 1) * low), 1), std::min((
int)((i - 1) * high), i - 1));
781 return lowhigh(n, 0, 1, weightL, weightR);
786 for (
int i = 2; i <= n; i++) {
787 int fa =
randint(std::max(i - k, 1), i - 1);
794 return tail(n, 1, weightL, weightR);
799 for (
int i = 2; i <= n; i++) {
806 return star(n, weightL, weightR);
813 for (
int i = 2; i <= n; i++) {
816 if (fa.second < k) tree.
insert({fa.first, fa.second + 1});
817 g.
add(fa.first, i, randint(weightL, weightR));
829 for (
int i = 2; i <= k; i++) g.
add(i - 1, i, randint(weightL, weightR));
830 for (
int i = k + 1; i <= n; i++) g.
add(randint(1, k), i,
randint(weightL, weightR));
836 for (
int i = 2; i <= (n >> 1); i++) g.
add(i - 1, i, randint(weightL, weightR));
837 for (
int i = (n >> 1) + 1; i <= (n >> 1) << 1; i++) g.
add(i - (n >> 1), i,
randint(weightL, weightR));
838 if (((n >> 1) << 1) != n) g.
add(randint(1, n - 1), n,
randint(weightL, weightR));
845 for (
int i = 2; i <= tmp; i++) g.
add(i - 1, i, randint(weightL, weightR));
846 for (
int i = tmp + 1; i <= tmp * 2; i++) g.
add(i - tmp, i, randint(weightL, weightR));
847 for (
int i = (tmp << 1) + 1; i <= tmp * 3; i++) g.
add(i - (tmp << 1), i, randint(weightL, weightR));
848 for (
int i = (tmp * 3 + 1); i <= n; i++) g.
add(randint(1, i - 1), i,
randint(weightL, weightR));
860 int bound = std::min(tot + k - 1, n);
861 for (
int i = tot + 1; i <= bound; i++) {
870 return complete(n, 3, weightL, weightR);
875 std::vector<int> prufer;
876 for (
int i = 1; i <= n - 2; i++) prufer.push_back(randint(1, n));
885 for (
int i = n; i <= m; i++) {
889 if (u == v)
continue;
890 if (depth[u] > depth[v]) std::swap(u, v);
891 if (!repeat_edges && ret.
has_edge(u, v))
continue;
903 for (
int i = n; i <= m; i++) {
907 if (!self_loop && u == v)
continue;
908 if (!repeat_edges && ret.
has_edge(u, v))
continue;
920 for (
int i = n; i <= m; i++) {
924 if (!self_loop && u == v)
continue;
925 if (!repeat_edges && ret.
has_edge(u, v))
continue;
934 graph ret(n, directed);
935 for (
int i = 1; i <= m; i++) {
939 if (!self_loop && u == v)
continue;
940 if (!repeat_edges && ret.
has_edge(u, v))
continue;
960 file_writer(
const char* filename) {
961 _filename = filename;
962 if (std::strlen(filename)) {
963 fp = std::fopen(filename,
"w");
964 if (fp == NULL) raise(
carefree_file_exception(
"testcase_writer::file_writer::file_writer : cannot open file " + _filename));
969 if (fp !=
nullptr) std::fclose(fp);
971 ~file_writer() { close(); }
972 void writeChar(
char val) {
977 void writeInteger(T val) {
987 if (val >= 10) writeInteger(val / 10);
988 writeChar(
'0' + val % 10);
990 void writeString(
const char* val) {
992 const char* ptr = val;
993 while (*ptr !=
'\0') writeChar(*(ptr++));
995 void writeString(
string val) {
997 writeString(val.c_str());
1012 void lock() { locked =
true; }
1016 fin =
new file_writer(input_file.c_str());
1017 fout =
new file_writer(output_file.c_str());
1021 testcase_writer(
string file_prefix,
unsigned data_id,
string input_suffix =
".in",
string output_suffix =
".out",
bool disable_output =
false) {
1022 fin =
new file_writer((file_prefix + std::to_string(data_id) + input_suffix).c_str());
1023 if (!disable_output)
1024 fout =
new file_writer((file_prefix + std::to_string(data_id) + output_suffix).c_str());
1026 fout =
new file_writer(
"");
1030 testcase_writer(
string file_prefix,
unsigned subtask_id,
unsigned task_id,
string input_suffix =
".in",
string output_suffix =
".out",
bool disable_output =
false) {
1031 fin =
new file_writer((file_prefix + std::to_string(subtask_id) +
"-" + std::to_string(task_id) + input_suffix).c_str());
1032 if (!disable_output)
1033 fout =
new file_writer((file_prefix + std::to_string(subtask_id) +
"-" + std::to_string(task_id) + output_suffix).c_str());
1035 fout =
new file_writer(
"");
1041 fin->writeChar(val);
1045 fout->writeChar(val);
1050 fin->writeInteger(val);
1054 fout->writeInteger(val);
1059 fout->writeInteger(val);
1063 fin->writeInteger(val);
1068 fin->writeInteger(val);
1072 fout->writeInteger(val);
1077 fin->writeInteger(val);
1081 fout->writeInteger(val);
1086 fin->writeInteger(val);
1090 fout->writeInteger(val);
1095 fin->writeInteger(val);
1099 fout->writeInteger(val);
1102#ifdef CAREFREE_INT128_SUPPORT
1105 fin->writeInteger(val);
1109 fout->writeInteger(val);
1114 fin->writeInteger(val);
1118 fout->writeInteger(val);
1123 fin->writeString(val);
1127 fout->writeString(val);
1132 fin->writeString(val);
1136 fout->writeString(val);
1141 fin->writeString(val ?
"true" :
"false");
1145 fout->writeString(val ?
"true" :
"false");
1151 for (
auto it = val.begin(); it != val.end(); ++it) {
1153 if ((it + 1) != val.end()) input_write(
' ');
1159 for (
auto it = val.begin(); it != val.end(); ++it) {
1161 if ((it + 1) != val.end()) output_write(
' ');
1183 template <
class T,
typename... Args>
1188 input_write(args...);
1191 template <
class T,
typename... Args>
1196 output_write(args...);
1216 template <
class T,
typename... Args>
1221 input_writeln(args...);
1224 template <
class T,
typename... Args>
1229 output_writeln(args...);
1242 int stdin_ = dup(fileno(stdin));
1243 freopen(fin->_filename.c_str(),
"r", stdin);
1244 int stdout_ = dup(fileno(stdout));
1245 freopen(fout->_filename.c_str(),
"w", stdout);
1246 int returnid = std::system(program.c_str());
1247 if (returnid != 0) raise(
carefree_runtime_exception(
"testcase_writer::output_gen : program exited with non-zero return code"));
1248 dup2(stdin_, fileno(stdin));
1249 dup2(stdout_, fileno(stdout));
1253 return fin->_filename;
1257 return fout->_filename;
1268 if (fin !=
nullptr)
delete fin;
1269 if (fout !=
nullptr)
delete fout;
1273 using testcase_io [[deprecated(
"use testcase_writer instead.")]] = testcase_writer;
1284 void add(
string input_name,
int time_limit,
int memory_limit,
int score = -1,
int subtask_id = -1) {
1285 const string space =
" ";
1286 string current =
"";
1287 current += (input_name +
":\n");
1288 current += (space +
"timeLimit: " + std::to_string(time_limit) +
"\n");
1289 current += (space +
"memoryLimit: " + std::to_string(memory_limit) +
"\n");
1290 if (score != -1) current += (space +
"score: " + std::to_string(score) +
"\n");
1291 if (subtask_id != -1) current += (space +
"subtaskId: " + std::to_string(subtask_id) +
"\n");
1296 void save(
string filename =
"config.yml") {
1297 FILE* fobj = fopen(filename.c_str(),
"w");
1298 if (fobj == NULL) raise(
carefree_file_exception(
"luogu_testcase_config_writer::save : failed to open file " + filename));
1299 fputs(content.c_str(), fobj);
1300 if (fclose(fobj) != 0) raise(
carefree_file_exception(
"luogu_testcase_config_writer::save : failed to close file " + filename));
1321 string command_, input_file_, output_file_;
1322 HANDLE process_handle_ =
nullptr, hOutputFile =
nullptr, hInputFile =
nullptr;
1325 process_win(
const string& cmd,
const string& input =
"",
const string& output =
"")
1326 : command_(cmd), input_file_(input), output_file_(output) {
1328 PROCESS_INFORMATION pi;
1329 ZeroMemory(&si,
sizeof(si));
1331 ZeroMemory(&pi,
sizeof(pi));
1332 if (!input_file_.empty()) {
1333 SECURITY_ATTRIBUTES saAttr;
1334 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
1335 saAttr.bInheritHandle = TRUE;
1336 saAttr.lpSecurityDescriptor = NULL;
1337 hInputFile = CreateFileA(input_file_.c_str(), GENERIC_READ, 0, &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1338 if (hInputFile == INVALID_HANDLE_VALUE) {
1341 si.hStdInput = hInputFile;
1343 if (!output_file_.empty()) {
1344 SECURITY_ATTRIBUTES saAttr;
1345 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
1346 saAttr.bInheritHandle = TRUE;
1347 saAttr.lpSecurityDescriptor = NULL;
1348 hOutputFile = CreateFileA(output_file_.c_str(), GENERIC_WRITE, 0, &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1349 if (hOutputFile == INVALID_HANDLE_VALUE) {
1352 si.hStdOutput = hOutputFile;
1353 si.hStdError = NULL;
1354 si.dwFlags |= STARTF_USESTDHANDLES;
1356 if (!CreateProcessA(NULL, (
char*)(command_.c_str()), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
1359 CloseHandle(pi.hThread);
1360 process_handle_ = pi.hProcess;
1364 if (process_handle_ !=
nullptr) {
1365 CloseHandle(process_handle_);
1367 if (hInputFile !=
nullptr) CloseHandle(hInputFile);
1368 if (hOutputFile !=
nullptr) {
1369 FlushFileBuffers(hOutputFile);
1370 CloseHandle(hOutputFile);
1380 TerminateProcess(process_handle_, 1);
1385 if (GetExitCodeProcess(process_handle_, &exit_code) && exit_code == STILL_ACTIVE) {
1393 if (!GetExitCodeProcess(process_handle_, &exit_code) || exit_code == STILL_ACTIVE) {
1396 return static_cast<int>(exit_code);
1400 return (
int)GetProcessId(process_handle_);
1405 PROCESS_MEMORY_COUNTERS_EX pmc;
1406 ZeroMemory(&pmc,
sizeof(pmc));
1407 pmc.cb =
sizeof(pmc);
1408 if (!GetProcessMemoryInfo(process_handle_, (PROCESS_MEMORY_COUNTERS*)&pmc,
sizeof(pmc))) {
1412 return (
size_t)pmc.PrivateUsage;
1441 return "Wrong Answer";
1443 return "Time Limit Exceeded";
1445 return "Memory Limit Exceeded";
1447 return "Runtime Error";
1449 return "Compile Error";
1451 return "Presentation Error";
1453 return "Output Limit Exceeded";
1455 return "Unknown Error";
1457 return "Judge Failed";
1459 return "Partially Correct";
1463 return "Unknown Error";
1465 return "Unknown Error";
1500 using ull =
unsigned long long;
1510 string ret = jrt2s(type) +
"\t" + message +
"\t";
1511 ret += std::to_string(time / 1000.0 / 1000.0) +
"ms\t";
1512 ret += std::to_string(memory / 1024.0 / 1024.0) +
"MiB\t";
1513 ret += std::to_string(ratio * 100) +
"%";
1518 std::vector<string>
__split(
const string& str,
string delims) {
1519 std::vector<string> tokens;
1521 for (
auto it = str.begin(); it != str.end(); ++it) {
1522 if (delims.find(*it) != string::npos) {
1523 tokens.push_back(tmp);
1529 tokens.push_back(tmp);
1545 file(
const string& filename) : filename_(filename) {}
1547 std::ifstream
file(filename_, std::ios::in);
1548 if (!
file.is_open()) {
1550 file.open(filename_, std::ios::in);
1554 while (
file.good()) {
1556 std::getline(
file, line);
1557 content += line +
'\n';
1569 text(
const string& content) : content_(content) {}
1576 return from_text(
file(filename1).read(),
file(filename2).read());
1579 template <
class T1,
class T2>
1581 return from_text(a.read(), b.read());
1585 return from_file(answer_path, output_path);
1596 if (text1 == text2) {
1606 auto lines1 =
__split(text1,
"\n");
1607 auto lines2 =
__split(text2,
"\n");
1608 if (lines1.size() != lines2.size()) {
1609 string errmsg =
"expected " + std::to_string(lines1.size()) +
" line(s), but got " + std::to_string(lines2.size()) +
" line(s).";
1612 for (
ull i = 0; i < lines1.size(); ++i) {
1613 if (lines1[i] != lines2[i]) {
1614 string errmsg =
"at line " + std::to_string(i + 1);
1615 errmsg +=
", expected \"" + lines1[i] +
"\"";
1616 errmsg +=
", but got \"" + lines2[i] +
"\".";
1627 auto tokens1_ =
__split(text1,
" \t\r\n");
1628 auto tokens2_ =
__split(text2,
" \t\r\n");
1629 std::vector<string> tokens1, tokens2;
1630 std::copy_if(tokens1_.begin(), tokens1_.end(), std::back_inserter(tokens1), [](
const string& s) { return s !=
""; });
1631 std::copy_if(tokens2_.begin(), tokens2_.end(), std::back_inserter(tokens2), [](
const string& s) { return s !=
""; });
1632 if (tokens1.size() != tokens2.size()) {
1633 string errmsg =
"expected " + std::to_string(tokens1.size()) +
" token(s), but got " + std::to_string(tokens2.size()) +
" token(s).";
1636 for (
ull i = 0; i < tokens1.size(); ++i) {
1637 if (tokens1[i] != tokens2[i]) {
1638 string errmsg =
"at token " + std::to_string(i + 1);
1639 errmsg +=
", expected \"" + tokens1[i] +
"\"";
1640 errmsg +=
", but got \"" + tokens2[i] +
"\".";
1654 std::stringstream ss;
1655 ss << std::quoted(s);
1661 string testlib_path;
1663 string extract_outcome(
string xml) {
1664 size_t start_pos = xml.find(
"outcome = \"");
1665 if (start_pos == string::npos)
return "";
1667 size_t end_pos = xml.find(
"\"", start_pos);
1668 if (end_pos == string::npos)
return "";
1669 return xml.substr(start_pos, end_pos - start_pos);
1672 string extract_points(
string xml) {
1673 size_t start_pos = xml.find(
"points = \"");
1674 if (start_pos == string::npos)
return "";
1676 size_t end_pos = xml.find(
"\"", start_pos);
1677 if (end_pos == string::npos)
return "";
1678 return xml.substr(start_pos, end_pos - start_pos);
1681 string extract_result(
string xml) {
1682 size_t start_pos = xml.find(
"\">") + 2;
1683 if (start_pos == string::npos)
return "";
1684 size_t end_pos = xml.rfind(
"</result>");
1685 if (end_pos == string::npos)
return "";
1686 return xml.substr(start_pos, end_pos - start_pos);
1691 this->testlib_path = testlib_path;
1695 string cmd = testlib_path +
" ";
1696 cmd += quote(input_path) +
" " + quote(output_path) +
" " + quote(answer_path);
1698 string xml_path =
"carefree_testlib_report_" + std::to_string(nextid()) +
".xml";
1699 cmd += quote(xml_path) +
" -appes";
1700 int ret = system(cmd.c_str());
1701 string content =
file(xml_path).
read();
1702 std::remove(xml_path.c_str());
1703 string outcome = extract_outcome(content);
1704 string message = extract_result(content);
1705 if (outcome.empty())
return {
UnknownError,
"cannot parse report file.", 0.0, 0
ull, 0
ull};
1706 if (outcome ==
"accepted")
1708 else if (outcome ==
"wrong-answer")
1710 else if (outcome ==
"presentation-error")
1712 else if (outcome ==
"points") {
1713 string points = extract_points(content);
1714 if (points.empty())
return {
UnknownError,
"cannot parse report file.", 0.0, 0
ull, 0
ull};
1731 limprog(
string program,
ull time,
ull memory) : program(program), time(time), memory(memory) {}
1735 auto start = std::chrono::system_clock::now();
1736 ull memory = 0, tim = 0;
1739 auto now = std::chrono::system_clock::now();
1740 tim = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start).count();
1741 if (tim > prog.
time) {
1745 memory = std::max(memory, proc.
memory());
1746 if (memory > prog.
memory) {
1752 return {
RuntimeError,
"program finished with exit non-zero code " + std::to_string(proc.
return_code()) +
".", 0.0, tim, memory};
1754 return {
Accepted,
"program finished successfully.", 1.0, tim, memory};
1758 if (access(filename.c_str(), F_OK) != -1)
return false;
1759 std::ofstream f(filename, std::ios::out);
1762 std::remove(filename.c_str());
1772 output_file =
"carefree_output_" + std::to_string(
nextid()) +
".out";
1776 std::remove(output_file.c_str());
1780 struct stat output_stat {};
1781 stat(output_file.c_str(), &output_stat);
1782 struct stat answer_stat {};
1783 stat(answer_file.c_str(), &answer_stat);
1784 if (output_stat.st_size > answer_stat.st_size * 10) {
1785 std::remove(output_file.c_str());
1789 judge_result ans2 = cmp.test(input_file, output_file, answer_file);
1790 std::remove(output_file.c_str());
1794 template <
class T1,
class T2>
1795 bool combat(
limprog champion,
limprog challenger, T1 input_generator, T2 cmp,
int times = -1,
bool ole_check =
true) {
1796 for (
int i = 0; i != times; i++) {
1797 fprintf(stderr,
"Round #%d : ", i + 1);
1798 string input_file =
"";
1800 input_file =
"carefree_input_" + std::to_string(
nextid()) +
".in";
1803 input_generator(writer);
1806 answer_file =
"carefree_answer_" + std::to_string(
nextid()) +
".ans";
1808 auto ret =
limited_run(champion, input_file, answer_file);
1810 fprintf(stderr,
"champion is lost.\n");
1811 fprintf(stderr,
"%s\n", ret.to_str().c_str());
1812 fprintf(stderr,
"please watch input file \"%s\" to check.", input_file.c_str());
1815 ret =
judge(challenger, input_file, answer_file, cmp, ole_check = ole_check);
1817 fprintf(stderr,
"challenger is lost.\n");
1818 fprintf(stderr,
"%s\n", ret.to_str().c_str());
1819 fprintf(stderr,
"please watch input file \"%s\" to check.", input_file.c_str());
1822 std::remove(answer_file.c_str());
1823 std::remove(input_file.c_str());
1824 fprintf(stderr,
"champion and challenger are still alive.\n");
1829 void listdir(
string path, std::vector<string>& files) {
1831 _finddata_t fileinfo;
1832 if ((hFile = _findfirst(path.append(
"/*").c_str(), &fileinfo)) != -1) {
1833 while (_findnext(hFile, &fileinfo) == 0) {
1834 if (strcmp(fileinfo.name,
".."))
1835 files.push_back(fileinfo.name);
1842 return getcwd(NULL, 0);
1846 std::vector<string> files;
1849 for (
auto& i : files) {
1850 if (i.find(
"carefree_input_") == 0 ||
1851 i.find(
"carefree_output_") == 0 ||
1852 i.find(
"carefree_answer_") == 0 ||
1853 i.find(
"carefree_testlib_report_") == 0) {
1854 std::remove(i.c_str());
1890 string gcc_path =
"g++";
1896 bool link_static =
false, debug =
false;
1897 std::vector<string> include_files, include_dirs, link_libs;
1898 std::map<string, string> defintions;
1901 gcc_compile(
string filename,
string output_name) : filename(filename), output_name(output_name) {};
1904 this->gcc_path = gcc_path;
1919 this->warning = warning;
1924 this->warning |= warning;
1929 this->link_static = link_static;
1934 this->include_files.push_back(filename);
1939 this->defintions[key] = value;
1944 this->include_dirs.push_back(dir);
1949 this->link_libs.push_back(lib);
1954 this->debug = debug;
1959 string cmd = gcc_path +
" " + quote(filename);
1981 cmd +=
" -std=c++98";
1984 cmd +=
" -std=c++03";
1987 cmd +=
" -std=c++11";
1990 cmd +=
" -std=c++14";
1993 cmd +=
" -std=c++17";
1996 cmd +=
" -std=c++20";
2010 cmd +=
" -pedantic";
2017 for (
auto& i : include_files) {
2018 cmd +=
" -include " + i;
2021 for (
auto& i : include_dirs) {
2025 for (
auto& i : defintions) {
2026 if (i.second.empty())
2027 cmd +=
" -D" + i.first;
2029 cmd +=
" -D" + i.first +
"=" + i.second;
2032 for (
auto& i : link_libs) {
2040 cmd +=
" -o " + quote(output_name);
2046 return std::system(this->command().c_str()) == 0 ? judge_result_type::Accepted : judge_result_type::CompileError;
2091 const string product_name_art =
" .o88b. .d8b. d8888b. d88888b d88888b d8888b. d88888b d88888b \nd8P Y8 d8' `8b 88 `8D 88' 88' 88 `8D 88' 88' \n8P 88ooo88 88oobY' 88ooooo 88ooo 88oobY' 88ooooo 88ooooo \n8b 88~~~88 88`8b 88~~~~~ 88~~~ 88`8b 88~~~~~ 88~~~~~ \nY8b d8 88 88 88 `88. 88. 88 88 `88. 88. 88. \n `Y88P' YP YP 88 YD Y88888P YP 88 YD Y88888P Y88888P \n \n \n";
2092 std::cout << (
"Hello World! -- The greeting from Carefree " + version_str +
"\n\n");
2093 std::cout << product_name_art <<
'\n';
2094 std::cout <<
"For more information, please visit : https://github.com/xiezheyuan/carefree/\n";
2095 std::cout <<
"Do you want me to help you open this URL? (y | others): ";
2098 if (prompt ==
"y" || prompt ==
"Y") {
2099 std::system(
"start http://github.com/xiezheyuan/carefree/");
2106 std::function<bool(T)> val;
2115 return condition<T>([a, b](T v) {
return a(v) || b(v); });
2120 return condition<T>([a, b](T v) {
return a(v) && b(v); });
2191 std::map<char, bool> m;
2192 for (
size_t i = 0; i < s.length(); i++) {
2195 for (
size_t i = 0; i < x.length(); i++) {
2206 template <
class T =
int>
2211 template <
class T =
int>
2216 template <
class T =
int>
2221 template <
class T =
int>
2224 template <
class T =
int>
2227 template <
class T =
int>
2230 template <
class T =
int>
2233 template <
class T =
int>
2236 template <
class T =
int>
2239 template <
class T =
int>
2242 for (
size_t i = 0; i < v.size() - 1; i++) {
2243 if (v[i] < v[i + 1]) {
2251 template <
class T =
int>
2254 for (
size_t i = 0; i < v.size() - 1; i++) {
2255 if (v[i] > v[i + 1]) {
2343 using carefree_internal::testcase_io;
2361#pragma GCC diagnostic pop
#define maybe_unused
Definition carefree.hpp:65
#define CAREFREE_VERSION
Definition carefree.hpp:30
Definition carefree.hpp:147
string msg
Definition carefree.hpp:149
virtual const char * what() const noexcept
Definition carefree.hpp:155
_base_exception(const char *__arg)
Definition carefree.hpp:153
_base_exception(const string &__arg)
Definition carefree.hpp:152
virtual ~_base_exception() noexcept=default
Definition carefree.hpp:165
virtual ~_file_exception() noexcept=default
_file_exception(const char *__arg)
Definition carefree.hpp:168
_file_exception(const string &__arg)
Definition carefree.hpp:167
Definition carefree.hpp:172
_system_exception(const char *__arg)
Definition carefree.hpp:175
_system_exception(const string &__arg)
Definition carefree.hpp:174
virtual ~_system_exception() noexcept=default
Definition carefree.hpp:158
_unsupported_operation(const char *__arg)
Definition carefree.hpp:161
virtual ~_unsupported_operation() noexcept=default
_unsupported_operation(const string &__arg)
Definition carefree.hpp:160
Definition carefree.hpp:179
_validate_failed(const string &__arg)
Definition carefree.hpp:181
virtual ~_validate_failed() noexcept=default
_validate_failed(const char *__arg)
Definition carefree.hpp:182
Definition carefree.hpp:554
bool erase(T x)
Definition carefree.hpp:561
bool empty()
Definition carefree.hpp:569
int rnk(T x)
Definition carefree.hpp:563
void insert(T x)
Definition carefree.hpp:559
T kth(int x)
Definition carefree.hpp:565
int size()
Definition carefree.hpp:567
Definition carefree.hpp:95
string what()
Definition carefree.hpp:112
cpp_err_type get_err()
Definition carefree.hpp:114
carefree_exception(const char *msg)
Definition carefree.hpp:107
carefree_exception(string msg)
Definition carefree.hpp:105
carefree_exception()
Definition carefree.hpp:103
cpp_err_type err_type
Definition carefree.hpp:101
string get_msg()
Definition carefree.hpp:116
Definition carefree.hpp:1540
file(const string &filename)
Definition carefree.hpp:1545
string read()
Definition carefree.hpp:1546
Definition carefree.hpp:1535
Definition carefree.hpp:1564
string read()
Definition carefree.hpp:1570
text(const string &content)
Definition carefree.hpp:1569
Definition carefree.hpp:1533
virtual judge_result test(const string &input_path __attribute__((unused)), const string &output_path, const string &answer_path)
Definition carefree.hpp:1584
virtual judge_result from_text(const string &text1, const string &text2)=0
judge_result operator()(T1 a, T2 b)
Definition carefree.hpp:1580
virtual judge_result from_file(const string &filename1, const string &filename2)
Definition carefree.hpp:1575
Definition carefree.hpp:2104
condition(std::function< bool(T)> x)
Definition carefree.hpp:2109
bool operator()(T x) const
Definition carefree.hpp:2110
Definition carefree.hpp:1888
gcc_compile & include_file(string filename)
Definition carefree.hpp:1933
gcc_compile & debug_mode(bool debug=true)
Definition carefree.hpp:1953
gcc_compile(string filename, string output_name)
Definition carefree.hpp:1901
judge_result_type start()
Definition carefree.hpp:2045
gcc_compile & warning_level(cpp_warnings::type warning)
Definition carefree.hpp:1918
gcc_compile & add_warning(cpp_warnings::type warning)
Definition carefree.hpp:1923
string command()
Definition carefree.hpp:1958
gcc_compile & linking_static(bool link_static=true)
Definition carefree.hpp:1928
gcc_compile & include_dir(string dir)
Definition carefree.hpp:1943
gcc_compile & link(string lib)
Definition carefree.hpp:1948
gcc_compile & define(string key, string value="")
Definition carefree.hpp:1938
gcc_compile & cpp_version(cpp_version cpp)
Definition carefree.hpp:1913
gcc_compile & optimization(optimization_type opti)
Definition carefree.hpp:1908
gcc_compile & gcc(string gcc_path)
Definition carefree.hpp:1903
Definition carefree.hpp:574
int N
Definition carefree.hpp:607
bool has_edge(edge edg)
Definition carefree.hpp:636
bool directed
Definition carefree.hpp:609
std::vector< edge > get_edges(int from)
Definition carefree.hpp:649
void add(int from, int to, _Weight weight=0)
Definition carefree.hpp:632
string to_string(bool shuffle=false)
Definition carefree.hpp:657
bool enable_edge_map
Definition carefree.hpp:611
void add(edge edg, bool __add_vector=true)
Definition carefree.hpp:622
std::vector< edge > get_edges()
Definition carefree.hpp:645
bool has_edge(int from, int to)
Definition carefree.hpp:641
graph(int N, bool directed=false, bool enable_edge_map=true)
Definition carefree.hpp:613
Definition carefree.hpp:1275
luogu_testcase_config_writer()
Definition carefree.hpp:1280
string to_string()
Definition carefree.hpp:1303
void add(string input_name, int time_limit, int memory_limit, int score=-1, int subtask_id=-1)
Definition carefree.hpp:1284
void save(string filename="config.yml")
Definition carefree.hpp:1296
Definition carefree.hpp:1308
virtual bool is_running() const =0
virtual int pid() const =0
virtual size_t memory() const =0
virtual int return_code() const =0
Definition carefree.hpp:1319
process_win(const string &cmd, const string &input="", const string &output="")
Definition carefree.hpp:1325
bool is_running() const
Definition carefree.hpp:1383
void kill()
Definition carefree.hpp:1378
void close()
Definition carefree.hpp:1363
~process_win()
Definition carefree.hpp:1374
size_t memory() const
Definition carefree.hpp:1403
int return_code() const
Definition carefree.hpp:1391
int pid() const
Definition carefree.hpp:1399
Definition carefree.hpp:1593
judge_result from_text(const string &text1, const string &text2)
Definition carefree.hpp:1595
Definition carefree.hpp:1603
judge_result from_text(const string &text1, const string &text2)
Definition carefree.hpp:1605
Definition carefree.hpp:948
void input_write(string val)
Definition carefree.hpp:1121
void input_write(char val)
Definition carefree.hpp:1039
void output_write(unsigned __int128 val)
Definition carefree.hpp:1116
void input_writeln(T val, Args... args)
Definition carefree.hpp:1217
void input_write(graph val)
Definition carefree.hpp:1165
void input_write(__int128 val)
Definition carefree.hpp:1103
void input_write(std::vector< T > val)
Definition carefree.hpp:1149
void input_write(bool val)
Definition carefree.hpp:1139
void output_writeln()
Definition carefree.hpp:1200
void input_flush()
Definition carefree.hpp:1234
string output_name()
Definition carefree.hpp:1256
void output_write(graph val)
Definition carefree.hpp:1169
testcase_writer(string file_prefix, unsigned data_id, string input_suffix=".in", string output_suffix=".out", bool disable_output=false)
Definition carefree.hpp:1021
testcase_writer(string input_file, string output_file="")
Definition carefree.hpp:1015
void input_write(unsigned __int128 val)
Definition carefree.hpp:1112
void output_write(long long val)
Definition carefree.hpp:1057
void output_writeln(T val, Args... args)
Definition carefree.hpp:1225
void output_flush()
Definition carefree.hpp:1235
void input_write(short val)
Definition carefree.hpp:1093
void output_write(T val, Args... args)
Definition carefree.hpp:1192
void output_write(bool val)
Definition carefree.hpp:1143
testcase_writer(string file_prefix, unsigned subtask_id, unsigned task_id, string input_suffix=".in", string output_suffix=".out", bool disable_output=false)
Definition carefree.hpp:1030
void output_write(const char *val)
Definition carefree.hpp:1134
void input_write(T val, Args... args)
Definition carefree.hpp:1184
void input_write(const char *val)
Definition carefree.hpp:1130
void output_write(unsigned short val)
Definition carefree.hpp:1088
void input_write(long long val)
Definition carefree.hpp:1061
void output_writeln(T val)
Definition carefree.hpp:1210
void input_write(unsigned int val)
Definition carefree.hpp:1066
void input_write(unsigned long long val)
Definition carefree.hpp:1075
void output_write(unsigned long long val)
Definition carefree.hpp:1079
bool is_locked()
Definition carefree.hpp:1232
void input_write(int val)
Definition carefree.hpp:1048
void input_writeln()
Definition carefree.hpp:1199
void input_write(edge val)
Definition carefree.hpp:1174
void output_write(std::vector< T > val)
Definition carefree.hpp:1157
void output_write(edge val)
Definition carefree.hpp:1178
void output_write(char val)
Definition carefree.hpp:1043
void output_write(string val)
Definition carefree.hpp:1125
void output_write(int val)
Definition carefree.hpp:1052
void output_write(unsigned int val)
Definition carefree.hpp:1070
void output_write(short val)
Definition carefree.hpp:1097
void output_write(__int128 val)
Definition carefree.hpp:1107
void output_gen(string program)
Definition carefree.hpp:1237
void input_write(unsigned short val)
Definition carefree.hpp:1084
void input_writeln(T val)
Definition carefree.hpp:1203
void close()
Definition carefree.hpp:1260
string input_name()
Definition carefree.hpp:1252
~testcase_writer()
Definition carefree.hpp:1267
Definition carefree.hpp:1659
judge_result test(string input_path, string output_path, string answer_path)
Definition carefree.hpp:1694
judge_result from_text(const string &text1 __attribute__((unused)), const string &text2 __attribute__((unused)))
Definition carefree.hpp:1720
testlib_comparator(const string &testlib_path)
Definition carefree.hpp:1690
Definition carefree.hpp:1624
judge_result from_text(const string &text1, const string &text2)
Definition carefree.hpp:1626
Definition carefree.hpp:1878
const int Wextra
Definition carefree.hpp:1881
const int Wpedantic
Definition carefree.hpp:1882
const int Werror
Definition carefree.hpp:1883
const int Wall
Definition carefree.hpp:1880
int type
Definition carefree.hpp:1885
const int Wnone
Definition carefree.hpp:1879
Definition carefree.hpp:2135
condition< T > inrange(T l, T r)
Definition carefree.hpp:2161
condition< T > neq(T x)
Definition carefree.hpp:2158
condition< T > geq(T x)
Definition carefree.hpp:2155
condition< T > leq(T x)
Definition carefree.hpp:2152
condition< T > eq(T x)
Definition carefree.hpp:2147
condition< T > gt(T x)
Definition carefree.hpp:2142
condition< T > lt(T x)
Definition carefree.hpp:2137
Definition carefree.hpp:2205
condition< std::vector< T > > decrease()
Definition carefree.hpp:2252
condition< std::vector< T > > increase()
Definition carefree.hpp:2240
Definition carefree.hpp:2164
condition< string > empty()
Definition carefree.hpp:2185
condition< string > unempty()
Definition carefree.hpp:2187
condition< string > len_leq(size_t x)
Definition carefree.hpp:2177
condition< string > len_geq(size_t x)
Definition carefree.hpp:2179
condition< string > len_gt(size_t x)
Definition carefree.hpp:2169
condition< string > len_inrange(size_t l, size_t r)
Definition carefree.hpp:2183
condition< string > len_neq(size_t x)
Definition carefree.hpp:2181
condition< string > len_eq(size_t x)
Definition carefree.hpp:2173
condition< string > sset(string s)
Definition carefree.hpp:2189
condition< string > len_lt(size_t x)
Definition carefree.hpp:2165
Definition carefree.hpp:2134
Definition carefree.hpp:430
const string math_symbols
Definition carefree.hpp:443
const string bracket_general
Definition carefree.hpp:438
const string digit
Definition carefree.hpp:433
const string math_symbols_naive
Definition carefree.hpp:441
const string lower
Definition carefree.hpp:431
const string math_symbols_simple
Definition carefree.hpp:442
const string alphabet
Definition carefree.hpp:435
const string quotes
Definition carefree.hpp:440
const string slug
Definition carefree.hpp:436
const string bool_symbols
Definition carefree.hpp:444
const string var_name
Definition carefree.hpp:437
const string upper
Definition carefree.hpp:432
const string bracket
Definition carefree.hpp:439
const string bitwise_symbols
Definition carefree.hpp:445
const string alphanum
Definition carefree.hpp:434
Definition carefree.hpp:86
std::invalid_argument _invalid_argument
Definition carefree.hpp:186
graph introvert(graph tree)
Definition carefree.hpp:747
T uniform(T l, T r)
Definition carefree.hpp:378
judge_result judge(limprog prog, const string &input_file, const string &answer_file, T cmp, bool ole_check=true)
Definition carefree.hpp:1769
void set_exception_policy(exception_policy policy)
Definition carefree.hpp:313
std::vector< string > __split(const string &str, string delims)
Definition carefree.hpp:1518
graph random_graph(int n, int m, bool directed=true, bool repeat_edges=false, bool self_loop=false, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:933
std::vector< int > get_depth(graph g)
Definition carefree.hpp:729
bool is_tree(graph g)
Definition carefree.hpp:675
void shuffle(T val)
Definition carefree.hpp:394
graph connected_undirected_graph(int n, int m, bool repeat_edges=false, bool self_loop=false, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:899
ull nextid()
Definition carefree.hpp:1648
void err_equal_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:302
void err_range_checker(T l, T r, string func_name)
Definition carefree.hpp:248
void listdir(string path, std::vector< string > &files)
Definition carefree.hpp:1829
graph dag(int n, int m, bool repeat_edges=false, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:880
int autoclear_tmpfiles()
Definition carefree.hpp:1845
graph flower(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:805
condition< T > operator&&(condition< T > a, condition< T > b)
Definition carefree.hpp:2119
bool is_file_creatable(string filename)
Definition carefree.hpp:1757
optimization_type
Definition carefree.hpp:1861
@ O0
Definition carefree.hpp:1862
@ O1
Definition carefree.hpp:1863
@ O3
Definition carefree.hpp:1865
@ Ofast
Definition carefree.hpp:1866
@ O2
Definition carefree.hpp:1864
void err_natural_checker(T x, string func_name, string var_name)
Definition carefree.hpp:266
graph random_tree(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:873
judge_result_type
Definition carefree.hpp:1421
@ UnknownError
Definition carefree.hpp:1430
@ Accepted
Definition carefree.hpp:1422
@ MemoryLimitExceeded
Definition carefree.hpp:1425
@ JudgeFailed
Definition carefree.hpp:1431
@ WrongAnswer
Definition carefree.hpp:1423
@ PartiallyCorrect
Definition carefree.hpp:1432
@ RuntimeError
Definition carefree.hpp:1426
@ TimeLimitExceeded
Definition carefree.hpp:1424
@ CompileError
Definition carefree.hpp:1427
@ OutputLimitExceeded
Definition carefree.hpp:1429
@ Skipped
Definition carefree.hpp:1433
@ PresentationError
Definition carefree.hpp:1428
double random()
Definition carefree.hpp:383
bool combat(limprog champion, limprog challenger, T1 input_generator, T2 cmp, int times=-1, bool ole_check=true)
Definition carefree.hpp:1795
void err_leq_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:290
void err_unempty_checker(T x, string func_name, string var_name)
Definition carefree.hpp:254
string working_directory()
Definition carefree.hpp:1841
long long _Weight
Definition carefree.hpp:572
void err_positive_checker(T x, string func_name, string var_name)
Definition carefree.hpp:260
graph lowhigh(int n, double low, double high, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:771
graph binary_tree(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:823
std::runtime_error _runtime_exception
Definition carefree.hpp:190
condition< T > operator||(condition< T > a, condition< T > b)
Definition carefree.hpp:2114
void helloworld()
Definition carefree.hpp:2089
T::value_type choice(T val)
Definition carefree.hpp:388
graph relabel(graph g)
Definition carefree.hpp:691
carefree_exception< _range_exception, carefree_range_exception_name > carefree_range_exception
Definition carefree.hpp:194
graph externalize(graph tree)
Definition carefree.hpp:759
std::vector< Value > sequence(int n, T function)
Definition carefree.hpp:399
graph naive_tree(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:780
double timer(T function)
Definition carefree.hpp:461
struct carefree_internal::__enum_shortcut ES
T randint(T l, T r)
Definition carefree.hpp:372
graph connected_directed_graph(int n, int m, bool repeat_edges=false, bool self_loop=false, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:916
graph complete_binary(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:869
void err_less_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:278
string quote(string s)
Definition carefree.hpp:1653
void gen_data(int subtask_count, int task_per_subtask, T function)
Definition carefree.hpp:469
string jrt2sf(judge_result_type type)
Definition carefree.hpp:1468
graph firecrackers(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:842
condition< T > operator!(condition< T > a)
Definition carefree.hpp:2124
string jrt2s(judge_result_type type)
Definition carefree.hpp:1436
void err_greater_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:284
graph max_degree(int n, int k, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:809
graph silkworm(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:834
condition< T > operator&(condition< T > a, condition< T > b)
Definition carefree.hpp:2132
exception_policy get_exception_policy() noexcept
Definition carefree.hpp:219
string join_str(T1 a, T2 b)
Definition carefree.hpp:321
graph chain_star(int n, int k, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:827
carefree_exception< _invalid_argument, carefree_invalid_argument_name > carefree_invalid_argument
Definition carefree.hpp:192
string __fts(T val, unsigned precision=10)
Definition carefree.hpp:326
unsigned long long ull
Definition carefree.hpp:1500
void err_inrange_checker(T x, T l, T r, string func_name, string var_name)
Definition carefree.hpp:272
std::out_of_range _range_exception
Definition carefree.hpp:188
string fts(float val, unsigned precision=10)
Definition carefree.hpp:343
graph tail(int n, int k, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:784
exception_policy
Definition carefree.hpp:206
@ Simulate
Definition carefree.hpp:214
@ Throw
Definition carefree.hpp:208
@ Ignore
Definition carefree.hpp:210
@ Friendly
Definition carefree.hpp:212
condition< T > operator|(condition< T > a, condition< T > b)
Definition carefree.hpp:2129
std::mt19937_64 public_random_engine
Definition carefree.hpp:369
std::vector< T > ltv(std::initializer_list< T > val)
Definition carefree.hpp:365
exception_policy exception_policy_val
Definition carefree.hpp:217
graph complete(int n, int k, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:852
void err_unequal_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:308
graph star(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:797
void raise(carefree_exception< T1, T2 > err)
Definition carefree.hpp:224
string randstr(int length, const string sset=strsets::lower)
Definition carefree.hpp:448
graph chain(int n, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:793
cpp_version
Definition carefree.hpp:1869
@ Cpp11
Definition carefree.hpp:1872
@ Cpp17
Definition carefree.hpp:1874
@ Cpp98
Definition carefree.hpp:1870
@ Cpp14
Definition carefree.hpp:1873
@ Cpp03
Definition carefree.hpp:1871
@ Cpp20
Definition carefree.hpp:1875
graph prufer_decode(int n, std::vector< int > prufer, _Weight weightL=0, _Weight weightR=0)
Definition carefree.hpp:702
void err_geq_checker(T x, T l, string func_name, string var_name)
Definition carefree.hpp:296
judge_result limited_run(limprog prog, const string &input_file, const string &output_file)
Definition carefree.hpp:1734
__attribute__((constructor)) static void init_rnd_seed()
Definition carefree.hpp:549
Definition carefree.hpp:2268
Definition carefree.hpp:2050
Definition carefree.hpp:90
virtual string name()
Definition carefree.hpp:91
Definition carefree.hpp:131
string name()
Definition carefree.hpp:132
Definition carefree.hpp:119
string name()
Definition carefree.hpp:120
Definition carefree.hpp:123
string name()
Definition carefree.hpp:124
Definition carefree.hpp:135
string name()
Definition carefree.hpp:136
Definition carefree.hpp:139
string name()
Definition carefree.hpp:140
Definition carefree.hpp:127
string name()
Definition carefree.hpp:128
Definition carefree.hpp:143
string name()
Definition carefree.hpp:144
Definition carefree.hpp:576
int to
Definition carefree.hpp:577
edge(int from, int to, _Weight weight=0)
Definition carefree.hpp:579
int from
Definition carefree.hpp:577
_Weight weight
Definition carefree.hpp:578
Definition carefree.hpp:588
string operator()(edge edg)
Definition carefree.hpp:589
Definition carefree.hpp:582
string operator()(edge edg)
Definition carefree.hpp:583
Definition carefree.hpp:1502
string message
Definition carefree.hpp:1504
ull time
Definition carefree.hpp:1506
double ratio
Definition carefree.hpp:1505
ull memory
Definition carefree.hpp:1507
string to_str() const
Definition carefree.hpp:1509
judge_result_type type
Definition carefree.hpp:1503
Definition carefree.hpp:1726
string program
Definition carefree.hpp:1727
ull time
Definition carefree.hpp:1728
ull memory
Definition carefree.hpp:1729
limprog(string program, ull time, ull memory)
Definition carefree.hpp:1731