Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"verbose": 0,
"action": None,
"no_visualizer": True,
"local_time_multiplier": None,
}


Expand Down
6 changes: 3 additions & 3 deletions bin/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def prepare_problem(problem: "Problem", language: str):
create_constants_file(problem, language)


def get_tl(problem: "Problem"):
tl = problem.limits.time_limit
def get_raw_tl(problem: "Problem"):
tl = problem.limits.raw_time_limit
tl = int(tl) if abs(tl - int(tl)) < 0.0001 else tl

if "print_time_limit" in contest_yaml():
Expand Down Expand Up @@ -221,7 +221,7 @@ def problem_data(problem: "Problem", language: str):
"problembackground": background,
"problemforeground": foreground,
"problemborder": border,
"timelimit": get_tl(problem),
"timelimit": get_raw_tl(problem),
"problemdir": problem.path.absolute().as_posix(),
"problemdirname": problem.name,
"builddir": latex_builddir(problem, language).as_posix(),
Expand Down
55 changes: 37 additions & 18 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def __init__(
check_unknown_keys(time_multipliers, "limits.time_multipliers")

self.time_limit_is_default: bool = "time_limit" not in yaml_data
self.time_limit: float = parse_setting(yaml_data, "time_limit", 1.0, "> 0") # in seconds
self.raw_time_limit: float = parse_setting(
yaml_data, "time_limit", 1.0, "> 0"
) # in seconds
self.time_resolution: float = parse_setting(yaml_data, "time_resolution", 1.0, "> 0")
self.memory: int = parse_setting(yaml_data, "memory", 2048, "> 0") # in MiB
self.output: int = parse_setting(yaml_data, "output", 8, "> 0") # in MiB
Expand Down Expand Up @@ -208,8 +210,15 @@ def __init__(

check_unknown_keys(yaml_data, "limits")

# adjust actual time_limit based on local_time_multiplier
self.time_limit: float = self.raw_time_limit
if config.args.local_time_multiplier is not None:
self.time_limit *= config.args.local_time_multiplier

# Override limmits by command line arguments.
self.time_limit = config.args.time_limit or self.time_limit
if config.args.time_limit:
self.time_limit = config.args.time_limit
self.raw_time_limit = config.args.time_limit
self.timeout: int = int(config.args.timeout or self.time_limit_to_tle * self.time_limit + 1)
if config.args.timeout:
self.validation_time = self.generator_time = self.visualizer_time = config.args.timeout
Expand Down Expand Up @@ -1529,30 +1538,28 @@ def get_slowest(result):
error("No AC submissions found")
return False

problem.limits.time_limit = problem.limits.time_resolution * math.ceil(
duration * problem.limits.ac_to_time_limit / problem.limits.time_resolution
raw_time_limit = duration * problem.limits.ac_to_time_limit
if config.args.local_time_multiplier is not None:
raw_time_limit /= config.args.local_time_multiplier
problem.limits.raw_time_limit = problem.limits.time_resolution * math.ceil(
raw_time_limit / problem.limits.time_resolution
)
problem.limits.time_limit = problem.limits.raw_time_limit
if config.args.local_time_multiplier is not None:
problem.limits.time_limit *= config.args.local_time_multiplier
safety_time_limit = problem.limits.time_limit * problem.limits.time_limit_to_tle
problem.limits.timeout = int(safety_time_limit * problem.limits.time_limit_to_tle + 1)

if config.args.write:
if not has_ryaml:
warn("ruamel.yaml library not found. Please update the time limit fields manually.")
else:
yaml_path = problem.path / "problem.yaml"
problem_yaml = read_yaml(yaml_path)
if problem_yaml is None:
problem_yaml = ruamel.yaml.comments.CommentedMap()
limits = ryaml_get_or_add(problem_yaml, "limits")
limits["time_limit"] = problem.limits.time_limit
write_yaml(problem_yaml, problem.path / "problem.yaml")

print()
print(file=sys.stderr)
message(f"{duration:.3f}s @ {testcase} ({submission})", "slowest AC")
message(
f"{problem.limits.time_limit}s >= {duration:.3f}s * {problem.limits.ac_to_time_limit}",
"time limit",
)
if config.args.local_time_multiplier is not None:
warn(
f"local_time_multiplier = {config.args.local_time_multiplier:.1f} => time_limit should be set as {problem.limits.raw_time_limit}s"
)
message(
f"{safety_time_limit}s >= {problem.limits.time_limit}s * {problem.limits.time_limit_to_tle}",
"safety limit",
Expand All @@ -1561,7 +1568,19 @@ def get_slowest(result):
f"{problem.limits.timeout}s >= {problem.limits.time_limit}s * {problem.limits.time_limit_to_tle}²",
"timeout",
)
print()
print(file=sys.stderr)

if config.args.write:
if not has_ryaml:
warn("ruamel.yaml library not found. Please update the time limit fields manually.")
else:
yaml_path = problem.path / "problem.yaml"
problem_yaml = read_yaml(yaml_path)
if problem_yaml is None:
problem_yaml = ruamel.yaml.comments.CommentedMap()
limits = ryaml_get_or_add(problem_yaml, "limits")
limits["time_limit"] = problem.limits.raw_time_limit
write_yaml(problem_yaml, problem.path / "problem.yaml")

submission, testcase, duration = run_all(
lambda vs: vs == [verdicts.Verdict.TIME_LIMIT_EXCEEDED], min
Expand Down
Loading