mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 13:38:41 +00:00
feat(judger): support non-integer time limit
This commit is contained in:
parent
6b785e8bc7
commit
1e63154574
@ -633,6 +633,23 @@ int conf_int(const string &key, int num, const int &val) {
|
||||
int conf_int(const string &key) {
|
||||
return conf_int(key, 0);
|
||||
}
|
||||
double conf_double(const string &key, const double &val) {
|
||||
if (config.count(key) == 0) {
|
||||
return val;
|
||||
}
|
||||
return stod(config[key]);
|
||||
}
|
||||
double conf_double(const string &key, int num, const double &val) {
|
||||
ostringstream sout;
|
||||
sout << key << "_" << num;
|
||||
if (config.count(sout.str()) == 0) {
|
||||
return conf_double(key, val);
|
||||
}
|
||||
return stod(config[sout.str()]);
|
||||
}
|
||||
double conf_double(const string &key) {
|
||||
return conf_double(key, 0);
|
||||
}
|
||||
string conf_file_name_with_num(string s, int num) {
|
||||
ostringstream name;
|
||||
if (num < 0) {
|
||||
@ -664,10 +681,10 @@ runp::limits_t conf_run_limit(string pre, const int &num, const runp::limits_t &
|
||||
pre += "_";
|
||||
}
|
||||
runp::limits_t limits;
|
||||
limits.time = conf_int(pre + "time_limit", num, val.time);
|
||||
limits.time = conf_double(pre + "time_limit", num, val.time);
|
||||
limits.memory = conf_int(pre + "memory_limit", num, val.memory);
|
||||
limits.output = conf_int(pre + "output_limit", num, val.output);
|
||||
limits.real_time = conf_int(pre + "real_time_limit", num, val.real_time);
|
||||
limits.real_time = conf_double(pre + "real_time_limit", num, val.real_time);
|
||||
limits.stack = conf_int(pre + "stack_limit", num, val.stack);
|
||||
return limits;
|
||||
}
|
||||
|
@ -501,6 +501,23 @@ int conf_int(const string &key, int num, const int &val) {
|
||||
int conf_int(const string &key) {
|
||||
return conf_int(key, 0);
|
||||
}
|
||||
double conf_double(const string &key, const double &val) {
|
||||
if (uconfig.count(key) == 0) {
|
||||
return val;
|
||||
}
|
||||
return stod(uconfig[key]);
|
||||
}
|
||||
double conf_double(const string &key, int num, const double &val) {
|
||||
ostringstream sout;
|
||||
sout << key << "_" << num;
|
||||
if (uconfig.count(sout.str()) == 0) {
|
||||
return conf_double(key, val);
|
||||
}
|
||||
return stod(uconfig[sout.str()]);
|
||||
}
|
||||
double conf_double(const string &key) {
|
||||
return conf_double(key, 0);
|
||||
}
|
||||
string conf_file_name_with_num(string s, int num) {
|
||||
ostringstream name;
|
||||
if (num < 0) {
|
||||
@ -530,10 +547,10 @@ runp::limits_t conf_run_limit(string pre, const int &num, const runp::limits_t &
|
||||
pre += "_";
|
||||
}
|
||||
runp::limits_t limits;
|
||||
limits.time = conf_int(pre + "time_limit", num, val.time);
|
||||
limits.time = conf_double(pre + "time_limit", num, val.time);
|
||||
limits.memory = conf_int(pre + "memory_limit", num, val.memory);
|
||||
limits.output = conf_int(pre + "output_limit", num, val.output);
|
||||
limits.real_time = conf_int(pre + "real_time_limit", num, val.real_time);
|
||||
limits.real_time = conf_double(pre + "real_time_limit", num, val.real_time);
|
||||
limits.stack = conf_int(pre + "stack_limit", num, val.real_time);
|
||||
return limits;
|
||||
}
|
||||
|
@ -133,14 +133,14 @@ namespace runp {
|
||||
fs::path run_path;
|
||||
|
||||
struct limits_t {
|
||||
int time;
|
||||
double time;
|
||||
int memory;
|
||||
int output;
|
||||
int real_time;
|
||||
double real_time;
|
||||
int stack;
|
||||
|
||||
limits_t() = default;
|
||||
limits_t(const int &_time, const int &_memory, const int &_output)
|
||||
limits_t(const double &_time, const int &_memory, const int &_output)
|
||||
: time(_time), memory(_memory), output(_output), real_time(-1), stack(-1) {
|
||||
}
|
||||
};
|
||||
|
@ -51,10 +51,10 @@ error_t run_program_argp_parse_opt (int key, char *arg, struct argp_state *state
|
||||
|
||||
switch (key) {
|
||||
case 'T':
|
||||
config->limits.time = atoi(arg);
|
||||
config->limits.time = stod(arg);
|
||||
break;
|
||||
case 'R':
|
||||
config->limits.real_time = atoi(arg);
|
||||
config->limits.real_time = stod(arg);
|
||||
break;
|
||||
case 'M':
|
||||
config->limits.memory = atoi(arg);
|
||||
@ -201,9 +201,15 @@ void set_limit(int r, int rcur, int rmax = -1) {
|
||||
}
|
||||
}
|
||||
|
||||
void set_user_cpu_time_limit(int tl) {
|
||||
void set_user_cpu_time_limit(double tl) {
|
||||
struct itimerval val;
|
||||
val.it_value = {tl, 100 * 1000};
|
||||
long tl_sec = (long)tl;
|
||||
long tl_usec = (long)((tl - floor(tl)) * 1000 + 100) * 1000;
|
||||
if (tl_usec >= 1'000'000l) {
|
||||
tl_sec++;
|
||||
tl_usec -= 1'000'000l;
|
||||
}
|
||||
val.it_value = {tl_sec, tl_usec};
|
||||
val.it_interval = {0, 100 * 1000};
|
||||
setitimer(ITIMER_VIRTUAL, &val, NULL);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
Loading…
Reference in New Issue
Block a user