diff --git a/task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs b/task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs index 3c6b60635..f874b7ee8 100644 --- a/task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs +++ b/task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs @@ -121,6 +121,8 @@ where subtask_name: Option, /// The mapping from subtask name to subtask id. st_name_to_id: HashMap, + /// Mapping from subtask_id to the list of names of dependencies. + st_deps: HashMap>, /// The identifier of the next testcase to process. testcase_id: TestcaseId, } @@ -162,6 +164,7 @@ where subtask_id: 0, subtask_name: None, st_name_to_id: HashMap::new(), + st_deps: HashMap::new(), testcase_id: 0, }; @@ -192,6 +195,28 @@ where _ => unreachable!(), } } + + for entry in &mut cases.result { + if let TaskInputEntry::Subtask(subtask) = entry { + if let Some(deps) = cases.st_deps.get(&subtask.id) { + for dep in deps { + if dep == "*" { + subtask.dependencies = (0..cases.subtask_id).collect(); + eprintln!("ASDFASDFQWERQWER {}", cases.subtask_id); + } else { + let dep_id = *cases + .st_name_to_id + .get(dep) + .ok_or_else(|| anyhow!("Unknown subtask name: {}", dep))?; + subtask.dependencies.push(dep_id); + } + } + subtask.dependencies.sort_unstable(); + subtask.dependencies.dedup(); + } + } + } + Ok(cases) } @@ -555,14 +580,13 @@ where /// Parse a `:STDEP` command. fn parse_st_dep(&mut self, line: Pair) -> Result<(), Error> { for dep in line.into_inner() { - let id = *self - .st_name_to_id - .get(dep.as_str()) - .context("Unknown subtask")?; let Some(TaskInputEntry::Subtask(subtask)) = self.result.last_mut() else { bail!(":STDEP must immediately follow a #ST: in gen/GEN"); }; - subtask.dependencies.push(id); + self.st_deps + .entry(subtask.id) + .or_default() + .push(dep.as_str().to_owned()); } Ok(()) } diff --git a/task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs b/task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs index 37f117ce6..278bd1b8b 100644 --- a/task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs +++ b/task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs @@ -49,6 +49,7 @@ where let mut subtask_id: SubtaskId = 0; let mut entries = vec![]; let mut st_name_to_id = HashMap::new(); + let mut st_deps = HashMap::>::new(); let mut default_subtask = Some(SubtaskInfo { id: 0, @@ -145,10 +146,10 @@ where bail!("#STDEP: must immediately follow a #ST: in gen/GEN"); }; for dependency in line.into_inner() { - let dep_id = *st_name_to_id - .get(dependency.as_str()) - .ok_or_else(|| anyhow!("Unknown subtask name: {}", dependency))?; - subtask.dependencies.push(dep_id); + st_deps + .entry(subtask.id) + .or_default() + .push(dependency.as_str().to_owned()); } } parser::Rule::copy => { @@ -195,6 +196,26 @@ where _ => unreachable!(), } } + + for entry in &mut entries { + if let TaskInputEntry::Subtask(subtask) = entry { + if let Some(deps) = st_deps.get(&subtask.id) { + for dep in deps { + if dep == "*" { + subtask.dependencies = (0..subtask_id).collect(); + } else { + let dep_id = *st_name_to_id + .get(dep) + .ok_or_else(|| anyhow!("Unknown subtask name: {}", dep))?; + subtask.dependencies.push(dep_id); + } + } + subtask.dependencies.sort_unstable(); + subtask.dependencies.dedup(); + } + } + } + Ok(entries) } diff --git a/tests/deps.rs b/tests/deps.rs index 9e97abeb4..cc0885845 100644 --- a/tests/deps.rs +++ b/tests/deps.rs @@ -16,12 +16,12 @@ fn classic(test: TestInterface) { .must_compile("sol-12.cpp") .must_compile("sol-012.cpp") .solution_score("sol-.cpp", vec![0.0, 0.0, 0.0]) - .solution_score("sol-0.cpp", vec![30.0, 0.0, 0.0]) - .solution_score("sol-1.cpp", vec![0.0, 0.0, 0.0]) + .solution_score("sol-0.cpp", vec![0.0, 0.0, 0.0]) + .solution_score("sol-1.cpp", vec![0.0, 30.0, 0.0]) .solution_score("sol-2.cpp", vec![0.0, 0.0, 0.0]) .solution_score("sol-01.cpp", vec![30.0, 30.0, 0.0]) - .solution_score("sol-02.cpp", vec![30.0, 0.0, 0.0]) - .solution_score("sol-12.cpp", vec![0.0, 0.0, 0.0]) + .solution_score("sol-02.cpp", vec![0.0, 0.0, 0.0]) + .solution_score("sol-12.cpp", vec![0.0, 30.0, 0.0]) .solution_score("sol-012.cpp", vec![30.0, 30.0, 40.0]); } diff --git a/tests/tasks/deps/gen/GEN b/tests/tasks/deps/gen/GEN index 41e6d5759..9f6165571 100644 --- a/tests/tasks/deps/gen/GEN +++ b/tests/tasks/deps/gen/GEN @@ -1,13 +1,13 @@ #ST: 30 #STNAME: st-0 +#STDEP: st-1 0 #ST: 30 #STNAME: st-1 -#STDEP: st-0 1 #ST: 40 #STNAME: st-2 -#STDEP: st-1 +#STDEP: * 2