mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-26 03:08: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) {
|
int conf_int(const string &key) {
|
||||||
return conf_int(key, 0);
|
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) {
|
string conf_file_name_with_num(string s, int num) {
|
||||||
ostringstream name;
|
ostringstream name;
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
@ -664,10 +681,10 @@ runp::limits_t conf_run_limit(string pre, const int &num, const runp::limits_t &
|
|||||||
pre += "_";
|
pre += "_";
|
||||||
}
|
}
|
||||||
runp::limits_t limits;
|
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.memory = conf_int(pre + "memory_limit", num, val.memory);
|
||||||
limits.output = conf_int(pre + "output_limit", num, val.output);
|
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);
|
limits.stack = conf_int(pre + "stack_limit", num, val.stack);
|
||||||
return limits;
|
return limits;
|
||||||
}
|
}
|
||||||
|
@ -501,6 +501,23 @@ int conf_int(const string &key, int num, const int &val) {
|
|||||||
int conf_int(const string &key) {
|
int conf_int(const string &key) {
|
||||||
return conf_int(key, 0);
|
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) {
|
string conf_file_name_with_num(string s, int num) {
|
||||||
ostringstream name;
|
ostringstream name;
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
@ -530,10 +547,10 @@ runp::limits_t conf_run_limit(string pre, const int &num, const runp::limits_t &
|
|||||||
pre += "_";
|
pre += "_";
|
||||||
}
|
}
|
||||||
runp::limits_t limits;
|
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.memory = conf_int(pre + "memory_limit", num, val.memory);
|
||||||
limits.output = conf_int(pre + "output_limit", num, val.output);
|
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);
|
limits.stack = conf_int(pre + "stack_limit", num, val.real_time);
|
||||||
return limits;
|
return limits;
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,14 @@ namespace runp {
|
|||||||
fs::path run_path;
|
fs::path run_path;
|
||||||
|
|
||||||
struct limits_t {
|
struct limits_t {
|
||||||
int time;
|
double time;
|
||||||
int memory;
|
int memory;
|
||||||
int output;
|
int output;
|
||||||
int real_time;
|
double real_time;
|
||||||
int stack;
|
int stack;
|
||||||
|
|
||||||
limits_t() = default;
|
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) {
|
: 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) {
|
switch (key) {
|
||||||
case 'T':
|
case 'T':
|
||||||
config->limits.time = atoi(arg);
|
config->limits.time = stod(arg);
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
config->limits.real_time = atoi(arg);
|
config->limits.real_time = stod(arg);
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
config->limits.memory = atoi(arg);
|
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;
|
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};
|
val.it_interval = {0, 100 * 1000};
|
||||||
setitimer(ITIMER_VIRTUAL, &val, NULL);
|
setitimer(ITIMER_VIRTUAL, &val, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
Loading…
Reference in New Issue
Block a user