Skip to content

Commit

Permalink
some old updates which were cancelled by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
vfleaking committed Jul 9, 2018
1 parent cbf8fad commit 9f1302c
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 120 deletions.
68 changes: 49 additions & 19 deletions judge_client/1/uoj_judger/builtin/judger/judger.cpp
@@ -1,5 +1,15 @@
#include "uoj_judger.h"

struct SubtaskInfo {
bool passed;
int score;

SubtaskInfo() {
}
SubtaskInfo(const bool &_p, const int &_s)
: passed(_p), score(_s){}
};

void ordinary_test() {
int n = conf_int("n_tests", 10);
int m = conf_int("n_ex_tests", 0);
Expand Down Expand Up @@ -39,12 +49,15 @@ void ordinary_test() {
}
}
} else {
set<int> passedSubtasks;
map<int, SubtaskInfo> subtasks;
map<int,int> minScore;
for (int t = 1; t <= nT; t++) {
string subtaskType = conf_str("subtask_type", t, "packed");
int startI = conf_int("subtask_end", t - 1, 0) + 1;
int endI = conf_int("subtask_end", t, 0);

vector<PointInfo> points;
minScore[t] = 100;

vector<int> dependences;
if (conf_str("subtask_dependence", t, "none") == "many") {
Expand All @@ -59,9 +72,13 @@ void ordinary_test() {
}
bool skipped = false;
for (vector<int>::iterator it = dependences.begin(); it != dependences.end(); it++) {
if (!passedSubtasks.count(*it)) {
skipped = true;
break;
if (subtaskType == "packed") {
if (!subtasks[*it].passed) {
skipped = true;
break;
}
} else if (subtaskType == "min") {
minScore[t] = min(minScore[t], minScore[*it]);
}
}
if (skipped) {
Expand All @@ -70,28 +87,41 @@ void ordinary_test() {
}

int tfull = conf_int("subtask_score", t, 100 / nT);
int tscore = tfull;
int tscore = scale_score(minScore[t], tfull);
string info = "Accepted";
for (int i = startI; i <= endI; i++) {
report_judge_status_f("Judging Test #%d of Subtask #%d", i, t);
PointInfo po = test_point("answer", i);
if (po.scr != 100) {
passed = false;
po.scr = i == startI ? 0 : -tfull;
tscore = 0;
points.push_back(po);
info = po.info;
break;
} else {
po.scr = i == startI ? tfull : 0;
tscore = tfull;
points.push_back(po);
if (subtaskType == "packed") {
if (po.scr != 100) {
passed = false;
po.scr = i == startI ? 0 : -tfull;
tscore = 0;
points.push_back(po);
info = po.info;
break;
} else {
po.scr = i == startI ? tfull : 0;
tscore = tfull;
points.push_back(po);
}
} else if (subtaskType == "min") {
minScore[t] = min(minScore[t], po.scr);
if (po.scr != 100) {
passed = false;
}
po.scr = scale_score(po.scr, tfull);
if (po.scr <= tscore) {
tscore = po.scr;
points.push_back(po);
info = po.info;
} else {
points.push_back(po);
}
}
}

if (info == "Accepted") {
passedSubtasks.insert(t);
}
subtasks[t] = SubtaskInfo(info == "Accepted", tscore);

add_subtask_info(t, tscore, info, points);
}
Expand Down
211 changes: 110 additions & 101 deletions judge_client/1/uoj_judger/include/uoj_judger.h
Expand Up @@ -294,6 +294,101 @@ map<string, string> config;

/*==================== parameter End ================== */

/*====================== config set =================== */

void print_config() {
for (map<string, string>::iterator it = config.begin(); it != config.end(); ++it) {
cerr << it->first << " = " << it->second << endl;
}
}
void load_config(const string &filename) {
ifstream fin(filename.c_str());
if (!fin) {
return;
}
string key;
string val;
while (fin >> key >> val) {
config[key] = val;
}
}
string conf_str(const string &key, int num, const string &val) {
ostringstream sout;
sout << key << "_" << num;
if (config.count(sout.str()) == 0) {
return val;
}
return config[sout.str()];
}
string conf_str(const string &key, const string &val) {
if (config.count(key) == 0) {
return val;
}
return config[key];
}
string conf_str(const string &key) {
return conf_str(key, "");
}
int conf_int(const string &key, const int &val) {
if (config.count(key) == 0) {
return val;
}
return atoi(config[key].c_str());
}
int conf_int(const string &key, int num, const int &val) {
ostringstream sout;
sout << key << "_" << num;
if (config.count(sout.str()) == 0) {
return conf_int(key, val);
}
return atoi(config[sout.str()].c_str());
}
int conf_int(const string &key) {
return conf_int(key, 0);
}
string conf_input_file_name(int num) {
ostringstream name;
if (num < 0) {
name << "ex_";
}
name << conf_str("input_pre", "input") << abs(num) << "." << conf_str("input_suf", "txt");
return name.str();
}
string conf_output_file_name(int num) {
ostringstream name;
if (num < 0) {
name << "ex_";
}
name << conf_str("output_pre", "output") << abs(num) << "." << conf_str("output_suf", "txt");
return name.str();
}
RunLimit conf_run_limit(string pre, const int &num, const RunLimit &val) {
if (!pre.empty()) {
pre += "_";
}
RunLimit limit;
limit.time = conf_int(pre + "time_limit", num, val.time);
limit.memory = conf_int(pre + "memory_limit", num, val.memory);
limit.output = conf_int(pre + "output_limit", num, val.output);
return limit;
}
RunLimit conf_run_limit(const int &num, const RunLimit &val) {
return conf_run_limit("", num, val);
}
void conf_add(const string &key, const string &val) {
if (config.count(key)) return;
config[key] = val;
}
bool conf_has(const string &key) {
return config.count(key) != 0;
}
bool conf_is(const string &key, const string &val) {
if (config.count(key) == 0) return false;
return config[key] == val;
}

/*==================== config set End ================= */

/*====================== info print =================== */

template <class T>
Expand Down Expand Up @@ -333,7 +428,7 @@ inline string info_str(const RunResult &p) {
return info_str(p.type);
}

void add_point_info(const PointInfo &info) {
void add_point_info(const PointInfo &info, bool update_tot_score = true) {
if (info.num >= 0) {
if(info.ust >= 0) {
tot_time += info.ust;
Expand All @@ -342,16 +437,24 @@ void add_point_info(const PointInfo &info) {
max_memory = max(max_memory, info.usm);
}
}
tot_score += info.scr;
if (update_tot_score) {
tot_score += info.scr;
}

details_out << "<test num=\"" << info.num << "\""
<< " score=\"" << info.scr << "\""
<< " info=\"" << htmlspecialchars(info.info) << "\""
<< " time=\"" << info.ust << "\""
<< " memory=\"" << info.usm << "\">" << endl;
details_out << "<in>" << htmlspecialchars(info.in) << "</in>" << endl;
details_out << "<out>" << htmlspecialchars(info.out) << "</out>" << endl;
details_out << "<res>" << htmlspecialchars(info.res) << "</res>" << endl;
if (conf_str("show_in", "on") == "on") {
details_out << "<in>" << htmlspecialchars(info.in) << "</in>" << endl;
}
if (conf_str("show_out", "on") == "on") {
details_out << "<out>" << htmlspecialchars(info.out) << "</out>" << endl;
}
if (conf_str("show_res", "on") == "on") {
details_out << "<res>" << htmlspecialchars(info.res) << "</res>" << endl;
}
details_out << "</test>" << endl;
}
void add_custom_test_info(const CustomTestInfo &info) {
Expand All @@ -375,8 +478,9 @@ void add_subtask_info(const int &num, const int &scr, const string &info, const
details_out << "<subtask num=\"" << num << "\""
<< " score=\"" << scr << "\""
<< " info=\"" << htmlspecialchars(info) << "\">" << endl;
tot_score += scr;
for (vector<PointInfo>::const_iterator it = points.begin(); it != points.end(); it++) {
add_point_info(*it);
add_point_info(*it, false);
}
details_out << "</subtask>" << endl;
}
Expand Down Expand Up @@ -439,101 +543,6 @@ bool report_judge_status_f(const char *fmt, ...) {

/*==================== info print End ================= */

/*====================== config set =================== */

void print_config() {
for (map<string, string>::iterator it = config.begin(); it != config.end(); ++it) {
cerr << it->first << " = " << it->second << endl;
}
}
void load_config(const string &filename) {
ifstream fin(filename.c_str());
if (!fin) {
return;
}
string key;
string val;
while (fin >> key >> val) {
config[key] = val;
}
}
string conf_str(const string &key, int num, const string &val) {
ostringstream sout;
sout << key << "_" << num;
if (config.count(sout.str()) == 0) {
return val;
}
return config[sout.str()];
}
string conf_str(const string &key, const string &val) {
if (config.count(key) == 0) {
return val;
}
return config[key];
}
string conf_str(const string &key) {
return conf_str(key, "");
}
int conf_int(const string &key, const int &val) {
if (config.count(key) == 0) {
return val;
}
return atoi(config[key].c_str());
}
int conf_int(const string &key, int num, const int &val) {
ostringstream sout;
sout << key << "_" << num;
if (config.count(sout.str()) == 0) {
return conf_int(key, val);
}
return atoi(config[sout.str()].c_str());
}
int conf_int(const string &key) {
return conf_int(key, 0);
}
string conf_input_file_name(int num) {
ostringstream name;
if (num < 0) {
name << "ex_";
}
name << conf_str("input_pre", "input") << abs(num) << "." << conf_str("input_suf", "txt");
return name.str();
}
string conf_output_file_name(int num) {
ostringstream name;
if (num < 0) {
name << "ex_";
}
name << conf_str("output_pre", "output") << abs(num) << "." << conf_str("output_suf", "txt");
return name.str();
}
RunLimit conf_run_limit(string pre, const int &num, const RunLimit &val) {
if (!pre.empty()) {
pre += "_";
}
RunLimit limit;
limit.time = conf_int(pre + "time_limit", num, val.time);
limit.memory = conf_int(pre + "memory_limit", num, val.memory);
limit.output = conf_int(pre + "output_limit", num, val.output);
return limit;
}
RunLimit conf_run_limit(const int &num, const RunLimit &val) {
return conf_run_limit("", num, val);
}
void conf_add(const string &key, const string &val) {
if (config.count(key)) return;
config[key] = val;
}
bool conf_has(const string &key) {
return config.count(key) != 0;
}
bool conf_is(const string &key, const string &val) {
if (config.count(key) == 0) return false;
return config[key] == val;
}

/*==================== config set End ================= */

/*========================== run ====================== */

struct RunProgramConfig {
Expand Down

0 comments on commit 9f1302c

Please sign in to comment.